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 "CLua.h"
#include "hch\CCastleHandler.h"
#include "hch/CHeroHandler.h"
#include "hch\CHeroHandler.h"
#include <iomanip>
#include <sstream>
extern SDL_Surface * ekran;
class OCM_HLP
@ -26,7 +28,8 @@ public:
void CMapHandler::init()
{
///////////////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]);
@ -41,6 +44,17 @@ void CMapHandler::init()
}
}
CGI->objh->objInstances[no]->defInfo->name = nname;
if(CGI->objh->objInstances[no]->ID==70) //random hero - init here
{
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;
@ -70,6 +84,7 @@ void CMapHandler::init()
}
}
}
}
///////////////objects randomized///////////////////////////////////
@ -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();
}
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
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 removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
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 * terrBitmap(int x, int y);