Skip to content

Commit

Permalink
Applied Quipyowert2's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanemagnenat committed Oct 27, 2024
1 parent 2adc3e3 commit d9ba9b4
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 124 deletions.
12 changes: 6 additions & 6 deletions libgag/src/StringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ namespace GAGCore
for (std::map<std::string, size_t>::iterator it=stringAccess.begin(); it!=stringAccess.end(); ++it)
{
// For each entry...
bool lCwp=false;
bool lastCharWasPct=false;
int baseCount=0;
const std::string &s = it->first;
// we check that we only have valid format (from a FormattableString point of view)...
for (size_t j=0; j<s.length(); j++)
{
char c = s[j];
if (lCwp && c!=' ' && c!='%')
if (lastCharWasPct && c!=' ' && c!='%')
{
if (isdigit(c))
baseCount++;
Expand All @@ -197,18 +197,18 @@ namespace GAGCore
return false;
}
}
lCwp=(c=='%');
lastCharWasPct=(c=='%');
}
// then we are sure that format are correct in all translation
for (size_t i=0; i<strings[it->second]->data.size(); i++)
{
const std::string &s = strings[it->second]->data[i];
bool lCwp=false;
bool lastCharWasPct=false;
int count=0;
for (size_t j=0; j<s.length(); j++)
{
char c=s[j];
if (lCwp && c!=' ' && c!='%')
if (lastCharWasPct && c!=' ' && c!='%')
{
if (isdigit(c))
count++;
Expand All @@ -219,7 +219,7 @@ namespace GAGCore
return false;
}
}
lCwp=(c=='%');
lastCharWasPct=(c=='%');
}
// if not, issue an error message
if (baseCount!=count && s!="")
Expand Down
4 changes: 2 additions & 2 deletions src/AICastor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ void AICastor::computeCanSwim()
{
//printf("computeCanSwim()...\n");
// If our population has more healthy-working-units able to swim than healthy-working-units
// unable to swim then we choose to be able to go trough water:
// unable to swim then we choose to be able to go through water:
Unit **myUnits=team->myUnits;
int sumCanSwim=0;
int sumCantSwim=0;
Expand Down Expand Up @@ -2986,7 +2986,7 @@ void AICastor::computeResourcesCluster()

void AICastor::updateGlobalGradientNoObstacle(Uint8 *gradient)
{
//In this algorithm, "l" stands for one case at Left, "r" for one case at Right, "u" for Up, and "d" for Down.
//In this algorithm, "l" stands for one tile at Left, "r" for one tile at Right, "u" for Up, and "d" for Down.
// Warning, this is *nearly* a copy-past, 4 times, once for each direction.
int w=map->w;
int h=map->h;
Expand Down
22 changes: 11 additions & 11 deletions src/AIEcho.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ namespace AIEcho
bool load(GAGCore::InputStream *stream, Player *player, Sint32 versionMinor);
void save(GAGCore::OutputStream *stream);

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

///A generic, all purpose gradient. The gradient is referenced by its GradientInfo, which it uses continually in its computation.
///Echo gradients are probably the slowest gradients in the game. However, they have one key difference compared to other gradients,
///they can be shared, and they are generic, even more so than Nicowar gradients (which where decently generic, but not entirely).
///they can be shared, and they are generic, even more so than Nicowar gradients (which were decently generic, but not entirely).
class Gradient
{
public:
Expand All @@ -396,7 +396,7 @@ namespace AIEcho
///The gradient manager is a very important part of the system, just like the gradient itself is. The gradient manager takes upon the task
///of managing and updating various gradients in the game. It returns a matching gradient when provided a GradientInfo.
///This object is shared among all Echo AI's, which means gradients that aren't specific to a particular team (such as most Resource
///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.
///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.
class GradientManager
{
public:
Expand Down Expand Up @@ -563,7 +563,7 @@ namespace AIEcho
};


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

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

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

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

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


///A resource tracker is generally used for management, like most other things. A resource trackers job is to keep
///A resource tracker is generally used for management, like most other things. A resource tracker's job is to keep
///track of the number of resources in a particular building, and returning averages over a small period of time.
///Its better to use a resource tracker than getting the resource amounts directly, because a resource tracker
///It's better to use a resource tracker than getting the resource amounts directly, because a resource tracker
///returns trends, and small anomalies like an Inn running out of food for only a second don't impact its result greatly.
class ResourceTracker
{
Expand Down
34 changes: 17 additions & 17 deletions src/AINicowar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,9 @@ void NewNicowar::check_phases(Echo& echo)
}

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

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

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

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

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

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

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

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

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

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

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

///Warriors are constructed during the war preperation phase
///Warriors are constructed during the war preparation phase
if(war_preparation)
{
warrior_ratio=strategy.war_preparation_swarm_warrior_ratio;
Expand Down
24 changes: 12 additions & 12 deletions src/AINicowar.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,29 @@ class NicowarStrategy : LoadableFromConfigFile
int upgrading_phase_1_inn_chance;
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an hospital
int upgrading_phase_1_hospital_chance;
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an racetrack
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a racetrack
int upgrading_phase_1_racetrack_chance;
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an swimming pool
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a swimming pool
int upgrading_phase_1_swimmingpool_chance;
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an barracks
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a barracks
int upgrading_phase_1_barracks_chance;
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an school
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a school
int upgrading_phase_1_school_chance;
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose an tower
///The random chance that, when selecting the type of level 1 building to upgrade, it will choose a tower
int upgrading_phase_1_tower_chance;
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an inn
int upgrading_phase_2_inn_chance;
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an hospital
int upgrading_phase_2_hospital_chance;
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an racetrack
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a racetrack
int upgrading_phase_2_racetrack_chance;
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an swimming pool
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a swimming pool
int upgrading_phase_2_swimmingpool_chance;
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an barracks
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a barracks
int upgrading_phase_2_barracks_chance;
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an school
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a school
int upgrading_phase_2_school_chance;
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose an tower
///The random chance that, when selecting the type of level 2 building to upgrade, it will choose a tower
int upgrading_phase_2_tower_chance;
///The number of units to assign to an upgrade for upgrading phase level 1
int upgrading_phase_1_units_assigned;
Expand Down Expand Up @@ -274,7 +274,7 @@ class NewNicowar : public AIEcho::EchoAI
bool defend_explorers;
///During this phase, Nicowar tries to construct many explorers so that it can launch an attack with them
bool explorer_attack_preparation_phase;
///During this phase, Nicowar will activity attack its opponents with explorers
///During this phase, Nicowar will actively attack its opponents with explorers
bool explorer_attack_phase;


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

///This function starts construction on buildings that are queued for construction. Its careful
///This function starts construction on buildings that are queued for construction. It's careful
///not to construct too much or too little at once
void order_buildings(AIEcho::Echo& echo);
///This function starts construction of a RegularInn, and returns the ID code
Expand Down
6 changes: 3 additions & 3 deletions src/AINumbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,14 @@ boost::shared_ptr<Order>AINumbi::swarmsForWorkers(const int minSwarmNumbers, con

int f=estimateFood(b);
int numberRequestedTemp=numberRequested;
int numberRequestedLocA=b->maxUnitWorking;
int numberRequestedLocal=b->maxUnitWorking;
if (f<(nbu*3-1))
numberRequestedTemp=0;
else if (numberRequestedLocA==0)
else if (numberRequestedLocal==0)
if (f<(nbu*5+1))
numberRequestedTemp=0;

if (numberRequestedLocA!=numberRequestedTemp)
if (numberRequestedLocal!=numberRequestedTemp)
{
//printf("AI: (%d) numberRequested changed to (nrt=%d) (nrl=%d)(f=%d) (nbu=%d).\n", b->UID, numberRequestedTemp, numberRequestedLoca, f, nbu);
b->maxUnitWorkingLocal=numberRequestedTemp;
Expand Down
19 changes: 10 additions & 9 deletions src/Building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,19 +1395,19 @@ bool Building::isHardSpaceForBuildingSite(void)

bool Building::isHardSpaceForBuildingSite(ConstructionResultState constructionResultState)
{
int tlTn=-1;
int futureBuildingTypeId=-1;
if (constructionResultState==UPGRADE)
tlTn=type->nextLevel;
futureBuildingTypeId=type->nextLevel;
else if (constructionResultState==REPAIR)
tlTn=type->prevLevel;
futureBuildingTypeId=type->prevLevel;
else
assert(false);

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

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

0 comments on commit d9ba9b4

Please sign in to comment.