1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Minor changes (serialization and related)

This commit is contained in:
Michał W. Urbańczyk
2008-12-31 09:33:46 +00:00
parent 4a8ae4ed9a
commit f853074d20
8 changed files with 143 additions and 93 deletions

17
CMT.cpp
View File

@ -214,6 +214,23 @@ int main(int argc, char** argv)
tlog0 << "Ending...\n"; tlog0 << "Ending...\n";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
//else if(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4)
//{
// LOCPLINT->pim->lock();
// screen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, screen->format->BitsPerPixel, rmask, gmask, bmask, amask);
// SDL_SaveBMP(screen,"scra");
// SDL_SaveBMP(screen2,"scr2a");
// int hlp = SDL_BlitSurface(screen,0,screen2,0);
// SDL_SaveBMP(screen2,"scr2b");
// screen = SDL_SetVideoMode(screen->w,screen->h,screen->format->BitsPerPixel,
// SDL_SWSURFACE|SDL_DOUBLEBUF|((screen->flags&SDL_FULLSCREEN) ? 0 : SDL_FULLSCREEN));
// SDL_SaveBMP(screen,"scrb");
// SDL_BlitSurface(screen2,0,screen,0);
// SDL_SaveBMP(screen,"scrc");
// SDL_FreeSurface(screen2);
// SDL_Flip(screen);
// LOCPLINT->pim->unlock();
//}
eventsM.lock(); eventsM.lock();
events.push(ev); events.push(ev);
eventsM.unlock(); eventsM.unlock();

View File

@ -2579,7 +2579,7 @@ void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar
ser = i; ser = i;
ser -= from; ser -= from;
if(ser<0 || ser > SIZE) return; if(ser<0 || ser > SIZE) return;
int pom = std::min((which->movement)/100,(int)mobile->ourImages.size()-1); int pom = std::min((which->movement)/100,(si32)mobile->ourImages.size()-1);
blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point
} }
void CHeroList::draw() void CHeroList::draw()

View File

@ -86,7 +86,7 @@ GUISettings
Statusbar: x=8 y=723 graphic=ADROLLVR2.pcx; Statusbar: x=8 y=723 graphic=ADROLLVR2.pcx;
ResDataBar: x=0 y=743 graphic=ZRESBAR2.pcx offsetX=65 offsetY=2 resSpace=109 resDateSpace=135; ResDataBar: x=0 y=743 graphic=ZRESBAR2.pcx offsetX=65 offsetY=2 resSpace=109 resDateSpace=135;
ButtonKingdomOv: x=903 y=197 graphic=IAM002L.DEF playerColoured=1; ButtonKingdomOv: x=903 y=197 graphic=IAM002L.DEF playerColoured=1;
ButtonUnderground: x=903 y=230 graphic=IAM010L.DEF playerColoured=1 additionalDefs=(IAM003L.DEF); ButtonUnderground: x=903 y=229 graphic=IAM010L.DEF playerColoured=1 additionalDefs=(IAM003L.DEF);
ButtonQuestLog: x=903 y=261 graphic=IAM004L.DEF playerColoured=1; ButtonQuestLog: x=903 y=261 graphic=IAM004L.DEF playerColoured=1;
ButtonSleepWake: x=903 y=294 graphic=IAM005L.DEF playerColoured=1; ButtonSleepWake: x=903 y=294 graphic=IAM005L.DEF playerColoured=1;
ButtonMoveHero: x=903 y=327 graphic=IAM006L.DEF playerColoured=1; ButtonMoveHero: x=903 y=327 graphic=IAM006L.DEF playerColoured=1;

View File

