fixed a division by zero error when AI has equipment on field but no creatures to equip them to.

fixed formatting of getEfficiency code block
This commit is contained in:
techdragon.nguyen@gmail.com
2011-02-19 15:39:48 +00:00
parent 017e2cf00d
commit 788ae5e629
+4 -3
View File
@@ -278,7 +278,7 @@ int AIAction::getEfficiency()
break; break;
if(dynamic_cast<ALord*> (a) && !target) if(dynamic_cast<ALord*> (a) && !target)
{ {
//this is a specail case for all(this) targetting workaround. //this is a special case for all(this) targetting workaround.
//adding a direct method for targetting the source is planned for //adding a direct method for targetting the source is planned for
//the coming releases, all(this) workaround prevents eff from being returned //the coming releases, all(this) workaround prevents eff from being returned
//as its not targetted the same as abilities //as its not targetted the same as abilities
@@ -329,12 +329,13 @@ int AIAction::getEfficiency()
int equips = p->game->battlefield->countByType("Equipment"); int equips = p->game->battlefield->countByType("Equipment");
int myArmy = p->game->battlefield->countByType("Creature"); int myArmy = p->game->battlefield->countByType("Creature");
int equilized = abs(equips / myArmy); // when can this ever be negative?
int equilized = myArmy ? abs(equips / myArmy) : 0;
if (p == target->controller() && target->equipment <= 1 && !a->source->target) if (p == target->controller() && target->equipment <= 1 && !a->source->target)
{ {
efficiency = 20 * (target->DangerRanking()); efficiency = 20 * (target->DangerRanking());
if (target->hasColor(5)) if (target->hasColor(Constants::MTG_COLOR_WHITE))
efficiency += 20;//this is to encourage Ai to equip white creatures in a weenie deck. ultimately it will depend on what had the higher dangerranking. efficiency += 20;//this is to encourage Ai to equip white creatures in a weenie deck. ultimately it will depend on what had the higher dangerranking.
if (target->power == 1 && target->toughness == 1 && target->isToken == 0) if (target->power == 1 && target->toughness == 1 && target->isToken == 0)
efficiency += 10; //small bonus to encourage equipping nontoken 1/1 creatures. efficiency += 10; //small bonus to encourage equipping nontoken 1/1 creatures.