Browse Source

Minor changes (serialization and related)

Michał W. Urbańczyk 17 years ago
parent
commit
f853074d20
8 changed files with 143 additions and 93 deletions
  1. 17 0
      CMT.cpp
  2. 1 1
      CPlayerInterface.cpp
  3. 1 1
      config/settings.txt
  4. 30 31
      hch/CObjectHandler.cpp
  5. 74 30
      hch/CObjectHandler.h
  6. 6 16
      map.cpp
  7. 12 12
      map.h
  8. 2 2
      server/CGameHandler.cpp

+ 17 - 0
CMT.cpp

@@ -214,6 +214,23 @@ int main(int argc, char** argv)
 				tlog0 << "Ending...\n";
 				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();
 			events.push(ev);
 			eventsM.unlock();

+ 1 - 1
CPlayerInterface.cpp

@@ -2579,7 +2579,7 @@ void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar
 			ser = i;
 	ser -= from;
 	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
 }
 void CHeroList::draw()

+ 1 - 1
config/settings.txt

@@ -86,7 +86,7 @@ GUISettings
 			Statusbar: x=8 y=723 graphic=ADROLLVR2.pcx;
 			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;
-			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;
 			ButtonSleepWake: x=903 y=294 graphic=IAM005L.DEF playerColoured=1;
 			ButtonMoveHero: x=903 y=327 graphic=IAM006L.DEF playerColoured=1;

+ 30 - 31
hch/CObjectHandler.cpp

@@ -154,7 +154,6 @@ CGObjectInstance::CGObjectInstance(): animPhaseShift(rand()%0xff)
 	//state = new CLuaObjectScript();
 	ID = subID = id = -1;
 	defInfo = NULL;
-	state = NULL;
 	info = NULL;
 	tempOwner = 254;
 	blockVisit = false;
@@ -166,34 +165,34 @@ CGObjectInstance::~CGObjectInstance()
 	//	delete state;
 	//state=NULL;
 }
-CGObjectInstance::CGObjectInstance(const CGObjectInstance & right)
-{
-	pos = right.pos;
-	ID = right.ID;
-	subID = right.subID;
-	id	= right.id;
-	defInfo = right.defInfo;
-	info = right.info;
-	blockVisit = right.blockVisit;
-	//state = new CLuaObjectScript(right.state->);
-	//*state = *right.state;
-	//state = right.state;
-	tempOwner = right.tempOwner;
-}
-CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
-{
-	pos = right.pos;
-	ID = right.ID;
-	subID = right.subID;
-	id	= right.id;
-	defInfo = right.defInfo;
-	info = right.info;
-	blockVisit = right.blockVisit;
-	//state = new CLuaObjectScript();
-	//*state = *right.state;
-	tempOwner = right.tempOwner;
-	return *this;
-}
+//CGObjectInstance::CGObjectInstance(const CGObjectInstance & right)
+//{
+//	pos = right.pos;
+//	ID = right.ID;
+//	subID = right.subID;
+//	id	= right.id;
+//	defInfo = right.defInfo;
+//	info = right.info;
+//	blockVisit = right.blockVisit;
+//	//state = new CLuaObjectScript(right.state->);
+//	//*state = *right.state;
+//	//state = right.state;
+//	tempOwner = right.tempOwner;
+//}
+//CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
+//{
+//	pos = right.pos;
+//	ID = right.ID;
+//	subID = right.subID;
+//	id	= right.id;
+//	defInfo = right.defInfo;
+//	info = right.info;
+//	blockVisit = right.blockVisit;
+//	//state = new CLuaObjectScript();
+//	//*state = *right.state;
+//	tempOwner = right.tempOwner;
+//	return *this;
+//}
 
 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
 }
 
