Skip to content

Commit

Permalink
make [command] [attack] handler a bit friendlier
Browse files Browse the repository at this point in the history
Now, it won't warn about mismatch with gamestate when you don't
specify attacker_type or defender_type.

Simplify unit test 6 accordingly.
  • Loading branch information
cbeck88 committed May 11, 2014
1 parent ab0b63d commit a37ec8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 0 additions & 2 deletions data/test/scenarios/unit_test_6.cfg
Expand Up @@ -26,8 +26,6 @@
[attack]
weapon = 0
defender_weapon = 0
attacker_type = Orcish Grunt
defender_type = Elvish Archer
[source]
x = "$({X} + 1)"
y = {Y}
Expand Down
28 changes: 17 additions & 11 deletions src/synced_commands.cpp
Expand Up @@ -141,13 +141,17 @@ SYNCED_COMMAND_HANDLER_FUNCTION(recall, child, use_undo, show, error_handler)

SYNCED_COMMAND_HANDLER_FUNCTION(attack, child, /*use_undo*/, show, error_handler)
{

const config &destination = child.child("destination");
const config &source = child.child("source");
//check_checksums(*cfg);

if (!destination || !source) {
error_handler("no destination/source found in attack\n", true);
if (!destination) {
error_handler("no destination found in attack\n", true);
return false;
}

if (!source) {
error_handler("no source found in attack \n", true);
return false;
}

Expand All @@ -170,9 +174,11 @@ SYNCED_COMMAND_HANDLER_FUNCTION(attack, child, /*use_undo*/, show, error_handler
return false;
}

const std::string &att_type_id = child["attacker_type"];
if (u->type_id() != att_type_id) {
WRN_REPLAY << "unexpected attacker type: " << att_type_id << "(game_state gives: " << u->type_id() << ")\n";
if (child.has_attribute("attacker_type")) {
const std::string &att_type_id = child["attacker_type"];
if (u->type_id() != att_type_id) {
WRN_REPLAY << "unexpected attacker type: " << att_type_id << "(game_state gives: " << u->type_id() << ")\n";
}
}

if (size_t(weapon_num) >= u->attacks().size()) {
Expand All @@ -189,9 +195,11 @@ SYNCED_COMMAND_HANDLER_FUNCTION(attack, child, /*use_undo*/, show, error_handler
return false;
}

const std::string &def_type_id = child["defender_type"];
if (tgt->type_id() != def_type_id) {
WRN_REPLAY << "unexpected defender type: " << def_type_id << "(game_state gives: " << tgt->type_id() << ")\n";
if (child.has_attribute("defender_type")) {
const std::string &def_type_id = child["defender_type"];
if (tgt->type_id() != def_type_id) {
WRN_REPLAY << "unexpected defender type: " << def_type_id << "(game_state gives: " << tgt->type_id() << ")\n";
}
}

if (def_weapon_num >= static_cast<int>(tgt->attacks().size())) {
Expand All @@ -201,8 +209,6 @@ SYNCED_COMMAND_HANDLER_FUNCTION(attack, child, /*use_undo*/, show, error_handler
}

DBG_REPLAY << "Attacker XP (before attack): " << u->experience() << "\n";



resources::undo_stack->clear();
attack_unit_and_advance(src, dst, weapon_num, def_weapon_num, show);
Expand Down

0 comments on commit a37ec8b

Please sign in to comment.