Skip to content

Commit d9ba9b4

Browse files
Applied Quipyowert2's comments.
1 parent 2adc3e3 commit d9ba9b4

File tree

15 files changed

+96
-124
lines changed

15 files changed

+96
-124
lines changed

libgag/src/StringTable.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ namespace GAGCore
179179
for (std::map<std::string, size_t>::iterator it=stringAccess.begin(); it!=stringAccess.end(); ++it)
180180
{
181181
// For each entry...
182-
bool lCwp=false;
182+
bool lastCharWasPct=false;
183183
int baseCount=0;
184184
const std::string &s = it->first;
185185
// we check that we only have valid format (from a FormattableString point of view)...
186186
for (size_t j=0; j<s.length(); j++)
187187
{
188188
char c = s[j];
189-
if (lCwp && c!=' ' && c!='%')
189+
if (lastCharWasPct && c!=' ' && c!='%')
190190
{
191191
if (isdigit(c))
192192
baseCount++;
@@ -197,18 +197,18 @@ namespace GAGCore
197197
return false;
198198
}
199199
}
200-
lCwp=(c=='%');
200+
lastCharWasPct=(c=='%');
201201
}
202202
// then we are sure that format are correct in all translation
203203
for (size_t i=0; i<strings[it->second]->data.size(); i++)
204204
{
205205
const std::string &s = strings[it->second]->data[i];
206-
bool lCwp=false;
206+
bool lastCharWasPct=false;
207207
int count=0;
208208
for (size_t j=0; j<s.length(); j++)
209209
{
210210
char c=s[j];
211-
if (lCwp && c!=' ' && c!='%')
211+
if (lastCharWasPct && c!=' ' && c!='%')
212212
{
213213
if (isdigit(c))
214214
count++;
@@ -219,7 +219,7 @@ namespace GAGCore
219219
return false;
220220
}
221221
}
222-
lCwp=(c=='%');
222+
lastCharWasPct=(c=='%');
223223
}
224224
// if not, issue an error message
225225
if (baseCount!=count && s!="")

