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

* [feature] giving starting hero

* [feature] VCMI will try to use files from /Data folder instead of those from h3bitmap.lod
* [feature] picked artifacts are added to hero's backpack
This commit is contained in:
Michał W. Urbańczyk 2008-02-07 18:45:22 +00:00
parent 96734fafa1
commit a89b4e2c59
12 changed files with 195 additions and 107 deletions

@ -281,6 +281,20 @@ void CTerrainRect::clickLeft(tribool down)
{ //move
CPath sended(*currentPath); //temporary path - engine will operate on it
mres = LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
if(!mres)
{
delete currentPath;
currentPath = NULL;
int i=0;
for(;i<LOCPLINT->adventureInt->heroList.items.size();i++)
{
if(LOCPLINT->adventureInt->heroList.items[i].first->subID == ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID)
{
LOCPLINT->adventureInt->heroList.items[i].second = NULL;
break;
}
}
}
}
else
{

@ -609,6 +609,32 @@ void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID)
else
return;
}
void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack
{
CGHeroInstance* h = gs->getHero(hid,0);
if(position<0)
{
for(int i=0;i<h->artifacts.size();i++)
{
if(!h->artifacts[i])
{
h->artifacts[i] = &CGI->arth->artifacts[artid];
return;
}
}
h->artifacts.push_back(&CGI->arth->artifacts[artid]);
return;
}
else
{
if(h->artifWorn[position]) //slot is occupied
{
giveHeroArtifact(h->artifWorn[position]->id,hid,-1);
}
h->artifWorn[position] = &CGI->arth->artifacts[artid];
}
}
void CLuaCallback::registerFuncs(lua_State * L)
{
lua_newtable(L);

@ -111,7 +111,7 @@ public:
void showCompInfo(int player, SComponent * comp);
void heroVisitCastle(CGObjectInstance * ob, int heroID);
void stopHeroVisitCastle(CGObjectInstance * ob, int heroID);
void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack
//friends
friend void initGameState(CGameInfo * cgi);

@ -478,6 +478,11 @@ void CPickable::onHeroVisit(CGObjectInstance *os, int heroID)
{
switch(os->ID)
{
case 5:
{
cb->giveHeroArtifact(os->subID,heroID,-1); //TODO: na pozycje
break;
}
case 79:
{
//TODO: handle guards (when battles are finished)

13
CMT.cpp

@ -120,7 +120,7 @@ void initGameState(CGameInfo * cgi)
//*vhi=*(cgi->heroh->heroInstances[i]);
CGHeroInstance * vhi = (cgi->heroh->heroInstances[i]);
vhi->subID = vhi->type->ID;
if (!vhi->level)
if (vhi->level<1)
{
vhi->exp=40+rand()%50;
vhi->level = 1;
@ -760,6 +760,17 @@ int _tmain(int argc, _TCHAR* argv[])
initTable[ss] = mapstr[ss];
}
std::cout<<"done."<<std::endl;
for(int pru=0;pru<cgi->scenarioOps.playerInfos.size();pru++)
{
if(cgi->scenarioOps.playerInfos[pru].castle<0)
cgi->scenarioOps.playerInfos[pru].castle = rand()%F_NUMBER;
if(cgi->scenarioOps.playerInfos[pru].hero<0)
cgi->scenarioOps.playerInfos[pru].hero= cgi->scenarioOps.playerInfos[pru].castle*HEROES_PER_TYPE*2+(rand()%(HEROES_PER_TYPE*2));//cgi->scenarioOps.playerInfos[pru].hero = cgi->
}
#define CHOOSE
#ifdef CHOOSE
CAmbarCendamo * ac = new CAmbarCendamo(initTable); //4gryf

@ -261,12 +261,12 @@ SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot)
for(int j=0; j<ret->h; ++j)
{
{
Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel-2;
int k=2;
Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel;
//int k=2;
#if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], k);
CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2]);
#else
CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], k);
CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0]);
#endif
}
}
@ -452,6 +452,9 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
case 100:
shadow.unused = 100+64;
break;
case 125:
shadow.unused = 125+64;
break;
case 128:
shadow.unused = 128+64;
break;

