mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Clearing up the code as requested by FeniksFire
This commit is contained in:
parent
3d59420bb5
commit
cae8acc56a
@ -1152,7 +1152,7 @@ void VCAI::recruitCreatures(const CGDwelling * d, const CArmedInstance * recruit
|
||||
}
|
||||
}
|
||||
|
||||
bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsigned int maxDays)
|
||||
bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsigned int maxDays) const
|
||||
{
|
||||
if(maxDays == 0)
|
||||
{
|
||||
@ -1204,15 +1204,7 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsi
|
||||
}
|
||||
else if(canBuild == EBuildingState::NO_RESOURCES)
|
||||
{
|
||||
//TResources income = estimateIncome();
|
||||
TResources cost = t->town->buildings.at(buildID)->resources;
|
||||
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; i++)
|
||||
{
|
||||
//int diff = currentRes[i] - cost[i] + income[i];
|
||||
int diff = currentRes[i] - cost[i];
|
||||
if(diff < 0)
|
||||
saving[i] = 1;
|
||||
}
|
||||
//We can't do anything about it - no requests from this function
|
||||
continue;
|
||||
}
|
||||
else if(canBuild == EBuildingState::PREREQUIRES)
|
||||
@ -1230,85 +1222,7 @@ bool VCAI::tryBuildStructure(const CGTownInstance * t, BuildingID building, unsi
|
||||
return false;
|
||||
}
|
||||
|
||||
//bool VCAI::canBuildStructure(const CGTownInstance * t, BuildingID building, unsigned int maxDays=7)
|
||||
//{
|
||||
// if (maxDays == 0)
|
||||
// {
|
||||
// logAi->warn("Request to build building %d in 0 days!", building.toEnum());
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (!vstd::contains(t->town->buildings, building))
|
||||
// return false; // no such building in town
|
||||
//
|
||||
// if (t->hasBuilt(building)) //Already built? Shouldn't happen in general
|
||||
// return true;
|
||||
//
|
||||
// const CBuilding * buildPtr = t->town->buildings.at(building);
|
||||
//
|
||||
// auto toBuild = buildPtr->requirements.getFulfillmentCandidates([&](const BuildingID & buildID)
|
||||
// {
|
||||
// return t->hasBuilt(buildID);
|
||||
// });
|
||||
// toBuild.push_back(building);
|
||||
//
|
||||
// for(BuildingID buildID : toBuild)
|
||||
// {
|
||||
// EBuildingState::EBuildingState canBuild = cb->canBuildStructure(t, buildID);
|
||||
// if (canBuild == EBuildingState::HAVE_CAPITAL
|
||||
// || canBuild == EBuildingState::FORBIDDEN
|
||||
// || canBuild == EBuildingState::NO_WATER)
|
||||
// return false; //we won't be able to build this
|
||||
// }
|
||||
//
|
||||
// if (maxDays && toBuild.size() > maxDays)
|
||||
// return false;
|
||||
//
|
||||
// TResources currentRes = cb->getResourceAmount();
|
||||
// TResources income = estimateIncome();
|
||||
// //TODO: calculate if we have enough resources to build it in maxDays
|
||||
//
|
||||
// for(const auto & buildID : toBuild)
|
||||
// {
|
||||
// const CBuilding *b = t->town->buildings.at(buildID);
|
||||
//
|
||||
// EBuildingState::EBuildingState canBuild = cb->canBuildStructure(t, buildID);
|
||||
// if(canBuild == EBuildingState::ALLOWED)
|
||||
// {
|
||||
// if(!containsSavedRes(b->resources))
|
||||
// {
|
||||
// logAi->debug("Player %d will build %s in town of %s at %s", playerID, b->Name(), t->name, t->pos.toString());
|
||||
// return true;
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// else if(canBuild == EBuildingState::NO_RESOURCES)
|
||||
// {
|
||||
// TResources cost = t->town->buildings.at(buildID)->resources;
|
||||
// for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; i++)
|
||||
// {
|
||||
// int diff = currentRes[i] - cost[i] + income[i];
|
||||
// if(diff < 0)
|
||||
// saving[i] = 1;
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// else if (canBuild == EBuildingState::PREREQUIRES)
|
||||
// {
|
||||
// // can happen when dependencies have their own missing dependencies
|
||||
// if (canBuildStructure(t, buildID, maxDays - 1))
|
||||
// return true;
|
||||
// }
|
||||
// else if (canBuild == EBuildingState::MISSING_BASE)
|
||||
// {
|
||||
// if (canBuildStructure(t, b->upgrade, maxDays - 1))
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
bool VCAI::tryBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays)
|
||||
bool VCAI::tryBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays) const
|
||||
{
|
||||
for(const auto & building : buildList)
|
||||
{
|
||||
@ -1320,7 +1234,7 @@ bool VCAI::tryBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID
|
||||
return false; //Can't build anything
|
||||
}
|
||||
|
||||
BuildingID VCAI::canBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays)
|
||||
BuildingID VCAI::canBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays) const
|
||||
{
|
||||
for(const auto & building : buildList)
|
||||
{
|
||||
@ -1332,7 +1246,7 @@ BuildingID VCAI::canBuildAnyStructure(const CGTownInstance * t, std::vector<Buil
|
||||
return BuildingID::NONE; //Can't build anything
|
||||
}
|
||||
|
||||
bool VCAI::tryBuildNextStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays)
|
||||
bool VCAI::tryBuildNextStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays) const
|
||||
{
|
||||
for(const auto & building : buildList)
|
||||
{
|
||||
@ -1358,7 +1272,7 @@ static const BuildingID _spells[] = {BuildingID::MAGES_GUILD_1, BuildingID::MAGE
|
||||
static const BuildingID extra[] = {BuildingID::RESOURCE_SILO, BuildingID::SPECIAL_1, BuildingID::SPECIAL_2, BuildingID::SPECIAL_3,
|
||||
BuildingID::SPECIAL_4, BuildingID::SHIPYARD}; // all remaining buildings
|
||||
|
||||
void VCAI::buildStructure(const CGTownInstance * t)
|
||||
void VCAI::buildStructure(const CGTownInstance * t) const
|
||||
{
|
||||
//TODO make *real* town development system
|
||||
//TODO: faction-specific development: use special buildings, build dwellings in better order, etc
|
||||
|
@ -133,12 +133,12 @@ public:
|
||||
|
||||
//try build an unbuilt structure in maxDays at most (0 = indefinite)
|
||||
/*bool canBuildStructure(const CGTownInstance * t, BuildingID building, unsigned int maxDays=7);*/
|
||||
bool tryBuildStructure(const CGTownInstance * t, BuildingID building, unsigned int maxDays = 7);
|
||||
bool tryBuildStructure(const CGTownInstance * t, BuildingID building, unsigned int maxDays = 7) const;
|
||||
//try build ANY unbuilt structure
|
||||
BuildingID canBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays = 7);
|
||||
bool tryBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays = 7);
|
||||
BuildingID canBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays = 7) const;
|
||||
bool tryBuildAnyStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays = 7) const;
|
||||
//try build first unbuilt structure
|
||||
bool tryBuildNextStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays = 7);
|
||||
bool tryBuildNextStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays = 7) const;
|
||||
|
||||
friend class FuzzyHelper;
|
||||
|
||||
@ -269,7 +269,7 @@ public:
|
||||
|
||||
void recruitHero(const CGTownInstance * t, bool throwing = false);
|
||||
bool isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, SectorMap & sm);
|
||||
void buildStructure(const CGTownInstance * t);
|
||||
void buildStructure(const CGTownInstance * t) const;
|
||||
//void recruitCreatures(const CGTownInstance * t);
|
||||
void recruitCreatures(const CGDwelling * d, const CArmedInstance * recruiter);
|
||||
bool canGetArmy(const CGHeroInstance * h, const CGHeroInstance * source); //can we get any better stacks from other hero?
|
||||
|
Loading…
Reference in New Issue
Block a user