src/AICastor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ void AICastor::computeCanSwim()
18351835
{
18361836
//printf("computeCanSwim()...\n");
18371837
// If our population has more healthy-working-units able to swim than healthy-working-units
1838-
// unable to swim then we choose to be able to go trough water:
1838+
// unable to swim then we choose to be able to go through water:
18391839
Unit **myUnits=team->myUnits;
18401840
int sumCanSwim=0;
18411841
int sumCantSwim=0;
@@ -2986,7 +2986,7 @@ void AICastor::computeResourcesCluster()
29862986

29872987
void AICastor::updateGlobalGradientNoObstacle(Uint8 *gradient)
29882988
{
2989-
//In this algorithm, "l" stands for one case at Left, "r" for one case at Right, "u" for Up, and "d" for Down.
2989+
//In this algorithm, "l" stands for one tile at Left, "r" for one tile at Right, "u" for Up, and "d" for Down.
29902990
// Warning, this is *nearly* a copy-past, 4 times, once for each direction.
29912991
int w=map->w;
29922992
int h=map->h;

src/AIEcho.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ namespace AIEcho
346346
bool load(GAGCore::InputStream *stream, Player *player, Sint32 versionMinor);
347347
void save(GAGCore::OutputStream *stream);
348348

349-
///Returns true if the provided position matches any of the sources that where added
349+
///Returns true if the provided position matches any of the sources that were added
350350
bool match_source(Map* map, int posX, int posY);
351-
///Returns true if the provided position matches any of the obstacles that where added
351+
///Returns true if the provided position matches any of the obstacles that were added
352352
bool match_obstacle(Map* map, int posX, int posY);
353353
///Returns true if this GradientInfo has any entities that can change, causing it to need to be updated.
354354
///This is an optimization, as many gradients don't need to be update
@@ -372,7 +372,7 @@ namespace AIEcho
372372

373373
///A generic, all purpose gradient. The gradient is referenced by its GradientInfo, which it uses continually in its computation.
374374
///Echo gradients are probably the slowest gradients in the game. However, they have one key difference compared to other gradients,
375-
///they can be shared, and they are generic, even more so than Nicowar gradients (which where decently generic, but not entirely).
375+
///they can be shared, and they are generic, even more so than Nicowar gradients (which were decently generic, but not entirely).
376376
class Gradient
377377
{
378378
public:
@@ -396,7 +396,7 @@ namespace AIEcho
396396
///The gradient manager is a very important part of the system, just like the gradient itself is. The gradient manager takes upon the task
397397
///of managing and updating various gradients in the game. It returns a matching gradient when provided a GradientInfo.
398398
///This object is shared among all Echo AI's, which means gradients that aren't specific to a particular team (such as most Resource
399-
///gradients) don't have to be recalculated for every Echo AI separately. This saves allot of cpu time when their are multiple Echo AI's.
399+
///gradients) don't have to be recalculated for every Echo AI separately. This saves a lot of cpu time when their are multiple Echo AI's.
400400
class GradientManager
401401
{
402402
public:
@@ -563,7 +563,7 @@ namespace AIEcho
563563
};
564564

565565

566-
///This constraint, against unlike the others, does not use gradients. It only allows the given
566+
///This constraint, again unlike the others, does not use gradients. It only allows the given
567567
///position to be allowed. The resulting building will *not* be centered on it except if it is
568568
///a 1x1 building
569569
class SinglePosition : public Constraint
@@ -633,7 +633,7 @@ namespace AIEcho
633633

634634
///The building register is a very important sub system of Echo. It keeps track of buildings.
635635
///A seemingly simple process, but very, very important. Buildings you construct are looked for,
636-
///found, recorded, etc. Allot of seemingly odd code is found here, meant to work around some
636+
///found, recorded, etc. A lot of seemingly odd code is found here, meant to work around some
637637
///of the difficulties of other parts of glob2, so that the AI programmer can have a seamless,
638638
///comfortable interface. Nothing here is directly important to an AI programmer.
639639
///The system puts buildings through three stages. The first is where the building order has been
@@ -728,7 +728,7 @@ namespace AIEcho
728728

729729
///These are all conditions on a particular Building. They are used in several places, such as when counting numbers of buildings, or
730730
///for setting a condition on an order to change the number of units assigned, making them very useful. Its important to note that
731-
///none of the conditions work on enemies buildings, they only work on buildings on you're own team.
731+
///none of the conditions work on enemies buildings, they only work on buildings on your own team.
732732
namespace Conditions
733733
{
734734
///This is used for loading and saving purposes only
@@ -952,7 +952,7 @@ namespace AIEcho
952952
};
953953

954954
///Similar to BeingUpgraded, but this also takes a level, in which the building is being upgraded
955-
///to a particular level. When possible, use this instead od combining BeingUpgraded and BuildingLevel
955+
///to a particular level. When possible, use this instead of combining BeingUpgraded and BuildingLevel
956956
class BeingUpgradedTo : public BuildingCondition
957957
{
958958
public:
@@ -1122,7 +1122,7 @@ namespace AIEcho
11221122
///checks for the conditions for the management order to execute at all. indeterminate means
11231123
///that its impossible to execute, false means wait some more and true means ready to execute
11241124
///For example, the ChangeFlagSize order requires that the building be in existence, and
1125-
///that its a flag.
1125+
///that it's a flag.
11261126
virtual boost::logic::tribool wait(Echo& echo)=0;
11271127

11281128
virtual bool load(GAGCore::InputStream *stream, Player *player, Sint32 versionMinor);
@@ -1190,9 +1190,9 @@ namespace AIEcho
11901190
};
11911191

11921192

1193-
///A resource tracker is generally used for management, like most other things. A resource trackers job is to keep
1193+
///A resource tracker is generally used for management, like most other things. A resource tracker's job is to keep
11941194
///track of the number of resources in a particular building, and returning averages over a small period of time.
1195-
///Its better to use a resource tracker than getting the resource amounts directly, because a resource tracker
1195+
///It's better to use a resource tracker than getting the resource amounts directly, because a resource tracker
11961196
///returns trends, and small anomalies like an Inn running out of food for only a second don't impact its result greatly.
11971197
class ResourceTracker
11981198
{

src/AINicowar.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,9 @@ void NewNicowar::check_phases(Echo& echo)
567567
}
568568

569569
///Qualifications for the upgrading phase 1:
570-
///1) Atleast strategy.upgrading_phase_1_school_min schools
571-
///2) Atleast strategy.upgrading_phase_1_unit_min units
572-
///3) Atleast strategy.upgrading_phase_1_trained_worker_min of them are trained for upgrading to level 2
570+
///1) At least strategy.upgrading_phase_1_school_min schools
571+
///2) At least strategy.upgrading_phase_1_unit_min units
572+
///3) At least strategy.upgrading_phase_1_trained_worker_min of them are trained for upgrading to level 2
573573
BuildingSearch schools(echo);
574574
schools.add_condition(new SpecificBuildingType(IntBuildingType::SCIENCE_BUILDING));
575575
schools.add_condition(new NotUnderConstruction);
@@ -586,9 +586,9 @@ void NewNicowar::check_phases(Echo& echo)
586586
}
587587

588588
///Qualifications for the upgrading phase 2:
589-
///1) Atleast strategy.upgrading_phase_2_school_min level 2 or level 3 schools
590-
///2) Atleast strategy.upgrading_phase_2_unit_min units
591-
///3) Atleast strategy.upgrading_phase_2_trained_worker_min of them are trained for upgrading to level 3
589+
///1) At least strategy.upgrading_phase_2_school_min level 2 or level 3 schools
590+
///2) At least strategy.upgrading_phase_2_unit_min units
591+
///3) At least strategy.upgrading_phase_2_trained_worker_min of them are trained for upgrading to level 3
592592
BuildingSearch schools_2(echo);
593593
schools_2.add_condition(new SpecificBuildingType(IntBuildingType::SCIENCE_BUILDING));
594594
schools_2.add_condition(new NotUnderConstruction);
@@ -609,8 +609,8 @@ void NewNicowar::check_phases(Echo& echo)
609609
upgrading_phase_2=false;
610610
}
611611

612-
///Qualifications for the war preperation phase:
613-
///1) Atleast strategy.war_preparation_phase_unit_min units
612+
///Qualifications for the war preparation phase:
613+
///1) At least strategy.war_preparation_phase_unit_min units
614614
///2) Less than strategy.war_preparation_phase_barracks_max barracks OR
615615
///3) Less than strategy.war_preparation_phase_trained_warrior_max trained warriors
616616
BuildingSearch barracks(echo);
@@ -633,7 +633,7 @@ void NewNicowar::check_phases(Echo& echo)
633633
}
634634

