1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* hints for cregens

* moved battle loop to the activeStack
This commit is contained in:
Michał W. Urbańczyk 2008-02-29 22:14:53 +00:00
parent 8c0536be8e
commit 17d5d298ca
11 changed files with 72 additions and 14 deletions

View File

@ -9,7 +9,7 @@ class CGObjectInstance;
class SComponent;
class IChosen;
class CSelectableComponent;
class Action;
struct Action;
typedef struct lua_State lua_State;
class ICallback

View File

@ -92,7 +92,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
curB->round++;
SDL_Thread * eventh = SDL_CreateThread(battleEventThread, NULL);
//SDL_Thread * eventh = SDL_CreateThread(battleEventThread, NULL);
while(true) //do zwyciestwa jednej ze stron
{

View File

@ -647,13 +647,13 @@ void CHeroScript::onHeroVisit(CGObjectInstance *os, int heroID)
std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are handled by script
{
std::vector<int> ret(1);
ret.push_back(34); //town
ret.push_back(34); //hero
return ret;
}
void CMonsterS::newObject(CGObjectInstance *os)
{
os->blockVisit = true;
//os->blockVisit = true;
switch(CGI->creh->creatures[os->subID].level)
{
case 1:
@ -694,18 +694,37 @@ std::string CMonsterS::hoverText(CGObjectInstance *os)
{
int pom = CCreature::getQuantityID(((CCreatureObjInfo*)os->info)->number);
pom = 174 + 3*pom + 1;
return CGI->generaltexth->arraytxt[pom] + CGI->creh->creatures[os->subID].namePl;
return CGI->generaltexth->arraytxt[pom] + " " + CGI->creh->creatures[os->subID].namePl;
}
void CMonsterS::onHeroVisit(CGObjectInstance *os, int heroID)
{
CCreatureSet set;
//TODO: zrobic secik w sposob wyrafinowany
set.slots[0] = std::pair<CCreature*,int>(&CGI->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number);
//cb->startBattle(heroID,&set,os->pos);
cb->startBattle(heroID,&set,os->pos);
}
std::vector<int> CMonsterS::yourObjects() //returns IDs of objects which are handled by script
{
std::vector<int> ret(1);
ret.push_back(54); //town
ret.push_back(54); //monster
return ret;
}
void CCreatureGen::newObject(CGObjectInstance *os)
{
amount[os] = CGI->creh->creatures[CGI->objh->cregens[os->subID]].growth;
}
std::string CCreatureGen::hoverText(CGObjectInstance *os)
{
return CGI->objh->creGens[os->subID];
}
void CCreatureGen::onHeroVisit(CGObjectInstance *os, int heroID)
{
}
std::vector<int> CCreatureGen::yourObjects() //returns IDs of objects which are handled by script
{
std::vector<int> ret(1);
ret.push_back(17); //cregen1
return ret;
}

12
CLua.h
View File

@ -184,5 +184,17 @@ class CMonsterS : public CCPPObjectScript
void onHeroVisit(CGObjectInstance *os, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(CGameInfo * cgi);
};
class CCreatureGen : public CCPPObjectScript
{
std::map<CGObjectInstance*, int> amount; //amount of creatures in each dwelling
CCreatureGen(CScriptCallback * CB):CCPPObjectScript(CB){};
void newObject(CGObjectInstance *os);
std::string hoverText(CGObjectInstance *os);
void onHeroVisit(CGObjectInstance *os, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(CGameInfo * cgi);
};

View File

@ -251,6 +251,7 @@ void initGameState(CGameInfo * cgi)
handleCPPObjS(&scripts,new CTownScript(csc));
handleCPPObjS(&scripts,new CHeroScript(csc));
handleCPPObjS(&scripts,new CMonsterS(csc));
handleCPPObjS(&scripts,new CCreatureGen(csc));
//created map
/****************************LUA OBJECT SCRIPTS************************************************/

View File

@ -1873,6 +1873,20 @@ void CPlayerInterface::actionFinished(Action action)//occurs AFTER every action
void CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
{
while(true)
{
SDL_Event sEvent;
while (SDL_PollEvent(&sEvent)) //wait for event...
{
LOCPLINT->handleEvent(&sEvent);
}
for(int i=0;i<objsToBlit.size();i++)
objsToBlit[i]->show();
//SDL_Flip(ekran);
CSDL_Ext::update(ekran);
SDL_Delay(5); //give time for other apps
SDL_framerateDelay(mainFPSmng);
}
}
void CPlayerInterface::battleEnd(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner)

View File

@ -90,10 +90,12 @@
90 170
91 168
92 172
93 164
94 169
95 173
96 192
97 193
98 194
99 195
100 196
100 196
68 24

View File

@ -514,7 +514,7 @@ void CAmbarCendamo::deh3m()
THC std::cout<<"\tReading rumors: "<<th.getDif()<<std::endl;
switch(map.version)
{
case WoG: case SoD: case AB:
case WoG: case SoD:
{
for(int z=0;z<HEROES_QUANTITY;z++) //disposed heroes
{

View File

@ -795,12 +795,12 @@ std::string CLodHandler::getTextFile(std::string name)
std::string ret0;
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
Entry *e;
for (int i=0;i<totalFiles;i++)
{
e = entries.znajdz(name);
}
e = entries.znajdz(name);
if(!e)
{
std::cout << "Error: cannot load "<<name<<" from the .lod file!"<<std::endl;
return ret0;
}
if(e->offset<0)
{
char * outp = new char[e->realSize];

View File

@ -79,7 +79,16 @@ void CObjectHandler::loadObjects()
ifs >> dw >> cr;
cregens[dw]=cr;
}
ifs.close();
ifs.clear();
buf = CGameInfo::mainObj->bitmaph->getTextFile("ZCRGN1.TXT");
it=0;
while (it<buf.length()-1)
{
CGeneralTextHandler::loadToIt(temp,buf,it,3);
creGens.push_back(temp);
}
}
bool CGObjectInstance::isHero() const

View File

@ -419,6 +419,7 @@ public:
std::vector<int> cregens; //type 17. dwelling subid -> creature ID
void loadObjects();
std::vector<std::string> creGens; //names of creatures' generators
std::vector<std::string> advobtxt;
std::vector<std::string> xtrainfo;
std::vector<std::string> restypes;