@ -154,7 +154,6 @@ CGObjectInstance::CGObjectInstance(): animPhaseShift(rand()%0xff)
//state = new CLuaObjectScript(); //state = new CLuaObjectScript();
ID = subID = id = -1; ID = subID = id = -1;
defInfo = NULL; defInfo = NULL;
state = NULL;
info = NULL; info = NULL;
tempOwner = 254; tempOwner = 254;
blockVisit = false; blockVisit = false;
@ -166,34 +165,34 @@ CGObjectInstance::~CGObjectInstance()
// delete state; // delete state;
//state=NULL; //state=NULL;
} }
CGObjectInstance::CGObjectInstance(const CGObjectInstance & right) //CGObjectInstance::CGObjectInstance(const CGObjectInstance & right)
{ //{
pos = right.pos; // pos = right.pos;
ID = right.ID; // ID = right.ID;
subID = right.subID; // subID = right.subID;
id = right.id; // id = right.id;
defInfo = right.defInfo; // defInfo = right.defInfo;
info = right.info; // info = right.info;
blockVisit = right.blockVisit; // blockVisit = right.blockVisit;
//state = new CLuaObjectScript(right.state->); // //state = new CLuaObjectScript(right.state->);
//*state = *right.state; // //*state = *right.state;
//state = right.state; // //state = right.state;
tempOwner = right.tempOwner; // tempOwner = right.tempOwner;
} //}
CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right) //CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
{ //{
pos = right.pos; // pos = right.pos;
ID = right.ID; // ID = right.ID;
subID = right.subID; // subID = right.subID;
id = right.id; // id = right.id;
defInfo = right.defInfo; // defInfo = right.defInfo;
info = right.info; // info = right.info;
blockVisit = right.blockVisit; // blockVisit = right.blockVisit;
//state = new CLuaObjectScript(); // //state = new CLuaObjectScript();
//*state = *right.state; // //*state = *right.state;
tempOwner = right.tempOwner; // tempOwner = right.tempOwner;
return *this; // return *this;
} //}
const std::string & CGObjectInstance::getHoverText() const const std::string & CGObjectInstance::getHoverText() const
{ {
@ -380,7 +379,7 @@ int CGHeroInstance::getSightDistance() const //returns sight distance of this he
return 6 + getSecSkillLevel(3); //default + scouting return 6 + getSecSkillLevel(3); //default + scouting
} }
int CGHeroInstance::manaLimit() const si32 CGHeroInstance::manaLimit() const
{ {
double modifier = 1.0; double modifier = 1.0;
switch(getSecSkillLevel(24)) //intelligence level switch(getSecSkillLevel(24)) //intelligence level
@ -418,7 +417,7 @@ int CGHeroInstance::getPrimSkillLevel(int id) const
{ {
return primSkills[id]; return primSkills[id];
} }
int CGHeroInstance::getSecSkillLevel(const int & ID) const ui8 CGHeroInstance::getSecSkillLevel(const int & ID) const
{ {
for(size_t i=0; i < secSkills.size(); ++i) for(size_t i=0; i < secSkills.size(); ++i)
if(secSkills[i].first==ID) if(secSkills[i].first==ID)

View File

@ -28,20 +28,24 @@ class DLL_EXPORT CCastleEvent
{ {
public: public:
std::string name, message; std::string name, message;
int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources std::vector<si32> resources; //gain / loss of resources
unsigned char players; //players for whom this event can be applied ui8 players; //players for whom this event can be applied
bool forHuman, forComputer; ui8 forHuman, forComputer;
int firstShow; //postpone of first encounter time in days ui32 firstShow; //postpone of first encounter time in days
int forEvery; //every n days this event will occure ui32 forEvery; //every n days this event will occure
ui8 bytes[6]; //build specific buildings (raw format, similar to town's)
unsigned char bytes[6]; //build specific buildings (raw format, similar to town's) si32 gen[7]; //additional creatures in i-th level dwelling
int gen[7]; //additional creatures in i-th level dwelling
bool operator<(const CCastleEvent &drugie) const bool operator<(const CCastleEvent &drugie) const
{ {
return firstShow<drugie.firstShow; return firstShow<drugie.firstShow;
} }
template <typename Handler> void serialize(Handler &h, const int version)
{
h & name & message & resources & players & forHuman & forComputer & firstShow
& forEvery & bytes & gen;
}
}; };
class CQuest class CQuest
@ -57,6 +61,12 @@ public:
std::vector<ui32> m7resources; std::vector<ui32> m7resources;
std::string firstVisitText, nextVisitText, completedText; std::string firstVisitText, nextVisitText, completedText;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & missionType & lastDay & m13489val & m2stats & m5arts & m6creatures & m7resources
& firstVisitText & nextVisitText & completedText;
}
}; };
class DLL_EXPORT IObjectInterface class DLL_EXPORT IObjectInterface
@ -79,14 +89,13 @@ protected:
public: public:
mutable std::string hoverName; mutable std::string hoverName;
int3 pos; //h3m pos int3 pos; //h3m pos
int ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34 si32 ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34
si32 id;//number of object in CObjectHandler's vector si32 id;//number of object in CObjectHandler's vector
CGDefInfo * defInfo; CGDefInfo * defInfo;
CCPPObjectScript * state;
CSpecObjInfo * info; CSpecObjInfo * info;
unsigned char animPhaseShift; ui8 animPhaseShift;
ui8 tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna ui8 tempOwner;
ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile
int getOwner() const; int getOwner() const;
@ -98,13 +107,20 @@ public:
bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
CGObjectInstance(); CGObjectInstance();
virtual ~CGObjectInstance(); virtual ~CGObjectInstance();
CGObjectInstance(const CGObjectInstance & right); //CGObjectInstance(const CGObjectInstance & right);
CGObjectInstance& operator=(const CGObjectInstance & right); //CGObjectInstance& operator=(const CGObjectInstance & right);
virtual const std::string & getHoverText() const; virtual const std::string & getHoverText() const;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void initObj(); void initObj();
friend class CGameHandler; friend class CGameHandler;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & hoverName & pos & ID & subID & id & animPhaseShift & tempOwner & blockVisit;
//TODO: definfo
}
}; };
class DLL_EXPORT CArmedInstance: public CGObjectInstance class DLL_EXPORT CArmedInstance: public CGObjectInstance
@ -112,6 +128,11 @@ class DLL_EXPORT CArmedInstance: public CGObjectInstance
public: public:
CCreatureSet army; //army CCreatureSet army; //army
virtual bool needsLastStack() const; //true if last stack cannot be taken virtual bool needsLastStack() const; //true if last stack cannot be taken
template <typename Handler> void serialize(Handler &h, const int version)
{
h & army;
}
}; };
class DLL_EXPORT CGHeroInstance : public CArmedInstance class DLL_EXPORT CGHeroInstance : public CArmedInstance
@ -128,23 +149,23 @@ public:
CHero * type; CHero * type;
ui32 exp; //experience point ui32 exp; //experience point
int level; //current level of hero si32 level; //current level of hero
std::string name; //may be custom std::string name; //may be custom
std::string biography; //if custom std::string biography; //if custom
int portrait; //may be custom si32 portrait; //may be custom
int mana; // remaining spell points si32 mana; // remaining spell points
std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge std::vector<si32> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
std::vector<std::pair<ui8,ui8> > secSkills; //first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert); if hero has ability (-1, -1) it meansthat it should have default secondary abilities std::vector<std::pair<ui8,ui8> > secSkills; //first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert); if hero has ability (-1, -1) it meansthat it should have default secondary abilities
int movement; //remaining movement points si32 movement; //remaining movement points
int identifier; //from the map file si32 identifier; //from the map file
bool sex; ui8 sex;
struct DLL_EXPORT Patrol struct DLL_EXPORT Patrol
{ {
Patrol(){patrolling=false;patrolRadious=-1;}; Patrol(){patrolling=false;patrolRadious=-1;};
bool patrolling; bool patrolling;
int patrolRadious; int patrolRadious;
} patrol; } patrol;
bool inTownGarrison; // if hero is in town garrison ui8 inTownGarrison; // if hero is in town garrison
CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
std::vector<ui32> artifacts; //hero's artifacts from bag std::vector<ui32> artifacts; //hero's artifacts from bag
std::map<ui16,ui32> artifWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 std::map<ui16,ui32> artifWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
@ -152,6 +173,16 @@ public:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
template <typename Handler> void serialize(Handler &h, const int version)
{
h & exp & level & name & biography & portrait & mana & primSkills & secSkills & movement
& identifier & sex & inTownGarrison & artifacts & artifWorn & spells;
//TODO: type
//TODO: visited town
}
//////////////////////////////////////////////////////////////////////////
const std::string &getBiography() const; const std::string &getBiography() const;
bool needsLastStack()const; bool needsLastStack()const;
unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const; unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const;
@ -160,12 +191,12 @@ public:
float getMultiplicativeMoveBonus() const; float getMultiplicativeMoveBonus() const;
int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation' int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
int getSightDistance() const; //returns sight distance of this hero int getSightDistance() const; //returns sight distance of this hero
int manaLimit() const; //maximum mana value for this hero (basically 10*knowledge) si32 manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
bool canWalkOnSea() const; bool canWalkOnSea() const;
int getCurrentLuck() const; int getCurrentLuck() const;
int getCurrentMorale() const; int getCurrentMorale() const;
int getPrimSkillLevel(int id) const; int getPrimSkillLevel(int id) const;
int getSecSkillLevel(const int & ID) const; //0 - no skill ui8 getSecSkillLevel(const int & ID) const; //0 - no skill
int maxMovePoints(bool onLand) const; int maxMovePoints(bool onLand) const;
ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
void setArtAtPos(ui16 pos, int art); void setArtAtPos(ui16 pos, int art);
@ -190,13 +221,13 @@ class DLL_EXPORT CGTownInstance : public CArmedInstance
public: public:
CTown * town; CTown * town;
std::string name; // name of town std::string name; // name of town
int builded; //how many buildings has been built this turn si32 builded; //how many buildings has been built this turn
int destroyed; //how many buildings has been destroyed this turn si32 destroyed; //how many buildings has been destroyed this turn
const CGHeroInstance * garrisonHero, *visitingHero; const CGHeroInstance * garrisonHero, *visitingHero;
int identifier; //special identifier from h3m (only > RoE maps) ui32 identifier; //special identifier from h3m (only > RoE maps)
int alignment; si32 alignment;
std::set<si32> forbiddenBuildings, builtBuildings; std::set<si32> forbiddenBuildings, builtBuildings;
std::vector<int> possibleSpells, obligatorySpells; std::vector<ui32> possibleSpells, obligatorySpells;
std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
struct StrInfo struct StrInfo
@ -210,6 +241,19 @@ public:
} strInfo; } strInfo;
std::set<CCastleEvent> events; std::set<CCastleEvent> events;
//////////////////////////////////////////////////////////////////////////
template <typename Handler> void serialize(Handler &h, const int version)
{
h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings
& possibleSpells & obligatorySpells & spells & strInfo & events;
//TODO: town
//TODO: garrison/visiting hero
}
//////////////////////////////////////////////////////////////////////////
bool needsLastStack() const; bool needsLastStack() const;
int getSightDistance() const; //returns sight distance int getSightDistance() const; //returns sight distance

