fixed choose_weapon assertion failure

This commit is contained in:
Dave White 2003-10-22 10:03:02 +00:00
parent 2f2bb402fc
commit df1425f318
3 changed files with 42 additions and 35 deletions

View File

@ -83,13 +83,13 @@ Defeat:
canrecruit=1 canrecruit=1
recruit=Orcish Warrior,Wolf Rider,Orcish Crossbow,Orcish Assassin,Troll Warrior recruit=Orcish Warrior,Wolf Rider,Orcish Crossbow,Orcish Assassin,Troll Warrior
#ifdef EASY #ifdef EASY
gold=400 gold=250
#endif #endif
#ifdef NORMAL #ifdef NORMAL
gold=450 gold=300
#endif #endif
#ifdef HARD #ifdef HARD
gold=500 gold=350
#endif #endif
enemy=1 enemy=1
[/side] [/side]
@ -99,15 +99,17 @@ Defeat:
description=Urug-Tan description=Urug-Tan
side=3 side=3
canrecruit=1 canrecruit=1
recruit=Orcish Grunt,Goblin Knight,Orcish Crossbow,Orcish Assassin,Troll Warrior
#ifdef EASY #ifdef EASY
gold=450 recruit=Orcish Grunt,Wolf Rider,Orcish Archer,Orcish Assassin,Troll
gold=250
#endif #endif
#ifdef NORMAL #ifdef NORMAL
gold=500 recruit=Orcish Grunt,Goblin Knight,Orcish Crossbow,Orcish Assassin,Troll Warrior
gold=300
#endif #endif
#ifdef HARD #ifdef HARD
gold=550 recruit=Orcish Warrior,Goblin Knight,Orcish Crossbow,Orcish Assassin,Troll Warrior
gold=350
#endif #endif
enemy=1 enemy=1
[/side] [/side]
@ -120,13 +122,13 @@ Defeat:
canrecruit=1 canrecruit=1
recruit=Orcish Warrior,Wolf Rider,Orcish Crossbow,Troll Warrior,Orcish Slayer recruit=Orcish Warrior,Wolf Rider,Orcish Crossbow,Troll Warrior,Orcish Slayer
#ifdef EASY #ifdef EASY
gold=450 gold=250
#endif #endif
#ifdef NORMAL #ifdef NORMAL
gold=500 gold=300
#endif #endif
#ifdef HARD #ifdef HARD
gold=550 gold=350
#endif #endif
enemy=1 enemy=1
[/side] [/side]
@ -229,7 +231,7 @@ Defeat:
message="A monster was hiding in that lake!" message="A monster was hiding in that lake!"
[/message] [/message]
[role] [role]
type=Thief,Rogue,Mage,Elvish Shaman,Elvish Druid,Elvish Archer,Elvish Fighter,Elvish Captain,Elvish Marshal,Horseman type=Thief,Rogue,Mage,Elvish Shaman,Elvish Druid,Elvish Archer,Elvish Fighter,Elvish Captain,Elvish Marshal,Horseman,Elvish Lord
role=whiner role=whiner
[/role] [/role]
[message] [message]

View File

@ -536,41 +536,44 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
std::cout << "move: " << move.first.x << ", " << move.first.y << " - " << move.second.x << ", " << move.second.y << "\n"; std::cout << "move: " << move.first.x << ", " << move.first.y << " - " << move.second.x << ", " << move.second.y << "\n";
std::cout << "calling move_unit\n";
move_unit(gameinfo,disp,map,units,move.first,move.second,
possible_moves,teams,team_num);
std::cout << "end move_unit\n";
//search to see if there are any enemy units next //search to see if there are any enemy units next
//to the tile which really should be attacked //to the tile which really should be attacked once the move is done
gamemap::location adj[6]; gamemap::location adj[6];
get_adjacent_tiles(move.second,adj); get_adjacent_tiles(move.second,adj);
battle_stats bat_stats;
gamemap::location target;
int weapon = -1;
for(int n = 0; n != 6; ++n) { for(int n = 0; n != 6; ++n) {
const unit_map::iterator enemy = units.find(adj[n]); const unit_map::iterator enemy = units.find(adj[n]);
if(enemy != units.end() && if(enemy != units.end() &&
current_team.is_enemy(enemy->second.side())) { current_team.is_enemy(enemy->second.side())) {
battle_stats stats; target = adj[n];
const int weapon = choose_weapon(map,units,state,gameinfo, weapon = choose_weapon(map,units,state,gameinfo,move.first,
move.second,adj[n],stats, target,bat_stats,
map[move.second.x][move.second.y]); map[move.second.x][move.second.y]);
assert(weapon != -1);
const location attacker = move.second;
const location defender = adj[n];
recorder.add_attack(attacker,defender,weapon);
game_events::fire("attack",attacker,defender);
if(units.count(attacker) && units.count(defender)) {
attack(disp,map,attacker,defender,weapon,units,state,
gameinfo,false);
check_victory(units,teams);
}
break; break;
} }
} }
move_unit(gameinfo,disp,map,units,move.first,move.second,
possible_moves,teams,team_num);
//if we're going to attack someone
if(weapon != -1) {
const location& attacker = move.second;
recorder.add_attack(attacker,target,weapon);
game_events::fire("attack",attacker,target);
if(units.count(attacker) && units.count(target)) {
attack(disp,map,attacker,target,weapon,units,state,
gameinfo,false);
check_victory(units,teams);
}
}
//don't allow any other units to move onto the tile our unit //don't allow any other units to move onto the tile our unit
//just moved onto //just moved onto
typedef std::multimap<location,location>::iterator Itor; typedef std::multimap<location,location>::iterator Itor;

View File

@ -175,6 +175,8 @@ int choose_weapon(const gamemap& map, std::map<location,unit>& units,
cur_stats = cache_itor->stats; cur_stats = cache_itor->stats;
if(!(size_t(cache_itor->weapon) < itor->second.attacks().size())) { if(!(size_t(cache_itor->weapon) < itor->second.attacks().size())) {
std::cerr << "cached illegal weapon: " << cache_itor->weapon
<< "/" << itor->second.attacks().size() << "\n";
} }
assert(size_t(cache_itor->weapon) < itor->second.attacks().size()); assert(size_t(cache_itor->weapon) < itor->second.attacks().size());