make [command] [attack] handler a bit friendlier
Now, it won't warn about mismatch with gamestate when you don't specify attacker_type or defender_type. Simplify unit test 6 accordingly.
This commit is contained in:
parent
ab0b63dc58
commit
a37ec8bbdb
2 changed files with 17 additions and 13 deletions
|
@ -26,8 +26,6 @@
|
|||
[attack]
|
||||
weapon = 0
|
||||
defender_weapon = 0
|
||||
attacker_type = Orcish Grunt
|
||||
defender_type = Elvish Archer
|
||||
[source]
|
||||
x = "$({X} + 1)"
|
||||
y = {Y}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -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())) {
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue