1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-07 00:58:39 +02:00

deleting objects, a bit of hero randomizing

This commit is contained in:
mateuszb
2007-11-24 18:54:34 +00:00
parent 845d99a908
commit b226540775
2 changed files with 68 additions and 35 deletions

View File

@ -11,7 +11,9 @@
#include "CGameState.h" #include "CGameState.h"
#include "CLua.h" #include "CLua.h"
#include "hch\CCastleHandler.h" #include "hch\CCastleHandler.h"
#include "hch/CHeroHandler.h" #include "hch\CHeroHandler.h"
#include <iomanip>
#include <sstream>
extern SDL_Surface * ekran; extern SDL_Surface * ekran;
class OCM_HLP class OCM_HLP
@ -26,47 +28,60 @@ public:
void CMapHandler::init() void CMapHandler::init()
{ {
///////////////randomizing objects on map/////////////////////////// ///////////////randomizing objects on map///////////////////////////
for(int gh=0; gh<2; ++gh) //some objects can be initialized not before initializing some other
for(int no=0; no<CGI->objh->objInstances.size(); ++no)
{ {
std::string nname = getRandomizedDefName(CGI->objh->objInstances[no]->defInfo, CGI->objh->objInstances[no]); for(int no=0; no<CGI->objh->objInstances.size(); ++no)
if(nname.size()>0) //change def
{ {
int f=-1; std::string nname = getRandomizedDefName(CGI->objh->objInstances[no]->defInfo, CGI->objh->objInstances[no]);
for(f=0; f<CGI->dobjinfo->objs.size(); ++f) if(nname.size()>0) //change def
{ {
if(CGI->dobjinfo->objs[f].defName==nname) int f=-1;
for(f=0; f<CGI->dobjinfo->objs.size(); ++f)
{ {
break; if(CGI->dobjinfo->objs[f].defName==nname)
{
break;
}
} }
} CGI->objh->objInstances[no]->defInfo->name = nname;
CGI->objh->objInstances[no]->defInfo->name = nname; if(CGI->objh->objInstances[no]->ID==70) //random hero - init here
if(loadedDefs.find(nname)!=loadedDefs.end())
{
CGI->objh->objInstances[no]->defInfo->handler = loadedDefs.find(nname)->second;
}
else
{
CGI->objh->objInstances[no]->defInfo->handler = CGI->spriteh->giveDef(nname);
for(int dd=0; dd<CGI->objh->objInstances[no]->defInfo->handler->ourImages.size(); ++dd)
{ {
CSDL_Ext::fullAlphaTransform(CGI->objh->objInstances[no]->defInfo->handler->ourImages[dd].bitmap); CHeroObjInfo* curc = ((CHeroObjInfo*)CGI->objh->objInstances[no]->info);
curc->type = CGI->heroh->heroes[rand()%CGI->heroh->heroes.size()];
curc->sex = rand()%2; //TODO: what to do with that?
curc->name = curc->type->name;
curc->attack = curc->type->heroClass->initialAttack;
curc->defence = curc->type->heroClass->initialDefence;
curc->knowledge = curc->type->heroClass->initialKnowledge;
curc->power = curc->type->heroClass->initialPower;
}
if(loadedDefs.find(nname)!=loadedDefs.end())
{
CGI->objh->objInstances[no]->defInfo->handler = loadedDefs.find(nname)->second;
}
else
{
CGI->objh->objInstances[no]->defInfo->handler = CGI->spriteh->giveDef(nname);
for(int dd=0; dd<CGI->objh->objInstances[no]->defInfo->handler->ourImages.size(); ++dd)
{
CSDL_Ext::fullAlphaTransform(CGI->objh->objInstances[no]->defInfo->handler->ourImages[dd].bitmap);
}
loadedDefs.insert(std::pair<std::string, CDefHandler*>(nname, CGI->objh->objInstances[no]->defInfo->handler));
}
CGI->objh->objInstances[no]->defObjInfoNumber = f;
if(f!=-1)
{
CGI->objh->objInstances[no]->defInfo->isOnDefList = true;
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;
CGI->objh->objInstances[no]->defInfo->subid = CGI->dobjinfo->objs[f].subtype;
CGI->objh->objInstances[no]->defInfo->printPriority = CGI->dobjinfo->objs[f].priority;
}
else
{
CGI->objh->objInstances[no]->defInfo->isOnDefList = false;
} }
loadedDefs.insert(std::pair<std::string, CDefHandler*>(nname, CGI->objh->objInstances[no]->defInfo->handler));
}
CGI->objh->objInstances[no]->defObjInfoNumber = f;
if(f!=-1)
{
CGI->objh->objInstances[no]->defInfo->isOnDefList = true;
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;
CGI->objh->objInstances[no]->defInfo->subid = CGI->dobjinfo->objs[f].subtype;
CGI->objh->objInstances[no]->defInfo->printPriority = CGI->dobjinfo->objs[f].priority;
}
else
{
CGI->objh->objInstances[no]->defInfo->isOnDefList = false;
} }
} }
} }
@ -1766,6 +1781,23 @@ std::string CMapHandler::getRandomizedDefName(CGDefInfo *di, CGObjectInstance *
} }
} }
} }
else if(di->id==70) //random hero
{
std::stringstream nm;
nm<<"AH";
nm<<std::setw(2);
nm<<std::setfill('0');
nm<<rand()%18; //HARDCODED VALUE! TODO: REMOVE IN FUTURE
nm<<"_.DEF";
return nm.str();
}
return std::string(); return std::string();
} }
bool CMapHandler::removeObject(CGObjectInstance *obj)
{
hideObject(obj);
CGI->objh->objInstances.erase(std::find(CGI->objh->objInstances.begin(), CGI->objh->objInstances.end(), obj));
return true;
}

View File

@ -86,6 +86,7 @@ public:
std::string getDefName(int id, int subid); //returns name of def for object with given 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 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) bool hideObject(CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
void init(); void init();
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap = CGI->mh->visibility); SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap = CGI->mh->visibility);
SDL_Surface * terrBitmap(int x, int y); SDL_Surface * terrBitmap(int x, int y);