1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-23 21:29:13 +02:00

1.Support for cage of Warlord, Temple of Valhalla, Wall of Knowledge, Order of Fire

2.Level-up from newly implemented School of War crashed the game.
3.A sketch of shops support
This commit is contained in:
DjWarmonger 2009-09-21 09:00:33 +00:00
parent bff3abe122
commit b29ac50dcb
6 changed files with 180 additions and 14 deletions

View File

@ -4350,3 +4350,27 @@ void CPuzzleWindow::show(SDL_Surface * to)
if(screen->w != 800 || screen->h !=600)
CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15);
}
bool CShopWindow::swapItem (ui16 which, bool choose)
{
bool itemFound = false;
if (choose == true) //choose item
{
if (chosen.count(which))
{
itemFound = true;
chosen[which] = avaliable[which];
avaliable.erase(which);
}
}
else //return item to avaliable list
{
if (avaliable.count(which))
{
itemFound = true;
avaliable[which] = chosen[which];
chosen.erase(which);
}
}
return itemFound;
}

View File

@ -762,4 +762,25 @@ public:
~CPuzzleWindow();
};
class CShopWindow : public CIntObject
{
public:
std::map<ui16, Component> avaliable, chosen, bought;
bool swapItem (ui16 which, bool choose);
};
class CArtMerchantWindow : public CShopWindow
{};
class CUniversityWindow : public CShopWindow
{};
class CAltarWindow : public CShopWindow
{};
class CRefugeeCampWindow : public CShopWindow
{};
class CWarMachineWindow : public CShopWindow
{};
class CFreelancersWindow : public CShopWindow
{};
class CHillFortWindow : public CIntObject //garrison dialog? shop?
{};
#endif //__GUICLASSES_H__

View File

@ -1392,6 +1392,16 @@ int CGTownInstance::getSightRadious() const //returns sight distance
return 5;
}
void CGTownInstance::setPropertyDer(ui8 what, ui32 val)
{
///this is freakin' overcomplicated solution
switch (what)
{
case 11: //add visitor of town building
bonusingBuildings[val]->setProperty (4, visitingHero->id);
break;
}
}
int CGTownInstance::fortLevel() const //0 - none, 1 - fort, 2 - citadel, 3 - castle
{
if((builtBuildings.find(9))!=builtBuildings.end())
@ -1542,9 +1552,9 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
cb->setOwner(id, h->tempOwner);
}
}
for (std::vector<CGTownBuilding*>::const_iterator i = bonusingBuildings.begin(); i != bonusingBuildings.end(); i++)
(*i)->onHeroVisit (h); //does not work
cb->heroVisitCastle(id, h->id);
for (std::vector<CGTownBuilding*>::const_iterator i = bonusingBuildings.begin(); i != bonusingBuildings.end(); i++)
(*i)->onHeroVisit (h); //put it inside heroVisitCastle call, make sure *visitingHero is set
}
void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const
@ -1564,13 +1574,13 @@ void CGTownInstance::initObj()
if(creatureDwelling(i,true))
creatures[i].second.push_back(town->upgradedCreatures[i]);
}
switch (alignment)
switch (subID)
{ //add new visitable objects
case 2: case 3: case 5: case 6:
bonusingBuildings.push_back(new CTownBonus(23, this));
bonusingBuildings.push_back (new CTownBonus(23, this));
break;
case 7:
bonusingBuildings.push_back(new CTownBonus(17, this));
bonusingBuildings.push_back (new CTownBonus(17, this));
break;
}
}
@ -1923,6 +1933,12 @@ CTownBonus::CTownBonus (int index, CGTownInstance *TOWN)
{
ID = index;
town = TOWN;
id = town->bonusingBuildings.size();
}
void CTownBonus::setProperty (ui8 what, ui32 val)
{
if(what == 4)
visitors.insert(val);
}
void CTownBonus::onHeroVisit (const CGHeroInstance * h) const
{
@ -1933,7 +1949,7 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const
switch (ID)
{
case 23:
switch(town->alignment)
switch(town->subID)
{
case 2: //wall
cb->changePrimSkill (heroID, 3, 1);
@ -1954,7 +1970,7 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const
}
break;
case 17:
switch(town->alignment)
switch(town->subID)
{
case 7: //cage of warlords
cb->changePrimSkill (heroID, 1, 1);
@ -1964,10 +1980,10 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const
break;
}
iw.player = cb->getOwner(heroID);
iw.text << std::pair<ui8,ui32>(11,66);
iw.text << VLC->generaltexth->buildings[town->subID][ID].second;
//iw.soundID = sound;
cb->showInfoDialog(&iw);
cb->setObjProperty (id, 4, h->id); //add to visitors
cb->setObjProperty (town->id, 11, id); //add to visitors
}
}
bool CArmedInstance::needsLastStack() const
@ -4540,3 +4556,55 @@ void CCartographer::buyMap (const CGHeroInstance *h, ui32 accept) const
cb->setObjProperty (id, 10, h->tempOwner);
}
}
void CShop::setPropertyDer (ui8 what, ui32 val)
{
switch (what)
{
case 13: //sweep
avaliable.clear();
chosen.clear();
bought.clear();
break;
case 14: //reset - get new items
reset(val);
break;
}
}
void CGArtMerchant::reset(ui32 val)
{
std::vector<CArtifact*>::iterator index;
for (ui8 i = 0; i <= 6; i++)
{
int count = 0;
std::vector<CArtifact*> arts; //to avoid addition of different tiers
switch (i)
{
case 0:
cb->getAllowed (arts, CArtifact::ART_TREASURE);
count = 2;
break;
case 1:
cb->getAllowed (arts, CArtifact::ART_MINOR);
count = 2;
break;
case 2:
cb->getAllowed (arts, CArtifact::ART_MAJOR);
count = 1;
break;
case 3:
cb->getAllowed (arts, CArtifact::ART_RELIC);
count = 1;
break;
}
for (ui8 n = 0; n < count; n++)
{
index = arts.begin() + val % arts.size();
avaliable [avaliable.size()] = new Component (Component::ARTIFACT, (*index)->id, 0, 0);
arts.erase(index);
val *= (id + n * i); //randomize
}
}
}

