84
86
debug("delete stack from ai_analysis")
85
87
instance->d_threats->deleteStack(s->getId());
86
instance->d_stacks->flRemove(s->getId());
88
instance->d_stacks->removeStack(s->getId());
87
89
debug("stack " << s << " died")
93
float AI_Analysis::assessArmyStrength(const Army *army)
95
return (float)army->getStat(Army::STRENGTH);
91
98
float AI_Analysis::assessStackStrength(const Stack *stack)
93
debug("assessing stack with id "<<stack->getId())
96
101
return stack->size() * 5.0;
100
105
// our stack, so we can look inside it
101
106
float total = 0.0;
102
107
for (Stack::const_iterator it = stack->begin(); it != stack->end(); it++)
103
total += (*it)->getStat(Army::STRENGTH);
108
total += assessArmyStrength(*it);
109
115
// enemy stack, no cheating!
110
116
// if we were smarter, we would remember all stacks we had seen before and return a better number here.
111
117
// We don't assume a too high average strength
112
if (stack->getStrongestArmy()->getStat(Army::STRENGTH) < 5)
113
return stack->size() * stack->getStrongestArmy()->getStat(Army::STRENGTH);
118
guint32 as = stack->getOwner()->getArmyset();
119
guint32 type_id = stack->getStrongestArmy()->getTypeId();
120
ArmyProto *strongest = Armysetlist::getInstance()->getArmy(as, type_id);
121
//if the strongest army has a strength of 4 or less,
122
//we assume that all army units in the stack have the same strength.
123
if (strongest->getStrength() < 5)
124
return stack->size() * strongest->getStrength();
125
//otherwise we round everything down to an average of 5 strength.
114
126
return stack->size() * 5.0;
118
130
const Threatlist* AI_Analysis::getThreatsInOrder()
131
143
void AI_Analysis::getCityWorstDangers(float dangers[3])
133
std::map<string, AICityInfo *>::iterator it;
145
std::map<guint32, AICityInfo *>::iterator it;
136
148
// i wanto to have a result array with the first worst dangers
176
int AI_Analysis::getNumberOfDefendersInCity(City *city)
178
AICityMap::iterator it = d_cityInfo.find(city->getId());
179
if (it == d_cityInfo.end())
182
return (*it).second->getDefenderCount();
164
185
float AI_Analysis::getCityDanger(City *city)
166
// city does not exist in the map
167
if (d_cityInfo.find(city->getName()) == d_cityInfo.end())
170
debug("Threats to " << city->getName() << " are " << d_cityInfo[city->getName()]->getThreats()->toString())
171
return d_cityInfo[city->getName()]->getDanger();
187
AICityMap::iterator it = d_cityInfo.find(city->getId());
188
// city does not exist in the map
189
if (it == d_cityInfo.end())
192
debug("Threats to " << city->getName() << " are " << d_cityInfo[city->getId()]->getThreats()->toString())
193
return (*it).second->getDanger();
174
196
void AI_Analysis::reinforce(City *city, Stack *stack, int movesToArrive)
176
if (d_cityInfo.find(city->getName()) == d_cityInfo.end())
198
AICityMap::iterator it = d_cityInfo.find(city->getId()) ;
199
if (it == d_cityInfo.end())
179
AICityInfo *info = d_cityInfo[city->getName()];
180
info->addReinforcements(assessStackStrength(stack) / (float) movesToArrive);
202
(*it).second->addReinforcements(assessStackStrength(stack) / (float) movesToArrive);
183
205
float AI_Analysis::reinforcementsNeeded(City *city)
185
if (d_cityInfo.find(city->getName()) == d_cityInfo.end())
207
AICityMap::iterator it = d_cityInfo.find(city->getId());
208
if (it == d_cityInfo.end())
188
const AICityInfo* info = d_cityInfo[city->getName()];
189
return info->getDanger() - info->getReinforcements();
211
return (*it).second->getDanger() - (*it).second->getReinforcements();
192
214
void AI_Analysis::examineCities()
246
266
AICityInfo *info = new AICityInfo(city);
247
267
d_threats->findThreats(info);
248
d_cityInfo[city->getName()] = info;
268
d_cityInfo[city->getId()] = info;
273
void AI_Analysis::changeOwnership (Player * old_player, Player * new_player)
276
instance->d_threats->changeOwnership(old_player, new_player);