Skip to content

Commit

Permalink
Lot more tests!
Browse files Browse the repository at this point in the history
- Tests for converting legacy terrain types
- Tests for initialization to sane values

Fixes:
- cCreature no longer initializes spec1 and spec2 to 0. This probably didn't cause bugs, but who knows...
- In fact, cCreature no longer explicitly initializes anything in its cTownperson superclass. That's what the superclass constructor is for after all.
- Relatedly, cTownperson now defaults to a facial graphic of -1. Also a docile attitude.
- iLiving defaults to ap 0, direction here.
- Fix Change When Step terrains to properly support not having a sound while still allowing an arbitrary number of custom sounds.
- Add support for a lack of sound to Change When Used terrains, including at conversion time (original game supported it but OBoE was forcing the sound to a door sound).
- Fix conversion of crumbling terrain types (old conversion was allowing quickfire to destroy them)

Other:
- New addAttack method in cMonster.
- Change snd_num_t to signed, because it's been getting annoying that I can't easily use -1 to mean "no sound".
  • Loading branch information
CelticMinstrel committed Oct 4, 2015
1 parent d178dce commit 96229d1
Show file tree
Hide file tree
Showing 12 changed files with 489 additions and 27 deletions.
2 changes: 1 addition & 1 deletion doc/editor/Terrain.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ <h2>Defining Terrain Types</h2>
<li><b>Change When Walk -</b> The terrain type changes to another when the party tries to
walk into it. This happens even if the terrain is blocked to travel. Extra 1 is the number
of the terrain type the terrain changes into. Extra 2 is the number of the sound that
plays when this happens. If Extra 2 is left at 0, no sound plays.</li>
plays when this happens. If Extra 2 is left at -1, no sound plays.</li>
<li><b>Does Damage -</b> When someone walks on this space, some type of damage is
inflicted. Damaged inflicted is inflicted using a dice roll, with the number of dice in
Extra 2 and the sides per die in Extra 1. The type of damage to inflict is in Extra 3.
Expand Down
8 changes: 8 additions & 0 deletions src/BoE.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@
91CC173E1B421CA0003D9A69 /* scen_write.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CC173B1B421CA0003D9A69 /* scen_write.cpp */; };
91CC17491B422D5C003D9A69 /* scen_read.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91CC173A1B421CA0003D9A69 /* scen_read.cpp */; };
91D634560F8FD77800674AB3 /* BoE.icns in Resources */ = {isa = PBXBuildFile; fileRef = 2B8F435C0C0973680012E4A8 /* BoE.icns */; };
91E128E41BC1624700C8BE1D /* ter_legacy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E128E31BC1624700C8BE1D /* ter_legacy.cpp */; };
91E128E61BC19DA400C8BE1D /* init.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E128E51BC19DA400C8BE1D /* init.cpp */; };
91E381461B97673700F69B81 /* town_write.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E381451B97671E00F69B81 /* town_write.cpp */; };
91E381481B97677900F69B81 /* talk_write.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E381471B97675900F69B81 /* talk_write.cpp */; };
91E3814A1B97679800F69B81 /* out_write.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E381491B97678D00F69B81 /* out_write.cpp */; };
Expand Down Expand Up @@ -750,6 +752,8 @@
91D635AD0F90E7B500674AB3 /* valleydy.meg */ = {isa = PBXFileReference; lastKnownFileType = file; path = valleydy.meg; sourceTree = "<group>"; };
91D635AE0F90E7B500674AB3 /* zakhazi.exs */ = {isa = PBXFileReference; lastKnownFileType = file; path = zakhazi.exs; sourceTree = "<group>"; };
91D635AF0F90E7B500674AB3 /* zakhazi.meg */ = {isa = PBXFileReference; lastKnownFileType = file; path = zakhazi.meg; sourceTree = "<group>"; };
91E128E31BC1624700C8BE1D /* ter_legacy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ter_legacy.cpp; sourceTree = "<group>"; };
91E128E51BC19DA400C8BE1D /* init.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = init.cpp; sourceTree = "<group>"; };
91E1862B1B2B2AC0006A99EA /* estreams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = estreams.cpp; sourceTree = "<group>"; };
91E30F2A1A74819B0057C54A /* fileio_party.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fileio_party.cpp; sourceTree = "<group>"; };
91E30F2D1A7481C20057C54A /* fileio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fileio.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1324,6 +1328,7 @@
children = (
91CC17391B421CA0003D9A69 /* catch.cpp */,
91C763D81B4C4BB30086D879 /* enums.cpp */,
91E128E51BC19DA400C8BE1D /* init.cpp */,
919B13A31BBD8849009905A4 /* item_legacy.cpp */,
91EF27761B693D5500666469 /* item_read.cpp */,
91EF27781B693D5F00666469 /* item_write.cpp */,
Expand All @@ -1339,6 +1344,7 @@
919B13A51BBDE985009905A4 /* spec_legacy.cpp */,
91C2A6EE1B8FAA8E00346948 /* talk_read.cpp */,
91E381471B97675900F69B81 /* talk_write.cpp */,
91E128E31BC1624700C8BE1D /* ter_legacy.cpp */,
91EF27721B693D3800666469 /* ter_read.cpp */,
91EF27741B693D4800666469 /* ter_write.cpp */,
91C2A6EC1B8FA91400346948 /* town_read.cpp */,
Expand Down Expand Up @@ -1868,6 +1874,8 @@
919B13A21BBCDF14009905A4 /* monst_legacy.cpp in Sources */,
919B13A41BBD8854009905A4 /* item_legacy.cpp in Sources */,
919B13A61BBDE986009905A4 /* spec_legacy.cpp in Sources */,
91E128E41BC1624700C8BE1D /* ter_legacy.cpp in Sources */,
91E128E61BC19DA400C8BE1D /* init.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 3 additions & 2 deletions src/boe.specials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ bool check_special_terrain(location where_check,eSpecCtx mode,cPlayer& which_pc,
break;
case eTerSpec::CHANGE_WHEN_STEP_ON:
alter_space(where_check.x,where_check.y,ter_flag1);
if(ter_flag2 < 200) {
if(ter_flag2 >= 0) {
play_sound(-1 * ter_flag2);
}
give_help(47,65);
Expand Down Expand Up @@ -1256,7 +1256,8 @@ bool use_space(location where) {
}
add_string_to_buf(" OK.");
alter_space(where.x,where.y,univ.scenario.ter_types[ter].flag1);
play_sound(univ.scenario.ter_types[ter].flag2);
if(univ.scenario.ter_types[ter].flag2 >= 0)
play_sound(univ.scenario.ter_types[ter].flag2);
return true;
} else if(univ.scenario.ter_types[ter].special == eTerSpec::CALL_SPECIAL_WHEN_USED) {
short spec_type = 0;
Expand Down
14 changes: 5 additions & 9 deletions src/classes/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@

const short cCreature::charm_odds[21] = {90,90,85,80,78, 75,73,60,40,30, 20,10,4,1,0, 0,0,0,0,0, 0};

cCreature::cCreature(){
number = active = 0;
attitude = start_attitude = eAttitude::DOCILE;
start_loc.x = start_loc.y = cur_loc.x = cur_loc.y = targ_loc.x = targ_loc.y = 80;
mobility = 1;
summon_time = 0;
time_flag = eMonstTime::ALWAYS;
spec1 = spec2 = spec_enc_code = time_code = monster_time = 0;
personality = special_on_kill = facial_pic = -1;
cCreature::cCreature() {
active = 0;
attitude = eAttitude::DOCILE;
cur_loc.x = cur_loc.y = targ_loc.x = targ_loc.y = 80;
summon_time = 0;
target = 6;
}

Expand Down
4 changes: 2 additions & 2 deletions src/classes/living.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class iLiving {
public:
// HACK: This is only really marked mutable so that I can use operator[] from const methods
mutable std::map<eStatus,short> status;
short ap;
eDirection direction;
short ap = 0;
eDirection direction = DIR_HERE;
short marked_damage = 0; // for use during animations

virtual bool is_alive() const = 0;
Expand Down
13 changes: 13 additions & 0 deletions src/classes/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ void cMonster::append(legacy::monster_record_type& old){
see_spec = -1;
}

int cMonster::addAttack(unsigned short dice, unsigned short sides, eMonstMelee type) {
int which = 0;
while(which < 3 && a[which].dice > 0 && a[which].sides > 0)
which++;
if(which >= 3) return -1;
a[which].dice = dice;
a[which].sides = sides;
a[which].type = type;
return which;
}

std::map<eMonstAbil,uAbility>::iterator cMonster::addAbil(eMonstAbilTemplate what, int param) {
switch(what) {
// Missiles: {true, type, missile pic, dice, sides, skill, range, odds}
Expand Down Expand Up @@ -415,6 +426,8 @@ cTownperson::cTownperson() {
personality = -1;
special_on_kill = -1;
special_on_talk = -1;
facial_pic = -1;
start_attitude = eAttitude::DOCILE;
}

cTownperson::cTownperson(location loc, mon_num_t num, const cMonster& monst) : cTownperson() {
Expand Down
1 change: 1 addition & 0 deletions src/classes/monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class cMonster {
spec_num_t see_spec;

std::map<eMonstAbil,uAbility>::iterator addAbil(eMonstAbilTemplate what, int param = 0);
int addAttack(unsigned short dice, unsigned short sides, eMonstMelee type = eMonstMelee::SWING);

void append(legacy::monster_record_type& old);
cMonster();
Expand Down
4 changes: 2 additions & 2 deletions src/classes/terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void cTerrain::append(legacy::terrain_type_type& old){
break;
case 1:
special = eTerSpec::CHANGE_WHEN_STEP_ON;
if(flag2 == 200) flag2 = -1;
flag3 = 0;
break;
case 2:
Expand All @@ -186,7 +187,7 @@ void cTerrain::append(legacy::terrain_type_type& old){
break;
case 7:
special = eTerSpec::CRUMBLING;
flag2 = 1; // destroyed by Move Mountains but not by quickfire; 0 = both, 2 = quickfire only
flag2 = 0; // destroyed by Move Mountains but not by quickfire; 1 = both, 2 = quickfire only
break;
case 8:
special = eTerSpec::LOCKABLE;
Expand Down Expand Up @@ -254,7 +255,6 @@ void cTerrain::append(legacy::terrain_type_type& old){
break;
case 22:
special = eTerSpec::CHANGE_WHEN_USED;
flag2 = 59;
flag3 = 0;
break;
case 23:
Expand Down
2 changes: 1 addition & 1 deletion src/tools/soundtool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <SFML/Audio.hpp>

typedef unsigned short snd_num_t;
typedef signed int snd_num_t;
void init_snd_tool();
bool sound_going(snd_num_t which_s);
void play_sound(short which, short how_many_times = 1);
Expand Down
223 changes: 223 additions & 0 deletions test/init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
//
// init.cpp
// BoE
//
// Created by Celtic Minstrel on 15-10-04.
//
//

#include <catch.hpp>
#include "scenario.hpp"
#include "creature.hpp"
#include "creatlist.hpp"

TEST_CASE("Initialization sanity test for terrain") {
cTerrain ter;
CHECK(ter.name.empty());
CHECK(ter.picture == 0);
CHECK(ter.blockage == eTerObstruct::CLEAR);
CHECK(ter.flag1 == -1);
CHECK(ter.flag2 == 0);
CHECK(ter.flag3 == 0);
CHECK(ter.special == eTerSpec::NONE);
CHECK(ter.trans_to_what == 0);
CHECK_FALSE(ter.fly_over);
CHECK_FALSE(ter.boat_over);
CHECK_FALSE(ter.block_horse);
CHECK_FALSE(ter.is_archetype);
CHECK(ter.light_radius == 0);
CHECK(ter.step_sound == eStepSnd::STEP);
CHECK(ter.shortcut_key == 0);
CHECK(ter.obj_num == 0);
CHECK(ter.ground_type == 0);
CHECK(ter.trim_type == eTrimType::NONE);
CHECK(ter.trim_ter == 0);
CHECK(ter.frill_for == -1);
CHECK(ter.frill_chance == 0);
CHECK(ter.combat_arena == 0);
CHECK(ter.obj_pos == loc(0,0));
CHECK(ter.obj_size == loc(0,0));
CHECK(ter.map_pic == -1);
}

TEST_CASE("Initialization sanity test for monster") {
cCreature who;
SECTION("Monster base class") {
cMonster& monst = who;
CHECK(monst.level == 0);
CHECK(monst.m_name.empty());
CHECK(monst.m_health == 0);
CHECK(monst.armor == 0);
CHECK(monst.skill == 0);
CHECK(monst.a[0].dice == 0);
CHECK(monst.a[0].sides == 0);
CHECK(monst.a[0].type == eMonstMelee::SWING);
CHECK(monst.a[1].dice == 0);
CHECK(monst.a[1].sides == 0);
CHECK(monst.a[1].type == eMonstMelee::SWING);
CHECK(monst.a[2].dice == 0);
CHECK(monst.a[2].sides == 0);
CHECK(monst.a[2].type == eMonstMelee::SWING);
CHECK(monst.m_type == eRace::HUMAN);
CHECK(monst.speed == 4);
CHECK(monst.mu == 0);
CHECK(monst.cl == 0);
CHECK(monst.treasure == 0);
CHECK(monst.abil.empty());
CHECK(monst.corpse_item == 0);
CHECK(monst.corpse_item_chance == 0);
CHECK(monst.resist.size() == 10);
CHECK(monst.resist[eDamageType::WEAPON] == 100);
CHECK(monst.resist[eDamageType::FIRE] == 100);
CHECK(monst.resist[eDamageType::POISON] == 100);
CHECK(monst.resist[eDamageType::COLD] == 100);
CHECK(monst.resist[eDamageType::MAGIC] == 100);
CHECK(monst.resist[eDamageType::UNBLOCKABLE] == 100);
CHECK(monst.resist[eDamageType::UNDEAD] == 100);
CHECK(monst.resist[eDamageType::DEMON] == 100);
CHECK(monst.resist[eDamageType::MARKED] == 100);
CHECK_FALSE(monst.mindless);
CHECK_FALSE(monst.invuln);
CHECK_FALSE(monst.invisible);
CHECK_FALSE(monst.guard);
CHECK_FALSE(monst.amorphous);
CHECK(monst.x_width == 1);
CHECK(monst.y_width == 1);
CHECK(monst.default_attitude == eAttitude::DOCILE);
CHECK(monst.summon_type == 0);
CHECK(monst.default_facial_pic == 0);
CHECK(monst.picture_num == 149);
CHECK(monst.ambient_sound == -1);
CHECK(monst.see_spec == -1);
}
SECTION("Townsperson base class") {
cTownperson& dude = who;
CHECK(dude.number == 0);
CHECK(dude.start_attitude == eAttitude::DOCILE);
CHECK(dude.start_loc == loc(80,80));
CHECK(dude.mobility == 1);
CHECK(dude.time_flag == eMonstTime::ALWAYS);
CHECK(dude.spec1 == -1);
CHECK(dude.spec2 == -1);
CHECK(dude.spec_enc_code == 0);
CHECK(dude.time_code == 0);
CHECK(dude.monster_time == 0);
CHECK(dude.personality == -1);
CHECK(dude.special_on_kill == -1);
CHECK(dude.special_on_talk == -1);
CHECK(dude.facial_pic == -1);
}
SECTION("Living base class") {
iLiving& base = who;
CHECK(base.status.empty());
CHECK(base.ap == 0);
CHECK(base.direction == DIR_HERE);
CHECK(base.marked_damage == 0);
}
SECTION("Main creature class") {
CHECK(who.active == 0);
CHECK(who.attitude == eAttitude::DOCILE);
CHECK(who.cur_loc == loc(80,80));
CHECK(who.summon_time == 0);
CHECK(who.target == 6);
CHECK(who.targ_loc == loc(80,80));
CHECK(who.health == 0);
CHECK(who.mp == 0);
CHECK(who.max_mp == 0);
CHECK(who.morale == 0);
CHECK(who.m_morale == 0);
}
}

TEST_CASE("Construction sanity test for monster") {
// First, build a base monster.
cMonster monst;
monst.default_facial_pic = 12;
monst.default_attitude = eAttitude::HOSTILE_A;

cTownperson dude({10,10}, 7, monst); // This is here because the population sections also need it
SECTION("Into townsperson") {
CHECK(dude.number == 7);
CHECK(dude.start_loc == loc(10,10));
CHECK(dude.facial_pic == 12);
CHECK(dude.start_attitude == eAttitude::HOSTILE_A);
return; // Don't need to bother adding the extra monster/townperson attributes for this test
}

cPopulation pop;
SECTION("Population init sanity test") {
CHECK(pop.size() == 0);
CHECK(pop.which_town == 200);
CHECK_FALSE(pop.hostile);
return; // Don't need to bother adding the extra monster/townperson attributes for this test
}

monst.addAbil(eMonstAbilTemplate::TOUCH_STEAL_GOLD);
monst.addAttack(2, 8, eMonstMelee::STAB);
monst.resist[eDamageType::FIRE] = 25;
monst.level = 5;
monst.m_name = "The Grinch";
monst.m_health = 32;
monst.armor = 9;
monst.skill = 1;
monst.m_type = eRace::GOBLIN;
monst.invisible = true;
monst.mu = 1;

dude.time_flag = eMonstTime::APPEAR_AFTER_CHOP;
dude.personality = 8;
dude.start_attitude = eAttitude::HOSTILE_B;

SECTION("Into population (normal mode)") {
pop.assign(0, dude, monst, false, 1);
REQUIRE(pop.size() == 1);
CHECK(pop[0].active == 1);
CHECK(pop[0].picture_num == 0);
CHECK(pop[0].m_health == 32);
CHECK(pop[0].health == 32);
CHECK(pop[0].max_mp == 60);
CHECK(pop[0].mp == 60);
CHECK(pop[0].m_morale == 50);
CHECK(pop[0].morale == 50);
CHECK(pop[0].ap == 0);
CHECK(pop[0].direction == DIR_HERE);
CHECK(pop[0].status.size() == 0);
CHECK(pop[0].attitude == eAttitude::HOSTILE_B);
CHECK(pop[0].cur_loc == loc(10,10));
// Townsperson stuff
CHECK(pop[0].time_flag == eMonstTime::APPEAR_AFTER_CHOP);
CHECK(pop[0].personality == 8);
// Monster stuff
CHECK(pop[0].m_name == "The Grinch");
CHECK(pop[0].level == 5);
CHECK(pop[0].armor == 9);
CHECK(pop[0].skill == 1);
CHECK(pop[0].speed == 4);
CHECK(pop[0].m_type == eRace::GOBLIN);
CHECK(pop[0].resist[eDamageType::FIRE] == 25);
CHECK(pop[0].invisible);
CHECK(pop[0].mu == 1);
REQUIRE(pop[0].abil.size() == 1);
CHECK(pop[0].abil[eMonstAbil::STEAL_GOLD].active);
// No need to bother checking the attributes of the ability, just make sure it's there
}
SECTION("Into population (easy mode)") {
pop.assign(0, dude, monst, true, 1);
REQUIRE(pop.size() == 1);
CHECK(pop[0].m_health == 16);
CHECK(pop[0].health == 16);
}
SECTION("Into population (with difficulty adjust") {
pop.assign(0, dude, monst, false, 10);
REQUIRE(pop.size() == 1);
CHECK(pop[0].m_health == 320);
CHECK(pop[0].health == 320);
}
SECTION("Into population (high-level monster)") {
monst.level = 50;
pop.assign(0, dude, monst, false, 1);
REQUIRE(pop.size() == 1);
CHECK(pop[0].m_morale == 800);
CHECK(pop[0].morale == 800);
}
}
Loading

0 comments on commit 96229d1

Please sign in to comment.