1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-14 02:33:51 +02:00

Little more changes.

This commit is contained in:
Michał W. Urbańczyk 2010-12-09 23:10:28 +00:00
parent f020562570
commit 69b97e0a51
7 changed files with 17 additions and 20 deletions

View File

@ -60,7 +60,7 @@ CGeniusAI::HypotheticalGameState::TownModel::TownModel(
{ {
hasBuilt = static_cast<bool>(t->builded); hasBuilt = static_cast<bool>(t->builded);
creaturesToRecruit = t->creatures; creaturesToRecruit = t->creatures;
creaturesInGarrison = t->getArmy(); //creaturesInGarrison = t->getArmy();
} }
CGeniusAI::HypotheticalGameState::HypotheticalGameState(CGeniusAI& ai) CGeniusAI::HypotheticalGameState::HypotheticalGameState(CGeniusAI& ai)
@ -317,8 +317,8 @@ float CGeniusAI::TownObjective::getValue() const
case upgradeCreatures: case upgradeCreatures:
UpgradeInfo ui = AI->m_cb->getUpgradeInfo(whichTown->t,which); UpgradeInfo ui = AI->m_cb->getUpgradeInfo(whichTown->t,which);
ID = whichTown->creaturesInGarrison.getCreature(which)->idNumber; ID = whichTown->t->getCreature(which)->idNumber;
howMany = whichTown->creaturesInGarrison.getStackCount(which); howMany = whichTown->t->getStackCount(which);
newID = ui.newID.back(); newID = ui.newID.back();
int upgrade_serial = ui.newID.size() - 1; int upgrade_serial = ui.newID.size() - 1;
@ -425,7 +425,7 @@ void CGeniusAI::TownObjective::print() const
case upgradeCreatures: case upgradeCreatures:
UpgradeInfo ui = AI->m_cb->getUpgradeInfo (whichTown->t, which); UpgradeInfo ui = AI->m_cb->getUpgradeInfo (whichTown->t, which);
ID = whichTown->creaturesInGarrison.getCreature(which)->idNumber; ID = whichTown->t->getCreature(which)->idNumber;
tlog6 << "upgrade " << VLC->creh->creatures[ID]->namePl; tlog6 << "upgrade " << VLC->creh->creatures[ID]->namePl;
//ui.cost //ui.cost
break; break;
@ -746,8 +746,7 @@ void CGeniusAI::HeroObjective::fulfill(CGeniusAI& cg, HypotheticalGameState& hgs
{ {
//upgrade hero's units //upgrade hero's units
tlog6 << "visiting town" << endl; tlog6 << "visiting town" << endl;
CCreatureSet hcreatures = h->h->getArmy(); for (TSlots::const_iterator i = h->h->Slots().begin(); i != h->h->Slots().end(); i++)
for (TSlots::const_iterator i = hcreatures.Slots().begin(); i != hcreatures.Slots().end(); i++)
{ // For each hero slot. { // For each hero slot.
UpgradeInfo ui = cg.m_cb->getUpgradeInfo(h->h,i->first); UpgradeInfo ui = cg.m_cb->getUpgradeInfo(h->h,i->first);
@ -773,11 +772,10 @@ void CGeniusAI::HeroObjective::fulfill(CGeniusAI& cg, HypotheticalGameState& hgs
} }
// Give town's units to hero. // Give town's units to hero.
CCreatureSet tcreatures = town->getArmy();
int weakestCreatureStack; int weakestCreatureStack;
int weakestCreatureAIValue = 99999; // we will lower it in the process int weakestCreatureAIValue = 99999; // we will lower it in the process
for (TSlots::const_iterator i = tcreatures.Slots().begin(); i != tcreatures.Slots().end(); i++) for (TSlots::const_iterator i = town->Slots().begin(); i != town->Slots().end(); i++)
{ {
if (i->second->type->AIValue < weakestCreatureAIValue) if (i->second->type->AIValue < weakestCreatureAIValue)
{ {
@ -785,15 +783,14 @@ void CGeniusAI::HeroObjective::fulfill(CGeniusAI& cg, HypotheticalGameState& hgs
weakestCreatureStack = i->first; weakestCreatureStack = i->first;
} }
} }
for (TSlots::const_iterator i = tcreatures.Slots().begin(); i != tcreatures.Slots().end(); i++)\ for (TSlots::const_iterator i = town->Slots().begin(); i != town->Slots().end(); i++)\
{ // For each town slot. { // For each town slot.
hcreatures = h->h->getArmy(); int hSlot = h->h->getSlotFor(i->second->type->idNumber);
int hSlot = hcreatures.getSlotFor(i->second->type->idNumber);
if (hSlot == -1) if (hSlot == -1)
continue; continue;
tlog6 << "giving hero " << i->second->type->namePl << endl; tlog6 << "giving hero " << i->second->type->namePl << endl;
if (!hcreatures.slotEmpty(hSlot)) if (!h->h->slotEmpty(hSlot))
{ {
// Can't take garrisonHero's last unit. // Can't take garrisonHero's last unit.
if ( (i->first == weakestCreatureStack) && (town->garrisonHero != NULL) ) if ( (i->first == weakestCreatureStack) && (town->garrisonHero != NULL) )
@ -878,7 +875,7 @@ void CGeniusAI::addTownObjectives (HypotheticalGameState::TownModel& t, Hypothet
} }
// Upgrade creatures. // Upgrade creatures.
for (TSlots::const_iterator i = t.creaturesInGarrison.Slots().begin(); i != t.creaturesInGarrison.Slots().end(); i++) for (TSlots::const_iterator i = t.t->Slots().begin(); i != t.t->Slots().end(); i++)
{ {
UpgradeInfo ui = m_cb->getUpgradeInfo(t.t, i->first); UpgradeInfo ui = m_cb->getUpgradeInfo(t.t, i->first);
if (ui.newID.size()) if (ui.newID.size())
@ -955,7 +952,7 @@ void CGeniusAI::TownObjective::fulfill(CGeniusAI& cg,
case upgradeCreatures: case upgradeCreatures:
UpgradeInfo ui = cg.m_cb->getUpgradeInfo(whichTown->t, which); UpgradeInfo ui = cg.m_cb->getUpgradeInfo(whichTown->t, which);
ID = whichTown->creaturesInGarrison.getCreature(which)->idNumber; ID = whichTown->t->getCreature(which)->idNumber;
newID = ui.newID.back(); newID = ui.newID.back();
// TODO: reduce resources in hgs // TODO: reduce resources in hgs
cg.m_cb->upgradeCreature(whichTown->t, which, newID); cg.m_cb->upgradeCreature(whichTown->t, which, newID);

View File

@ -61,7 +61,7 @@ private:
TownModel(const CGTownInstance *t); TownModel(const CGTownInstance *t);
const CGTownInstance *t; const CGTownInstance *t;
std::vector<std::pair<ui32, std::vector<ui32> > > creaturesToRecruit; std::vector<std::pair<ui32, std::vector<ui32> > > creaturesToRecruit;
CCreatureSet creaturesInGarrison; //type, num //CCreatureSet creaturesInGarrison; //type, num
bool hasBuilt; bool hasBuilt;
}; };
HypotheticalGameState(){} HypotheticalGameState(){}

View File

@ -110,7 +110,7 @@ public:
void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){}; void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){};
void showThievesGuildWindow(int requestingObjId){}; void showThievesGuildWindow(int requestingObjId){};
void giveResource(int player, int which, int val){}; void giveResource(int player, int which, int val){};
void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures, bool remove) {}; void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet &creatures, bool remove) {};
void takeCreatures (int objid, TSlots creatures){}; void takeCreatures (int objid, TSlots creatures){};
void takeCreatures (int objid, std::vector<CStackBasicDescriptor> creatures){}; void takeCreatures (int objid, std::vector<CStackBasicDescriptor> creatures){};
bool changeStackType(const StackLocation &sl, CCreature *c){return false;}; bool changeStackType(const StackLocation &sl, CCreature *c){return false;};

View File

@ -4456,7 +4456,7 @@ void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward
{ {
CCreatureSet creatures; CCreatureSet creatures;
creatures.setCreature(0, rID, rVal); creatures.setCreature(0, rID, rVal);
cb->giveCreatures (id, h, creatures,false); cb->giveCreatures(id, h, creatures, false);
} }
break; break;
default: default:

View File

@ -87,7 +87,7 @@ public:
virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) =0; //cb will be called when player closes garrison window virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) =0; //cb will be called when player closes garrison window
virtual void showThievesGuildWindow(int requestingObjId) =0; virtual void showThievesGuildWindow(int requestingObjId) =0;
virtual void giveResource(int player, int which, int val)=0; virtual void giveResource(int player, int which, int val)=0;
virtual void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures, bool remove) =0; virtual void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet &creatures, bool remove) =0;
//virtual void takeCreatures (int objid, TSlots creatures) =0; //virtual void takeCreatures (int objid, TSlots creatures) =0;
virtual void takeCreatures (int objid, std::vector<CStackBasicDescriptor> creatures) =0; virtual void takeCreatures (int objid, std::vector<CStackBasicDescriptor> creatures) =0;
virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0; virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0;

View File

@ -2087,7 +2087,7 @@ void CGameHandler::giveResource(int player, int which, int val)
sr.val = gs->players.find(player)->second.resources[which]+val; sr.val = gs->players.find(player)->second.resources[which]+val;
sendAndApply(&sr); sendAndApply(&sr);
} }
void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures, bool remove) void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet &creatures, bool remove)
{ {
assert(0); assert(0);
// if (creatures.stacksCount() <= 0) // if (creatures.stacksCount() <= 0)

View File

@ -138,7 +138,7 @@ public:
void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb); void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb);
void showThievesGuildWindow(int requestingObjId); //TODO: make something more general? void showThievesGuildWindow(int requestingObjId); //TODO: make something more general?
void giveResource(int player, int which, int val); void giveResource(int player, int which, int val);
void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures, bool remove); void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet &creatures, bool remove);
void takeCreatures (int objid, std::vector<CStackBasicDescriptor> creatures); void takeCreatures (int objid, std::vector<CStackBasicDescriptor> creatures);
bool changeStackType(const StackLocation &sl, CCreature *c); bool changeStackType(const StackLocation &sl, CCreature *c);
bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false); bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false);