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

1.Fixes for RazeStructures net packs.

2.Support for Pyramid. Unfortunately untested entirely as combats won't work on my system.
This commit is contained in:
DjWarmonger 2009-09-24 17:54:02 +00:00
parent 9a1669b926
commit 55925e0eea
12 changed files with 122 additions and 9 deletions

View File

@ -43,7 +43,7 @@ extern CLodHandler * bitmaph;
extern boost::rand48 ran;
std::map <ui8, std::set <ui8> > CGKeys::playerKeyMap;
std::map <si32, std::vector<si32> > CGMagi::eyelist;
BankConfig CGPyramid::pyramidConfig;
void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
{};
@ -1624,9 +1624,8 @@ void CGTownInstance::removeCapitols (ui8 owner, bool me) const
RazeStructures rs;
rs.tid = id;
rs.bid.insert(13);
si16 builded = destroyed;
rs.destroyed = destroyed;
cb->sendAndApply(&rs);
//cb->gameState()->getTown(id)->builtBuildings.erase(13); //destroy local capitol
return;
}
else
@ -4249,6 +4248,72 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
cb->setObjProperty (id, 14, ran()); //reset
}
void CGPyramid::initObj()
{
//would be nice to do that only once
if (!pyramidConfig.guards.size())
{
pyramidConfig.level = 1;
pyramidConfig.chance = 100;
pyramidConfig.upgradeChance = 0;
for (int i = 0; i < 2; ++i)
{
pyramidConfig.guards.push_back (std::pair <ui16, ui32>(116, 20));
pyramidConfig.guards.push_back (std::pair <ui16, ui32>(117, 10));
}
pyramidConfig.combatValue; //how hard are guards of this level
pyramidConfig.value; //overall value of given things
pyramidConfig.rewardDifficulty; //proportion of reward value to difficulty of guards; how profitable is this creature Bank config
pyramidConfig.easiest; //?!?
}
bc = &pyramidConfig;
std::vector<ui16> avaliable;
cb->getAllowedSpells (avaliable, 5);
spell = (avaliable[rand()%avaliable.size()]);
}
void CGPyramid::onHeroVisit (const CGHeroInstance * h) const
{
if (bc)
{
BlockingDialog bd (true, false);
bd.player = h->getOwner();
bd.soundID = soundBase::DANGER;
bd.text << VLC->generaltexth->advobtxt[105];
cb->showBlockingDialog (&bd, boost::bind (&CBank::fightGuards, this, h, _1));
}
else
{
InfoWindow iw;
iw.text << VLC->generaltexth->advobtxt[107];
iw.components.push_back (Component (Component::LUCK, 0 , -2, 0));
GiveBonus gb;
gb.bonus = HeroBonus(HeroBonus::ONE_BATTLE,HeroBonus::LUCK,HeroBonus::OBJECT,-2,id,VLC->generaltexth->arraytxt[ID]);
cb->giveHeroBonus(&gb);
cb->showInfoDialog(&iw);
}
}
void CGPyramid::endBattle (const CGHeroInstance *h, const BattleResult *result) const
{
if (result->winner == 0)
{
InfoWindow iw;
iw.text.addTxt (MetaString::ADVOB_TXT, 106);
iw.text.addTxt (MetaString::SPELL_NAME, spell);
if (!h->getArt(17)) //no spellbook
iw.text.addTxt (MetaString::ADVOB_TXT, 109);
else if (h->getSecSkillLevel(7) < 3) //no expert Wisdom
iw.text.addTxt (MetaString::ADVOB_TXT, 108);
else
{
std::set<ui32> spells;
spells.insert (spell);
cb->changeSpells (h->id, true, spells);
iw.components.push_back(Component (Component::SPELL, spell, 0, 0));
}
cb->showInfoDialog(&iw);
}
}
void CGKeys::setPropertyDer (ui8 what, ui32 val) //101-108 - enable key for player 1-8
{
if (what >= 101 && what <= (100 + PLAYER_LIMIT))
@ -4658,7 +4723,7 @@ void CShop::setPropertyDer (ui8 what, ui32 val)
void CGArtMerchant::reset(ui32 val)
{
std::vector<CArtifact*>::iterator index;
for (ui8 i = 0; i <= 6; i++)
for (ui8 i = 0; i < 4; ++i) //each tier
{
int count = 0;
std::vector<CArtifact*> arts; //to avoid addition of different tiers

View File

@ -912,6 +912,24 @@ class DLL_EXPORT CBank : public CArmedInstance
h & index & multiplier & artifacts & daycounter;
}
};
class DLL_EXPORT CGPyramid : public CBank
{
public:
static BankConfig pyramidConfig;
ui16 spell;
void initObj();
void newTurn() const {}; //empty, no reset
void onHeroVisit (const CGHeroInstance * h) const;
void fightGuards (const CGHeroInstance *h, ui32 accept) const {};
void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGObjectInstance&>(*this);
h & spell;
}
};
class CGShipyard : public CGObjectInstance, public IShipyard
{

View File

@ -122,7 +122,10 @@ namespace SRSLPraserHelpers
}
}
using namespace SRSLPraserHelpers;
CSpellHandler::CSpellHandler()
{
VLC->spellh = this;
}
std::set<ui16> CSpell::rangeInHexes(unsigned int centralHex, ui8 schoolLvl ) const
{
std::set<ui16> ret;

View File

@ -6,6 +6,7 @@
#include <set>
#include "CSoundBase.h"
//#include "map.h"
/*
* CSpellHandler.h, part of VCMI engine
@ -53,6 +54,7 @@ public:
class DLL_EXPORT CSpellHandler
{
public:
CSpellHandler::CSpellHandler();
std::vector<CSpell> spells;
void loadSpells();

View File

@ -5,6 +5,7 @@
#include "../hch/CObjectHandler.h"
#include "../StartInfo.h"
#include "../hch/CArtHandler.h"
#include "../hch/CSpellHandler.h"
#include "../lib/VCMI_Lib.h"
/*
@ -190,6 +191,17 @@ void IGameCallback::getAllowed(std::vector<CArtifact*> &out, int flags)
getAllowedArts(out,&CArtHandler::relics);
}
void IGameCallback::getAllowedSpells(std::vector<ui16> &out, ui16 level)
{
for (int i = 0; i < (VLC->spellh->spells).size(); i++)
{
if (isAllowed (1, i))
{
out.push_back(i);
}
}
}
int3 IGameCallback::getMapSize()
{
return int3(gs->map->width, gs->map->height, gs->map->twoLevel + 1);

View File

@ -59,6 +59,7 @@ public:
virtual bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact
virtual void getAllowedArts(std::vector<CArtifact*> &out, std::vector<CArtifact*> CArtHandler::*arts);
virtual void getAllowed(std::vector<CArtifact*> &out, int flags); //flags: bitfield uses EartClass
virtual void getAllowedSpells(std::vector<ui16> &out, ui16 level);
virtual int3 getMapSize(); //returns size of the map
virtual TerrainTile * getTile(int3 pos);

View File

@ -453,15 +453,19 @@ struct NewStructures : public CPackForClient //504
h & tid & bid & builded;
}
};
struct RazeStructures : public NewStructures //505
struct RazeStructures : public CPackForClient //505
{
RazeStructures() {type = 505;};
void applyCl (CClient *cl);
DLL_EXPORT void applyGs(CGameState *gs);
si32 tid;
std::set<si32> bid;
si16 destroyed;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & tid & bid & builded;
h & tid & bid & destroyed;
}
};
struct SetAvailableCreatures : public CPackForClient //506

View File

@ -359,7 +359,7 @@ DLL_EXPORT void RazeStructures::applyGs( CGameState *gs )
{
t->builtBuildings.erase(id);
}
t->destroyed = builded; //yeaha
t->destroyed = destroyed; //yeaha
}
DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs )
{

View File

@ -53,6 +53,7 @@ void registerTypes1(Serializer &s)
s.template registerType<CGSirens>();
s.template registerType<CGOnceVisitable>();
s.template registerType<CBank>();
s.template registerType<CGPyramid>();
s.template registerType<CGShipyard>();
s.template registerType<CCartographer>();
s.template registerType<CGObjectInstance>();

View File

@ -1943,6 +1943,11 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
nobj = new CBank();
break;
}
case 63: //Pyramid
{
nobj = new CGPyramid();
break;
}
case 13: //Cartographer
{
nobj = new CCartographer();

View File

@ -406,10 +406,12 @@ struct DLL_EXPORT Mapa : public CMapHeader
objects.resize(hlp);
}
//static structures
h & CGTeleport::objs;
h & CGTeleport::gates;
h & CGKeys::playerKeyMap;
h & CGMagi::eyelist;
h & CGPyramid::pyramidConfig;
for(int i=0; i<objects.size(); i++)
{

View File

@ -2044,7 +2044,7 @@ bool CGameHandler::razeStructure (si32 tid, si32 bid)
RazeStructures rs;
rs.tid = tid;
rs.bid.insert(bid);
rs.builded = t->destroyed + 1; //define TRUE FALSE?
rs.destroyed = t->destroyed + 1;
sendAndApply(&rs);
return true;
}