635635
///Qualifications for the war phase:
636-
///Atleast strategy.war_phase_trained_warrior_min trained warriors
636+
///At least strategy.war_phase_trained_warrior_min trained warriors
637637
if(warrior_count >= strategy.war_phase_trained_warrior_min)
638638
{
639639
war=true;
@@ -644,7 +644,7 @@ void NewNicowar::check_phases(Echo& echo)
644644
}
645645

646646
///Qualifications for the fruit phase:
647-
///Atleast strategy.fruit_phase_unit_min units, and fruits on the map
647+
///At least strategy.fruit_phase_unit_min units, and fruits on the map
648648
if(echo.is_fruit_on_map() && stat->totalUnit >= strategy.fruit_phase_unit_min)
649649
{
650650
fruit_phase=true;
@@ -656,7 +656,7 @@ void NewNicowar::check_phases(Echo& echo)
656656

657657
///Qualifications for the starving recovery phase:
658658
///1) More than strategy.starvation_recovery_phase_starving_no_inn_min_percent % units hungry but not able to eat
659-
///2) Atleast one unit (because of division by 0)
659+
///2) At least one unit (because of division by 0)
660660
if(stat->totalUnit > 1)
661661
{
662662
int total_starving_percent = stat->needFoodNoInns * 100 / stat->totalUnit;
@@ -677,7 +677,7 @@ void NewNicowar::check_phases(Echo& echo)
677677
///Qualifications for the no worker phase:
678678
///1) More than strategy.no_workers_phase_free_worker_minimum_percent % workers free
679679
///2) No needed jobs
680-
///3) Atleast one worker (because of division by 0)
680+
///3) At least one worker (because of division by 0)
681681
if(stat->numberUnitPerType[WORKER] > 0)
682682
{
683683
const int workers_free = (stat->isFree[WORKER] - stat->totalNeeded) * 100 / stat->numberUnitPerType[WORKER];
@@ -696,7 +696,7 @@ void NewNicowar::check_phases(Echo& echo)
696696
}
697697

698698
///Qualifications for the can swim phase:
699-
///1) Atleast one worker that can swim
699+
///1) At least one worker that can swim
700700
int total_can_swim=0;
701701
for(int i=0; i<4; ++i)
702702
total_can_swim += stat->upgradeStatePerType[WORKER][SWIM][i];
@@ -1060,7 +1060,7 @@ int NewNicowar::order_regular_inn(Echo& echo)
10601060
//You dont want to be too close to water, so that farm can develop between it and water
10611061
bo->add_constraint(new AIEcho::Construction::MinimumDistance(gi_water, 6));
10621062

1063-
//Constraints arround nearby settlement
1063+
//Constraints around nearby settlement
10641064
AIEcho::Gradients::GradientInfo gi_building;
10651065
gi_building.add_source(new AIEcho::Gradients::Entities::AnyTeamBuilding(echo.player->team->teamNumber, false));
10661066
gi_building.add_obstacle(new AIEcho::Gradients::Entities::AnyResource);
@@ -1126,7 +1126,7 @@ int NewNicowar::order_regular_swarm(Echo& echo)
11261126
//Constraints about the distance to water.
11271127
AIEcho::Gradients::GradientInfo gi_water;
11281128
gi_water.add_source(new AIEcho::Gradients::Entities::Water);
1129-
//You dont want to be too close to water, so that farm can develop between it and water
1129+
//You don't want to be too close to water, so that farm can develop between it and water
11301130
bo->add_constraint(new AIEcho::Construction::MinimumDistance(gi_water, 6));
11311131

11321132
//Constraints around nearby settlement
@@ -1218,7 +1218,7 @@ int NewNicowar::order_regular_racetrack(Echo& echo)
12181218

12191219
int NewNicowar::order_regular_swimmingpool(Echo& echo)
12201220
{
1221-
//The main order for the swimmingpool
1221+
//The main order for the swimming pool
12221222
BuildingOrder* bo = new BuildingOrder(IntBuildingType::SWIMSPEED_BUILDING, 6);
12231223

12241224
//Constraints around the location of wood
@@ -1527,7 +1527,7 @@ void NewNicowar::manage_swarm(Echo& echo, int id)
15271527
else
15281528
explorer_ratio=0;
15291529

1530-
///Warriors are constructed during the war preperation phase
1530+
///Warriors are constructed during the war preparation phase
15311531
if(war_preparation)
15321532
{
15331533
warrior_ratio=strategy.war_preparation_swarm_warrior_ratio;

src/AINicowar.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,29 @@ class NicowarStrategy : LoadableFromConfigFile
151151
int upgrading_phase_1_inn_chance;
152152
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an hospital
153153
int upgrading_phase_1_hospital_chance;
154-
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an racetrack
154+
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a racetrack
155155
int upgrading_phase_1_racetrack_chance;
156-
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an swimming pool
156+
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a swimming pool
157157
int upgrading_phase_1_swimmingpool_chance;
158-
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an barracks
158+
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a barracks
159159
int upgrading_phase_1_barracks_chance;
160-
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an school
160+
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a school
161161
int upgrading_phase_1_school_chance;
162-
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an tower
162+
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a tower
163163
int upgrading_phase_1_tower_chance;
164164
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an inn
165165
int upgrading_phase_2_inn_chance;
166166
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an hospital
167167
int upgrading_phase_2_hospital_chance;
168-
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an racetrack
168+
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a racetrack
169169
int upgrading_phase_2_racetrack_chance;
170-
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an swimming pool
170+
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a swimming pool
171171
int upgrading_phase_2_swimmingpool_chance;
172-
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an barracks
172+
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a barracks
173173
int upgrading_phase_2_barracks_chance;
174-
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an school
174+
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a school
175175
int upgrading_phase_2_school_chance;
176-
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an tower
176+
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a tower
177177
int upgrading_phase_2_tower_chance;
178178
///The number of units to assign to an upgrade for upgrading phase level 1
179179
int upgrading_phase_1_units_assigned;
@@ -274,7 +274,7 @@ class NewNicowar : public AIEcho::EchoAI
274274
bool defend_explorers;
275275
///During this phase, Nicowar tries to construct many explorers so that it can launch an attack with them
276276
bool explorer_attack_preparation_phase;
277-
///During this phase, Nicowar will activity attack its opponents with explorers
277+
///During this phase, Nicowar will actively attack its opponents with explorers
278278
bool explorer_attack_phase;
279279

280280

@@ -300,7 +300,7 @@ class NewNicowar : public AIEcho::EchoAI
300300
///This counts how many StarvingRecoveryInn's there are under construction
301301
int starving_recovery_inns;
302302

303-
///This function starts construction on buildings that are queued for construction. Its careful
303+
///This function starts construction on buildings that are queued for construction. It's careful
304304
///not to construct too much or too little at once
305305
void order_buildings(AIEcho::Echo& echo);
306306
///This function starts construction of a RegularInn, and returns the ID code

src/AINumbi.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,14 @@ boost::shared_ptr<Order>AINumbi::swarmsForWorkers(const int minSwarmNumbers, con
410410

411411
int f=estimateFood(b);
412412
int numberRequestedTemp=numberRequested;
413-
int numberRequestedLocA=b->maxUnitWorking;
413+
int numberRequestedLocal=b->maxUnitWorking;
414414
if (f<(nbu*3-1))
415415
numberRequestedTemp=0;
416-
else if (numberRequestedLocA==0)
416+
else if (numberRequestedLocal==0)
417417
if (f<(nbu*5+1))
418418
numberRequestedTemp=0;
419419

420-
if (numberRequestedLocA!=numberRequestedTemp)
420+
if (numberRequestedLocal!=numberRequestedTemp)
421421
{
422422
//printf("AI: (%d) numberRequested changed to (nrt=%d) (nrl=%d)(f=%d) (nbu=%d).\n", b->UID, numberRequestedTemp, numberRequestedLoca, f, nbu);
423423
b->maxUnitWorkingLocal=numberRequestedTemp;

src/Building.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,19 +1395,19 @@ bool Building::isHardSpaceForBuildingSite(void)
13951395

13961396
bool Building::isHardSpaceForBuildingSite(ConstructionResultState constructionResultState)
13971397
{
1398-
int tlTn=-1;
1398+
int futureBuildingTypeId=-1;
13991399
if (constructionResultState==UPGRADE)
1400-
tlTn=type->nextLevel;
1400+
futureBuildingTypeId=type->nextLevel;
14011401
else if (constructionResultState==REPAIR)
1402-
tlTn=type->prevLevel;
1402+
futureBuildingTypeId=type->prevLevel;
14031403
else
14041404
assert(false);
14051405

1406-
if (tlTn==-1)
1406+
if (futureBuildingTypeId==-1)
14071407
return true;
1408-
BuildingType *bt=globalContainer->buildingsTypes.get(tlTn);
1409-
int x=posX+bt->decLeft-type->decLeft;
1410-
int y=posY+bt->decTop -type->decTop ;
1408+
BuildingType *bt=globalContainer->buildingsTypes.get(futureBuildingTypeId);
1409+
int x=posX + bt->decLeft - type->decLeft;
1410+
int y=posY + bt->decTop - type->decTop ;
14111411
int w=bt->width;
14121412
int h=bt->height;
14131413

@@ -1485,8 +1485,8 @@ bool Building::subscribeToBringResourcesStep()
14851485
1-the closest the unit is, the better it is.
14861486
2-the less the unit is hungry, the better it is.
14871487
3-if the unit has a needed resource, this is better.
1488-
4-if the unit as a not needed resource, this is worse.
1489-
5-if the unit is close of a needed resource, this is better
1488+
4-if the unit has a not-needed resource, this is worse.
1489+
5-if the unit is close to a needed resource, this is better.
14901490
14911491
score_to_max=(rightRes*100/d+noRes*80/(d+dr)+wrongRes*25/(d+dr))/walk+sign(timeLeft>>2 - (d+dr))*500+100/harvest
14921492
*/
@@ -2531,6 +2531,7 @@ void Building::addResourceIntoBuilding(int resourceType)
25312531
int totResources=0;
25322532
for (unsigned i=0; i<MAX_NB_RESOURCES; i++)
25332533
totResources+=type->maxResource[i];
2534+
assert(totResources>0);
25342535
hp += type->hpMax/totResources;
25352536
hp = std::min(hp, type->hpMax);
25362537
}

0 commit comments

Comments
 (0)