@ -259,6 +259,11 @@ CGObjectInstance::~CGObjectInstance()
// delete state;
//state=NULL;
}
CGHeroInstance::CGHeroInstance()
{
level = exp = -1;
moveDir=4;
}
CGHeroInstance::~CGHeroInstance()
{

@ -367,6 +367,7 @@ public:
bool canWalkOnSea() const;
int getCurrentLuck() const;
int getCurrentMorale() const;
CGHeroInstance();
virtual ~CGHeroInstance();
};

@ -19,11 +19,12 @@ void CTownHandler::loadNames()
ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT"));
names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT"));
int si=0;
char bufname[50];
while (!ins.eof())
{
CTown town;
ins >> town.name;
char bufname[50];
ins.getline(bufname,50);
town.name = std::string(bufname);
for (int i=0; i<NAMES_PER_TOWN; i++)
{
names.getline(bufname,50);

28
map.h

@ -63,11 +63,6 @@ struct DefInfo //information from def declaration
bool isOnDefList;
bool isVisitable();
};
struct Location
{
int x, y;
bool z; // underground
};
struct SheroName //name of starting hero
{
int heroID;
@ -86,19 +81,16 @@ struct PlayerInfo
std::vector<SheroName> heroesNames;
bool hasMainTown;
bool generateHeroAtMainTown;
Location posOfMainTown;
int3 posOfMainTown;
int team;
bool generateHero;
};
struct LossCondition
{
ElossCon typeOfLossCon;
union
{
Location castlePos;
Location heroPos;
int timeLimit; // in days
};
int3 castlePos;
int3 heroPos;
int timeLimit; // in days
};
struct CspecificVictoryConidtions
{
@ -121,26 +113,26 @@ struct VicCon2 : public CspecificVictoryConidtions // accumulate resources
};
struct VicCon3 : public CspecificVictoryConidtions // upgrade specific town
{
Location posOfCity;
int3 posOfCity;
int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
};
struct VicCon4 : public CspecificVictoryConidtions // build grail structure
{
bool anyLocation;
Location whereBuildGrail;
int3 whereBuildGrail;
};
struct VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
{
Location locationOfHero;
int3 locationOfHero;
};
struct VicCon6 : public CspecificVictoryConidtions // capture a specific town
{
Location locationOfTown;
int3 locationOfTown;
};
struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
{
Location locationOfMonster;
int3 locationOfMonster;
};
/*struct VicCon8 : public CspecificVictoryConidtions // flag all creature dwellings
{
@ -151,7 +143,7 @@ struct VicCon9 : public CspecificVictoryConidtions // flag all mines
struct VicCona : public CspecificVictoryConidtions //transport specific artifact
{
int artifactID;
Location destinationPlace;
int3 destinationPlace;
};
struct Rumor
{

@ -197,7 +197,7 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur)
t->defInfo->handler = CGI->spriteh->giveDef(t->defInfo->name);
alphaTransformDef(t->defInfo);
}
CGI->townh->townInstances.push_back(t);
//CGI->townh->townInstances.push_back(t);
return;
}
//we have to replace normal random object
@ -218,6 +218,8 @@ void CMapHandler::randomizeObjects()
for(int no=0; no<CGI->objh->objInstances.size(); ++no)
{
randomizeObject(CGI->objh->objInstances[no]);
if(CGI->objh->objInstances[no]->ID==26)
CGI->objh->objInstances[no]->defInfo->handler=NULL;
}
}
void CMapHandler::prepareFOWDefs()
@ -611,54 +613,66 @@ void CMapHandler::initObjectRects()
continue;
}
CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler;
for(int fx=0; fx<curd->ourImages[0].bitmap->w>>5; ++fx) //curd->ourImages[0].bitmap->w/32
if(curd)
{
for(int fy=0; fy<curd->ourImages[0].bitmap->h>>5; ++fy) //curd->ourImages[0].bitmap->h/32
for(int fx=0; fx<curd->ourImages[0].bitmap->w>>5; ++fx) //curd->ourImages[0].bitmap->w/32
{
SDL_Rect cr;
cr.w = 32;
cr.h = 32;
cr.x = fx<<5; //fx*32
cr.y = fy<<5; //fy*32
std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector<std::list<int3>>()));
///initializing places that will be coloured by blitting (flag colour / player colour positions)
if(toAdd.first->defInfo->isVisitable())
for(int fy=0; fy<curd->ourImages[0].bitmap->h>>5; ++fy) //curd->ourImages[0].bitmap->h/32
{
toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size());
for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no)
SDL_Rect cr;
cr.w = 32;
cr.h = 32;
cr.x = fx<<5; //fx*32
cr.y = fy<<5; //fy*32
std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector<std::list<int3>>()));
///initializing places that will be coloured by blitting (flag colour / player colour positions)
if(toAdd.first->defInfo->isVisitable())
{
bool breakNow = true;
for(int dx=0; dx<32; ++dx)
SDL_Rect cr;
cr.w = 32;
cr.h = 32;
cr.x = fx*32;
cr.y = fy*32;
std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3> > > > toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector<std::list<int3>>()));
///initializing places that will be coloured by blitting (flag colour / player colour positions)
if(toAdd.first->defInfo->isVisitable() && toAdd.first->defInfo->handler->ourImages[0].bitmap->format->BitsPerPixel!=8)
{
for(int dy=0; dy<32; ++dy)
toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size());
for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no)
{
SDL_Surface * curs = toAdd.first->defInfo->handler->ourImages[no].bitmap;
Uint32* point = (Uint32*)( (Uint8*)curs->pixels + curs->pitch * (fy*32+dy) + curs->format->BytesPerPixel*(fx*32+dx));
Uint8 r, g, b, a;
SDL_GetRGBA(*point, curs->format, &r, &g, &b, &a);
if(r==255 && g==255 && b==0)
bool breakNow = true;
for(int dx=0; dx<32; ++dx)
{
toAdd.second.second[no].push_back(int3((fx*32+dx), (fy*32+dy), 0));
breakNow = false;
for(int dy=0; dy<32; ++dy)
{
SDL_Surface * curs = toAdd.first->defInfo->handler->ourImages[no].bitmap;
Uint32* point = (Uint32*)( (Uint8*)curs->pixels + curs->pitch * (fy*32+dy) + curs->format->BytesPerPixel*(fx*32+dx));
Uint8 r, g, b, a;
SDL_GetRGBA(*point, curs->format, &r, &g, &b, &a);
if(r==255 && g==255 && b==0)
{
toAdd.second.second[no].push_back(int3((fx*32+dx), (fy*32+dy), 0));
breakNow = false;
}
}
}
if(breakNow)
break;
}
}
if(breakNow)
break;
}
}
if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
{
//TerrainTile2 & curt =
// ttiles
// [CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32]
//[CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32]
//[CGI->objh->objInstances[f]->pos.z];
ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd);
}
} // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
} //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
{
//TerrainTile2 & curt =
// ttiles
// [CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32]
//[CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32]
//[CGI->objh->objInstances[f]->pos.z];
ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd);
}
} // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
} //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
}//if curd
} // for(int f=0; f<CGI->objh->objInstances.size(); ++f)
for(int ix=0; ix<ttiles.size()-Woff; ++ix)
{
@ -717,6 +731,7 @@ void CMapHandler::init()
timeHandler th;
th.getDif();
randomizeObjects();//randomizing objects on map
std::cout<<"\tRandomizing objects: "<<th.getDif()<<std::endl;
@ -733,9 +748,28 @@ void CMapHandler::init()
borderAndTerrainBitmapInit();
std::cout<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
for(int i=0;i<PLAYER_LIMIT;i++)
{
if(reader->map.players[i].generateHeroAtMainTown && reader->map.players[i].hasMainTown)
{
int3 hpos = reader->map.players[i].posOfMainTown;
hpos.x+=1; hpos.y+=1;
int j;
for(j=0;j<CGI->scenarioOps.playerInfos.size();j++)
if(CGI->scenarioOps.playerInfos[j].color==i)
break;
if(j==CGI->scenarioOps.playerInfos.size())
continue;
CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,CGI->scenarioOps.playerInfos[j].hero,hpos,i);
nnn->defInfo->handler = CGI->heroh->flags1[0];
CGI->heroh->heroInstances.push_back(nnn);
CGI->objh->objInstances.push_back(nnn);
}
}
initObjectRects();
std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl;
calculateBlockedPos();
std::cout<<"\tCalculating blockmap: "<<th.getDif()<<std::endl;
}
@ -812,9 +846,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
int imgVal = 8;
SDL_Surface * tb;
if(((CHeroObjInfo*)themp->info)->myInstance->type==NULL)
if(themp->type==NULL)
continue;
std::vector<Cimage> & iv = ((CHeroObjInfo*)themp->info)->myInstance->type->heroClass->moveAnim->ourImages;
std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
switch(themp->moveDir)
{
case 1:
@ -960,9 +994,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
int imgVal = 8;
SDL_Surface * tb;
if(((CHeroObjInfo*)themp->info)->myInstance->type==NULL)
if(themp->type==NULL)
continue;
std::vector<Cimage> & iv = ((CHeroObjInfo*)themp->info)->myInstance->type->heroClass->moveAnim->ourImages;
std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
switch(themp->moveDir)
{
case 1:
@ -1589,65 +1623,61 @@ std::vector < CGObjectInstance * > CMapHandler::getVisitableObjs(int3 pos)
return ret;
}
CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos)
CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos, int owner)
{
CGObjectInstance * nobj;
switch(id)
{
case 43: //hero
nobj = new CGHeroInstance;
break;
case 34: //hero
{
CGHeroInstance * nobj;
nobj = new CGHeroInstance();
nobj->pos = pos;
nobj->tempOwner = owner;
nobj->defInfo = new CGDefInfo();
nobj->defInfo->id = 34;
nobj->defInfo->subid = subid;
nobj->type = CGI->heroh->heroes[subid];
for(int i=0;i<6;i++)
{
nobj->defInfo->blockMap[i]=1;
nobj->defInfo->visitMap[i]=0;
}
nobj->ID = id;
nobj->subID = subid;
nobj->defInfo->handler=NULL;
nobj->defInfo->blockMap[5] = 0x7f;
nobj->defInfo->visitMap[5] = 0x80;
nobj->artifWorn.resize(20);
nobj->artifacts.resize(20);
nobj->artifWorn[16] = &CGI->arth->artifacts[3];
return nobj;
}
case 98: //town
nobj = new CGTownInstance;
break;
default: //rest of objects
nobj = new CGObjectInstance;
nobj->defInfo = CGI->dobjinfo->gobjs[id][subid];
break;
}
nobj->ID = id;
nobj->subID = subid;
nobj->defInfo = CGI->dobjinfo->gobjs[id][subid];
if(!nobj->defInfo)
std::cout <<"No def declaration for " <<id <<" "<<subid<<std::endl;
/*new CGDefInfo;
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)
{
defObjInfoNumber = f;
break;
}
}
nobj->defInfo->name = CGI->dobjinfo->objs[defObjInfoNumber].defName;
for(int g=0; g<6; ++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->pos = pos;
//nobj->state = NULL;//new CLuaObjectScript();
nobj->tempOwner = 254;
nobj->tempOwner = owner;
nobj->info = NULL;
nobj->defInfo->id = id;
nobj->defInfo->subid = subid;
//assigning defhandler
std::string ourName = getDefName(id, subid);
std::transform(ourName.begin(), ourName.end(), ourName.begin(), (int(*)(int))toupper);
nobj->defInfo->name = ourName;
if(loadedDefs[ourName] == NULL)
{
nobj->defInfo->handler = CGI->spriteh->giveDef(ourName);
loadedDefs[ourName] = nobj->defInfo->handler;
}
else
{
nobj->defInfo->handler = loadedDefs[ourName];
}
if(nobj->ID==34 || nobj->ID==98)
return nobj;
nobj->defInfo = CGI->dobjinfo->gobjs[id][subid];
if(!nobj->defInfo->handler)
nobj->defInfo->handler = CGI->spriteh->giveDef(nobj->defInfo->name);
return nobj;
}

@ -84,7 +84,7 @@ public:
int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
CGObjectInstance * createObject(int id, int subid, int3 pos); //creates a new object with a certain id and subid
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
bool hideObject(CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)