-int CGHeroInstance::manaLimit() const
+si32 CGHeroInstance::manaLimit() const
 {
 	double modifier = 1.0;
 	switch(getSecSkillLevel(24)) //intelligence level
@@ -418,7 +417,7 @@ int CGHeroInstance::getPrimSkillLevel(int id) const
 {
 	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)
 		if(secSkills[i].first==ID)

+ 74 - 30
hch/CObjectHandler.h

@@ -28,20 +28,24 @@ class DLL_EXPORT CCastleEvent
 {
 public:
 	std::string name, message;
-	int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources
-	unsigned char players; //players for whom this event can be applied
-	bool forHuman, forComputer;
-	int firstShow; //postpone of first encounter time in days
-	int forEvery; //every n days this event will occure
-
-	unsigned char bytes[6]; //build specific buildings (raw format, similar to town's)
-
-	int gen[7]; //additional creatures in i-th level dwelling
+	std::vector<si32> resources;  //gain / loss of resources
+	ui8 players; //players for whom this event can be applied
+	ui8 forHuman, forComputer;
+	ui32 firstShow; //postpone of first encounter time in days
+	ui32 forEvery; //every n days this event will occure
+	ui8 bytes[6]; //build specific buildings (raw format, similar to town's)
+	si32 gen[7]; //additional creatures in i-th level dwelling
 
 	bool operator<(const CCastleEvent &drugie) const
 	{
 		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
@@ -57,6 +61,12 @@ public:
 	std::vector<ui32> m7resources;
 
 	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
@@ -79,14 +89,13 @@ protected:
 public:
 	mutable std::string hoverName;
 	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		
 	CGDefInfo * defInfo;
-	CCPPObjectScript * state;
 	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
 
 	int getOwner() const;
@@ -98,13 +107,20 @@ public:
 	bool operator<(const CGObjectInstance & cmp) const;  //screen printing priority comparing
 	CGObjectInstance();
 	virtual ~CGObjectInstance();
-	CGObjectInstance(const CGObjectInstance & right);
-	CGObjectInstance& operator=(const CGObjectInstance & right);
+	//CGObjectInstance(const CGObjectInstance & right);
+	//CGObjectInstance& operator=(const CGObjectInstance & right);
 	virtual const std::string & getHoverText() const;
 	//////////////////////////////////////////////////////////////////////////
 	void initObj();
 
 	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
@@ -112,6 +128,11 @@ class  DLL_EXPORT CArmedInstance: public CGObjectInstance
 public:
 	CCreatureSet army; //army
 	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
@@ -128,23 +149,23 @@ public:
 
 	CHero * type;
 	ui32 exp; //experience point
-	int level; //current level of hero
+	si32 level; //current level of hero
 	std::string name; //may be custom
 	std::string biography; //if custom
-	int portrait; //may be custom
-	int mana; // remaining spell points
-	std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
+	si32 portrait; //may be custom
+	si32 mana; // remaining spell points
+	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
-	int movement; //remaining movement points
-	int identifier; //from the map file
-	bool sex;
+	si32 movement; //remaining movement points
+	si32 identifier; //from the map file
+	ui8 sex;
 	struct DLL_EXPORT Patrol
 	{
 		Patrol(){patrolling=false;patrolRadious=-1;};
 		bool patrolling;
 		int patrolRadious;
 	} 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
 	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
@@ -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;
 	bool needsLastStack()const;
 	unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const;
@@ -160,12 +191,12 @@ public:
 	float getMultiplicativeMoveBonus() const;
 	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 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;
 	int getCurrentLuck() const;
 	int getCurrentMorale() 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;
 	ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
 	void setArtAtPos(ui16 pos, int art);
@@ -190,13 +221,13 @@ class DLL_EXPORT CGTownInstance : public CArmedInstance
 public:
 	CTown * town;
 	std::string name; // name of town
-	int builded; //how many buildings has been built this turn
-	int destroyed; //how many buildings has been destroyed this turn
+	si32 builded; //how many buildings has been built this turn
+	si32 destroyed; //how many buildings has been destroyed this turn
 	const CGHeroInstance * garrisonHero, *visitingHero;
-	int identifier; //special identifier from h3m (only > RoE maps)
-	int alignment;
+	ui32 identifier; //special identifier from h3m (only > RoE maps)
+	si32 alignment;
 	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
 
 	struct StrInfo
@@ -210,6 +241,19 @@ public:
 	} strInfo;
 	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;
 	int getSightDistance() const; //returns sight distance

+ 6 - 16
map.cpp

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

+ 12 - 12
map.h

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

+ 2 - 2
server/CGameHandler.cpp

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