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

code cleanups, etc.

This commit is contained in:
mateuszb 2008-02-03 15:24:35 +00:00
parent 84b10c0cd9
commit 21ec0b77d4
19 changed files with 16 additions and 291 deletions

View File

@ -7,7 +7,6 @@
#include <map>
class CDefHandler;
class CCallback;
class CTownInstance;
class CPath;
class CAdvMapInt;
class CGHeroInstance;

View File

@ -116,7 +116,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
{ //performing move
hero->movement-=CGI->mh->getCost(stpos, endpos, hero);
std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CHeroInstance::convertPosition(curd.dst,false));
std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false));
bool blockvis = false;
for (int pit = 0; pit<vis.size();pit++)
if (vis[pit]->blockVisit)
@ -128,7 +128,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
hero->pos = curd.dst;
//inform leaved objects
std::vector< CGObjectInstance * > leave = CGI->mh->getVisitableObjs(CHeroInstance::convertPosition(curd.src,false));
std::vector< CGObjectInstance * > leave = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.src,false));
for (int iii=0; iii<leave.size(); iii++) //if object is visitable we call onHeroVisit
{
//TODO: allow to handle this in LUA

View File

@ -4,8 +4,6 @@
#include "mapHandler.h"
#include "tchar.h"
class CGameState;
class CHeroInstance;
class CTownInstance;
class CPath;
class CGObjectInstance;
class SComponent;

View File

@ -3,8 +3,6 @@
#include "mapHandler.h"
#include <set>
class CScriptCallback;
class CHeroInstance;
class CTownInstance;
class CCallback;
class CLuaCallback;
class CCPPObjectScript;

View File

@ -123,7 +123,7 @@ public:
virtual void show(SDL_Surface * to = NULL); //shows hero window
void redrawCurBack(); //redraws curBAck from scratch
void quit(); //stops displaying hero window
void dismissCurrent(); //dissmissed currently displayed hero (curHero) //TODO: make it working
void dismissCurrent(); //dissmissed currently displayed hero (curHero)
void questlog(); //show quest log in hero window
void gar1(); //garrison / formation handling
void gar2(); //garrison / formation handling

View File

@ -346,7 +346,6 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->bitmaph->init(std::string("Data\\H3bitmap.lod"));
THC std::cout<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
cgi->curh->initCursor();
cgi->curh->showGraphicCursor();

View File

@ -3,7 +3,6 @@
#include "global.h"
#include <queue>
#include <vector>
class CHeroInstance;
class CGHeroInstance;
struct CPathNode
{

View File

@ -5,7 +5,6 @@
#include "SDL_framerate.h"
class CDefEssential;
class CHeroInstance;
class CDefHandler;
struct HeroMoveDetails;
class CDefEssential;

BIN
h3m.txt

Binary file not shown.

View File

@ -495,7 +495,7 @@ void CAmbarCendamo::deh3m()
else if(map.version!=AB || map.rumors.size()==0) //omit a lot of rubbish in a strage way
{
int lastFFpos=i;
while(i-lastFFpos<200) //i far in terrain bytes
while(i-lastFFpos<350) //i far in terrain bytes
{
++i;
if(bufor[i]==0xff)
@ -506,7 +506,7 @@ void CAmbarCendamo::deh3m()
i=lastFFpos;
while(bufor[i-1]!=0 || bufor[i]>8 || bufor[i+2]>4 || bufor[i+1]==0) //back to terrain bytes
while(bufor[i-1]!=0 || bufor[i]>8 || bufor[i+2]>4 || bufor[i+1]==0 || ( bufor[i+2]==0 && bufor[i+3]>0 ) || (bufor[i+4]==0 && bufor[i+5]>0)) //back to terrain bytes
{
i++;
}
@ -616,7 +616,6 @@ void CAmbarCendamo::deh3m()
nobj->ID = nobj->defInfo->id;
nobj->subID = nobj->defInfo->subid;
//nobj->defInfo = readNormalNr(i, 4); i+=4;
//nobj->defObjInfoNumber = -1;
//nobj->isHero = false;
//nobj->moveDir = 0;
//nobj->isStanding = true;
@ -2362,28 +2361,7 @@ borderguardend:
SDL_FreeSurface(alphaTransSurf);
//assigning defobjinfos
for(int ww=0; ww<CGI->objh->objInstances.size(); ++ww)
{
for(int h=0; h<CGI->dobjinfo->objs.size(); ++h)
{
if(CGI->dobjinfo->objs[h].defName==CGI->objh->objInstances[ww]->defInfo->name)
{
CGI->objh->objInstances[ww]->defObjInfoNumber = h;
break;
}
}
}
THC std::cout<<"\tHandling defs: "<<th.getDif()<<std::endl;
//for(int ww=0; ww<CGI->objh->objInstances.size(); ++ww)
//{
// if (CGI->objh->objInstances[ww]->defObjInfoNumber==-1)
// std::cout<<CGI->objh->objInstances[ww]->ID<<"\t" << CGI->objh->objInstances[ww]->subID<<"\t"<<CGI->objh->objInstances[ww]->defInfo->name<<std::endl;
//}
//assigned
//loading events
int numberOfEvents = readNormalNr(i); i+=4;

Binary file not shown.

View File

@ -448,54 +448,8 @@ void CHeroHandler::initHeroClasses()
initTerrainCosts();
}
unsigned int CHeroInstance::getTileCost(EterrainType & ttype, Eroad & rdtype, Eriver & rvtype)
{
unsigned int ret = type->heroClass->terrCosts[ttype];
switch(rdtype)
{
case Eroad::dirtRoad:
ret*=0.75;
break;
case Eroad::grazvelRoad:
ret*=0.667;
break;
case Eroad::cobblestoneRoad:
ret*=0.5;
break;
}
return ret;
}
unsigned int CHeroHandler::level(unsigned int experience)
{
//if (experience==0)
// return 0;
//else if (experience<14700) //level < 10
//{
// return (-500+20*sqrt((float)experience+1025))/(200);
//}
//else if (experience<24320) //10 - 12
//{
// if (experience>20600)
// return 12;
// else if (experience>17500)
// return 11;
// else return 10;
//}
//else //>12
//{
// int lvl=12;
// int xp = 24320; //xp needed for 13 lvl
// int td = 4464; //diff 14-13
// float mp = 1.2;
// while (experience>xp)
// {
// xp+=td;
// td*=mp;
// lvl++;
// }
// return lvl;
//}
int add=0;
while(experience>=expPerLevel[expPerLevel.size()-1])
{
@ -528,58 +482,6 @@ unsigned int CHeroHandler::reqExp(unsigned int level)
return -1;
}
unsigned int CHeroInstance::getLowestCreatureSpeed()
{
unsigned int sl = 100;
for(int h=0; h<army.slots.size(); ++h)
{
if(army.slots[h].first->speed<sl)
sl = army.slots[h].first->speed;
}
return sl;
}
int3 CHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
{
if (toh3m)
{
src.x+=1;
return src;
}
else
{
src.x-=1;
return src;
}
}
int3 CHeroInstance::getPosition(bool h3m) const
{
if (h3m)
return pos;
else return convertPosition(pos,false);
}
void CHeroInstance::setPosition(int3 Pos, bool h3m)
{
if (h3m)
pos = Pos;
else
pos = convertPosition(Pos,true);
}
bool CHeroInstance::canWalkOnSea() const
{
//TODO: write it - it should check if hero is flying, or something similiar
return false;
}
int CHeroInstance::getCurrentLuck() const
{
//TODO: write it
return 0;
}
int CHeroInstance::getCurrentMorale() const
{
//TODO: write it
return 0;
}
void CHeroHandler::initTerrainCosts()
{
std::ifstream inp;
@ -601,7 +503,3 @@ void CHeroHandler::initTerrainCosts()
inp.close();
}
int CHeroInstance::getSightDistance() const //TODO: finish
{
return 6;
}

View File

@ -10,7 +10,6 @@
#include "../CGameInterface.h"
class CHeroClass;
class CObjectInstance;
class CDefHandler;
class CGameInfo;
class CGHeroInstance;
@ -47,41 +46,6 @@ public:
CDefHandler * moveAnim; //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
};
class CHeroInstance
{
public:
int owner;
CHero * type;
CObjectInstance * ourObject;
int exp; //experience point
int level; //current level of hero
std::string name; //may be custom
std::string biography; //may be custom
int portrait; //may be custom
int3 pos; //position of object (hero pic is on the left)
CCreatureSet army; //army
int mana; // remaining spell points
std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
std::vector<std::pair<int,int> > secSkills; //first - ID of skill, second - level of skill (0 - basic, 1 - adv., 2 - expert)
int movement; //remaining movement points
bool inTownGarrison; // if hero is in town garrison
unsigned int getTileCost(EterrainType & ttype, Eroad & rdtype, Eriver & rvtype);
unsigned int getLowestCreatureSpeed();
unsigned int getAdditiveMoveBonus();
float getMultiplicativeMoveBonus();
static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
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
void setPosition(int3 Pos, bool h3m); //as above, but sets position
bool canWalkOnSea() const;
int getCurrentLuck() const;
int getCurrentMorale() const;
//TODO: artifacts, known spells, commander, blessings, curses, morale/luck special modifiers
};
class CHeroHandler
{
public:

View File

@ -73,49 +73,6 @@ void CObjectHandler::loadObjects()
}
bool CObjectInstance::operator <(const CObjectInstance &cmp) const
{
//if(CGI->ac->map.defy[this->defNumber].printPriority==1 && CGI->ac->map.defy[cmp.defNumber].printPriority==0)
// return true;
//if(CGI->ac->map.defy[cmp.defNumber].printPriority==1 && CGI->ac->map.defy[this->defNumber].printPriority==0)
// return false;
//if(this->pos.y<cmp.pos.y)
// return true;
//if(this->pos.y>cmp.pos.y)
// return false;
//if(CGI->ac->map.defy[this->defNumber].isOnDefList && !(CGI->ac->map.defy[cmp.defNumber].isOnDefList))
// return true;
//if(CGI->ac->map.defy[cmp.defNumber].isOnDefList && !(CGI->ac->map.defy[this->defNumber].isOnDefList))
// return false;
//if(!CGI->ac->map.defy[this->defNumber].isVisitable() && CGI->ac->map.defy[cmp.defNumber].isVisitable())
// return true;
//if(!CGI->ac->map.defy[cmp.defNumber].isVisitable() && CGI->ac->map.defy[this->defNumber].isVisitable())
// return false;
//if(this->pos.x<cmp.pos.x)
// return true;
return false;
}
int CObjectInstance::getWidth() const
{
return -1;//CGI->mh->reader->map.defy[defNumber].handler->ourImages[0].bitmap->w/32;
}
int CObjectInstance::getHeight() const
{
return -1;//CGI->mh->reader->map.defy[defNumber].handler->ourImages[0].bitmap->h/32;
}
bool CObjectInstance::visitableAt(int x, int y) const
{
//if(x<0 || y<0 || x>=getWidth() || y>=getHeight() || defObjInfoNumber<0)
// return false;
//if((CGI->dobjinfo->objs[defObjInfoNumber].visitMap[y+6-getHeight()] >> (7-(8-getWidth()+x) )) & 1)
// return true;
return false;
}
bool CGObjectInstance::isHero() const
{
return false;
@ -288,7 +245,6 @@ CGObjectInstance::CGObjectInstance()
//std::cout << "Tworze obiekt "<<this<<std::endl;
//state = new CLuaObjectScript();
//state = NULL;
defObjInfoNumber = -1;
tempOwner = 254;
blockVisit = false;
}
@ -314,7 +270,6 @@ CGObjectInstance::CGObjectInstance(const CGObjectInstance & right)
id = right.id;
defInfo = right.defInfo;
info = right.info;
defObjInfoNumber = right.defObjInfoNumber;
blockVisit = right.blockVisit;
//state = new CLuaObjectScript(right.state->);
//*state = *right.state;
@ -329,7 +284,6 @@ CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
id = right.id;
defInfo = right.defInfo;
info = right.info;
defObjInfoNumber = right.defObjInfoNumber;
blockVisit = right.blockVisit;
//state = new CLuaObjectScript();
//*state = *right.state;

View File

@ -298,25 +298,6 @@ public:
std::string name; //object's name
};
class CObjectInstance //instance of object
{
public:
int defNumber; //specifies number of def file with animation of this object
int defObjInfoNumber; //number of this object's def's additional informations in CDefObjInfo's vector
int id; //number of object in CObjectHandler's vector //TODO: absolutnie wywalic i zastapic czyms sensownym
int3 pos; // position
CSpecObjInfo * info; //pointer to something with additional information
bool isHero; //true if this is a hero
unsigned char moveDir; //direction of hero movement (0 - default; 1 - lt; 2 - t; 3 - tr; 4 - r; 5 - br; 6 - b; 7 - bl; 8 - l)
bool isStanding; //true if is standing, flase if is moving
unsigned char flagPrinted; //true if flag has been printed //number of print hits
unsigned char owner; //if 254, object cannot have owner; if it has, it equal to owner's ID (or 255, when no owner)
int getWidth() const; //returns width of object graphic in tiles
int getHeight() const; //returns height of object graphic in tiles
bool visitableAt(int x, int y) const; //returns true if ibject is visitable at location (x, y) form left top tile of image (x, y in tiles)
bool operator<(const CObjectInstance & cmp) const; //screen printing priority comparing
};
class CGDefInfo
{
public:
@ -365,7 +346,6 @@ public:
CGDefInfo * defInfo;
CCPPObjectScript * state;
CSpecObjInfo * info;
int defObjInfoNumber;
int tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
bool blockVisit;

View File

@ -229,16 +229,3 @@ int CTownHandler::getTypeByDefName(std::string name)
return 0;
}
CTownInstance::CTownInstance()
:pos(-1,-1,-1)
{
builded=-1;
destroyed=-1;
garrisonHero=NULL;
town=NULL;
}
int CTownInstance::getSightDistance() const //TODO: finish
{
return 10;
}

View File

@ -11,9 +11,7 @@
class CBuilding;
class CSpell;
class CHero;
class CTownInstance;
class CGTownInstance;
class CHeroInstance;
class CTown
{
public:
@ -57,28 +55,4 @@ public:
};
class CTownInstance
{
public:
int3 pos; //position
CTown * town;
std::string name; // name of town
CCreatureSet garrison;
int builded; //how many buildings has been built this turn
int destroyed; //how many buildings has been destroyed this turn
//TODO:
std::vector<CBuilding *> /*allBuildings,*/ possibleBuildings, builtBuildings;
std::vector<int> creatureIncome; //vector by level
std::vector<int> creaturesLeft; //that can be recruited
CHeroInstance * garrisonHero;
std::vector<CSpell *> possibleSpells, obligatorySpells, availableSpells;
int getSightDistance() const; //returns sight distance
CTownInstance();
};
#endif //CTOWNHANDLER_H

8
map.h
View File

@ -46,12 +46,12 @@ struct TimeEvent
struct TerrainTile
{
EterrainType tertype; // type of terrain
unsigned int terview; // look of terrain
unsigned char terview; // look of terrain
Eriver nuine; // type of Eriver (0 if there is no Eriver)
unsigned int rivDir; // direction of Eriver
unsigned char rivDir; // direction of Eriver
Eroad malle; // type of Eroad (0 if there is no Eriver)
unsigned int roadDir; // direction of Eroad
unsigned int siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej
unsigned char roadDir; // direction of Eroad
unsigned char siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej
};
struct DefInfo //information from def declaration
{

View File

@ -85,7 +85,6 @@ void CMapHandler::randomizeObjects()
}
if(f!=-1 && f!=CGI->dobjinfo->objs.size())
{
CGI->objh->objInstances[no]->defObjInfoNumber = f;
CGI->objh->objInstances[no]->ID = CGI->dobjinfo->objs[f].type;
CGI->objh->objInstances[no]->subID = CGI->dobjinfo->objs[f].subtype;
CGI->objh->objInstances[no]->defInfo->id = CGI->dobjinfo->objs[f].type;
@ -94,7 +93,6 @@ void CMapHandler::randomizeObjects()
}
else
{
CGI->objh->objInstances[no]->defObjInfoNumber = -1;
CGI->objh->objInstances[no]->defInfo->printPriority = 0;
}
}
@ -1508,21 +1506,21 @@ CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos)
nobj->ID = id;
nobj->subID = subid;
nobj->defInfo = new CGDefInfo;
nobj->defObjInfoNumber = -1;
int defObjInfoNumber = -1;
for(int f=0; f<CGI->dobjinfo->objs.size(); ++f)
{
if(CGI->dobjinfo->objs[f].type==id && CGI->dobjinfo->objs[f].subtype == subid)
{
nobj->defObjInfoNumber = f;
defObjInfoNumber = f;
break;
}
}
nobj->defInfo->name = CGI->dobjinfo->objs[nobj->defObjInfoNumber].defName;
nobj->defInfo->name = CGI->dobjinfo->objs[defObjInfoNumber].defName;
for(int g=0; g<6; ++g)
nobj->defInfo->blockMap[g] = CGI->dobjinfo->objs[nobj->defObjInfoNumber].blockMap[g];
nobj->defInfo->blockMap[g] = CGI->dobjinfo->objs[defObjInfoNumber].blockMap[g];
for(int g=0; g<6; ++g)
nobj->defInfo->visitMap[g] = CGI->dobjinfo->objs[nobj->defObjInfoNumber].visitMap[g];
nobj->defInfo->printPriority = CGI->dobjinfo->objs[nobj->defObjInfoNumber].priority;
nobj->defInfo->visitMap[g] = CGI->dobjinfo->objs[defObjInfoNumber].visitMap[g];
nobj->defInfo->printPriority = CGI->dobjinfo->objs[defObjInfoNumber].priority;
nobj->pos = pos;
//nobj->state = NULL;//new CLuaObjectScript();
nobj->tempOwner = 254;
@ -1573,7 +1571,7 @@ bool CMapHandler::printObject(CGObjectInstance *obj)
cr.y = fy*32;
std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(obj, std::make_pair(cr, std::vector<std::list<int3>>()));
///initializing places that will be coloured by blitting (flag colour / player colour positions)
if(CGI->dobjinfo->objs[toAdd.first->defObjInfoNumber].isVisitable())
if(toAdd.first->defInfo->isVisitable())
{
toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size());
for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no)