View File

@ -42,6 +42,7 @@ class CGDefInfo;
class CSpecObjInfo;
struct TerrainTile;
struct InfoWindow;
struct Component;
struct BankConfig;
class CGBoat;
@ -355,25 +356,33 @@ public:
h & visitors & ttype;
}
};
class DLL_EXPORT CGTownBuilding : IObjectInterface
class DLL_EXPORT CGTownBuilding : public IObjectInterface
{
///basic class for town structures handled as map objects
public:
si32 ID; //from buildig list
si32 id; //identifies its index on towns vector
CGTownInstance *town;
virtual void onHeroVisit (const CGHeroInstance * h) const {};
template <typename Handler> void serialize(Handler &h, const int version)
{
h & ID & id;
}
};
class DLL_EXPORT CTownBonus : public CGVisitableOPH, public CGTownBuilding
class DLL_EXPORT CTownBonus : public CGTownBuilding
{
///used for one-time bonusing structures
///feel free to merge inheritance tree
public:
std::set<si32> visitors;
void setProperty(ui8 what, ui32 val);
void onHeroVisit (const CGHeroInstance * h) const;
CTownBonus (int index, CGTownInstance *TOWN);
CTownBonus (){ID = 0; town = NULL;};
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGObjectInstance&>(*this);
h & static_cast<CGTownBuilding&>(*this);
h & visitors;
}
};
@ -417,6 +426,7 @@ public:
int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
int getSightRadious() const; //returns sight distance
void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
void setPropertyDer(ui8 what, ui32 val);
//////////////////////////////////////////////////////////////////////////
@ -927,6 +937,31 @@ public:
};
class DLL_EXPORT CShop : public CGObjectInstance
{
///base class for university, art merchant, slave market etc.
public:
std::map<ui16, Component*> avaliable;
std::map<ui16, Component*> chosen, bought; //redundant?
//keys are unique for all three maps
std::map<ui16, ui32> price;
void initObj() {};
void setPropertyDer (ui8 what, ui32 val);
void newTurn() const {};
virtual void reset (ui32 val) {};
void onHeroVisit (const CGHeroInstance * h) const {};
virtual void trade (const CGHeroInstance * h) const {};
template <typename Handler> void serialize(Handler &h, const int version)
{
h & avaliable & chosen & bought & price;
}
};
class DLL_EXPORT CGArtMerchant : public CShop
{
void reset (ui32 val);
};
struct BankConfig
{
BankConfig() {level = chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };

View File

@ -26,6 +26,7 @@ struct InfoWindow;
struct MetaString;
struct ShowInInfobox;
struct BattleResult;
struct Component;
class CGameState;
struct PlayerSettings;
struct CPackForClient;
@ -94,7 +95,7 @@ public:
virtual void sendAndApply(CPackForClient * info)=0;
virtual void heroExchange(si32 hero1, si32 hero2)=0; //when two heroes meet on adventure map
friend struct CPack;
friend struct CPackForClient;
friend struct CPackForServer;
};

View File

@ -673,6 +673,22 @@ struct HeroLevelUp : public Query//2000
}
};
struct TradeComponents : public CPackForClient, public CPackForServer
{
///used to handle info about components avaliable in shops
void applyCl(CClient *cl);
DLL_EXPORT void applyGs(CGameState *gs);
si32 heroid;
ui32 objectid;
std::map<ui16, Component> avaliable, chosen, bought;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id & heroid & objectid & avaliable & chosen & bought;
}
};
//A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
//Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
//Until sending reply player won't be allowed to take any actions
@ -1042,6 +1058,7 @@ struct ShowInInfobox : public CPackForClient //107
}
};
/***********************************************************************************************************/
struct CloseServer : public CPackForServer