22
map.cpp
View File

@ -756,26 +756,15 @@ void Mapa::loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
for(int gh = 0; gh<numberOfEvent; ++gh) for(int gh = 0; gh<numberOfEvent; ++gh)
{ {
CCastleEvent nce; CCastleEvent nce;
int nameLen = readNormalNr(bufor,i); i+=4; nce.name = readString(bufor,i);
for(int ll=0; ll<nameLen; ++ll) nce.message = readString(bufor,i);
{
nce.name += bufor[i]; ++i;
}
int messLen = readNormalNr(bufor,i); i+=4; for(int x=0; x < 7; x++)
for(int ll=0; ll<messLen; ++ll)
{ {
nce.message += bufor[i]; ++i; nce.resources[x] = readNormalNr(bufor,i);
i+=4;
} }
nce.wood = readNormalNr(bufor,i); i+=4;
nce.mercury = readNormalNr(bufor,i); i+=4;
nce.ore = readNormalNr(bufor,i); i+=4;
nce.sulfur = readNormalNr(bufor,i); i+=4;
nce.crystal = readNormalNr(bufor,i); i+=4;
nce.gems = readNormalNr(bufor,i); i+=4;
nce.gold = readNormalNr(bufor,i); i+=4;
nce.players = bufor[i]; ++i; nce.players = bufor[i]; ++i;
if(version > AB) if(version > AB)
{ {
@ -783,6 +772,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
} }
else else
nce.forHuman = true; nce.forHuman = true;
nce.forComputer = bufor[i]; ++i; nce.forComputer = bufor[i]; ++i;
nce.firstShow = readNormalNr(bufor,i, 2); i+=2; nce.firstShow = readNormalNr(bufor,i, 2); i+=2;
nce.forEvery = bufor[i]; ++i; nce.forEvery = bufor[i]; ++i;

24
map.h
View File

@ -303,13 +303,13 @@ struct DLL_EXPORT Mapa
{ {
Eformat version; // version of map Eformat Eformat version; // version of map Eformat
ui32 checksum; ui32 checksum;
int twoLevel; // if map has underground level ui32 twoLevel; // if map has underground level
int difficulty; // 0 easy - 4 impossible ui8 difficulty; // 0 easy - 4 impossible
int levelLimit; ui8 levelLimit;
bool areAnyPLayers; // if there are any playable players on map ui8 areAnyPLayers; // if there are any playable players on map
std::string name; //name of map std::string name; //name of map
std::string description; //and description std::string description; //and description
int height, width; ui32 height, width;
TerrainTile*** terrain; TerrainTile*** terrain;
std::vector<Rumor> rumors; std::vector<Rumor> rumors;
std::vector<DisposedHero> disposedHeroes; std::vector<DisposedHero> disposedHeroes;
@ -317,15 +317,15 @@ struct DLL_EXPORT Mapa
std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom) std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom)
std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by scripts std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by scripts
PlayerInfo players[8]; // info about players PlayerInfo players[8]; // info about players
std::vector<int> teams; // teams[i] = team of player no i std::vector<ui8> teams; // teams[i] = team of player no i
LossCondition lossCondition; LossCondition lossCondition;
EvictoryConditions victoryCondition; //victory conditions EvictoryConditions victoryCondition; //victory conditions
CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
int howManyTeams; ui8 howManyTeams;
std::vector<bool> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed std::vector<ui8> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
std::vector<bool> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed std::vector<ui8> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
std::vector<bool> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed std::vector<ui8> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
std::vector<bool> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed std::vector<ui8> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed
std::vector<CMapEvent> events; std::vector<CMapEvent> events;
int3 grailPos; int3 grailPos;
@ -361,7 +361,7 @@ struct DLL_EXPORT Mapa
{ {
h & version & name & description & width & height & twoLevel & difficulty & levelLimit & rumors & defy & defs h & version & name & description & width & height & twoLevel & difficulty & levelLimit & rumors & defy & defs
& players & teams & lossCondition & victoryCondition & howManyTeams & allowedSpell & allowedAbilities & players & teams & lossCondition & victoryCondition & howManyTeams & allowedSpell & allowedAbilities
& allowedArtifact &allowedHeroes & events; & allowedArtifact &allowedHeroes & events & grailPos;
//TODO: viccondetails //TODO: viccondetails
if(h.saving) if(h.saving)
{ {

View File

@ -57,7 +57,7 @@ double distance(int3 a, int3 b)
} }
int getSchoolLevel(const CGHeroInstance *h, const CSpell *s) int getSchoolLevel(const CGHeroInstance *h, const CSpell *s)
{ {
int ret = 0; ui8 ret = 0;
if(s->fire) if(s->fire)
ret = std::max(ret,h->getSecSkillLevel(14)); ret = std::max(ret,h->getSecSkillLevel(14));
if(s->air) if(s->air)
@ -1213,7 +1213,7 @@ upgend:
} }
CSpell *s = &VLC->spellh->spells[ba.additionalInfo]; CSpell *s = &VLC->spellh->spells[ba.additionalInfo];
int skill = 0; //skill level ui8 skill = 0; //skill level
if(s->fire) if(s->fire)
skill = std::max(skill,h->getSecSkillLevel(14)); skill = std::max(skill,h->getSecSkillLevel(14));