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

battles are now enabled - but running any freezes the screen

Tow, do something with that
This commit is contained in:
mateuszb 2008-02-28 17:00:16 +00:00
parent fe2356ea0f
commit 8c0536be8e
2 changed files with 43 additions and 21 deletions

View File

@ -2,6 +2,9 @@
#include "CGameInterface.h"
#include "CPlayerInterface.h"
#include <algorithm>
#include "SDL_Thread.h"
#include "SDL_Extensions.h"
class CStack
{
public:
@ -13,6 +16,7 @@ public:
bool alive;
CStack(CCreature * C, int A, int O, int I):creature(C),amount(A),owner(O), alive(true), position(-1), ID(I){};
};
class CMP_stack
{
public:
@ -22,6 +26,20 @@ public:
}
} cmpst ;
int battleEventThread(void * pointer)
{
while(true)
{
SDL_Event sEvent;
while (SDL_PollEvent(&sEvent)) //wait for event...
{
LOCPLINT->handleEvent(&sEvent);
}
CSDL_Ext::update();
SDL_Delay(100);
}
return 0;
}
void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2)
{
@ -73,25 +91,29 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
}
curB->round++;
//while(true) //do zwyciestwa jednej ze stron
//{
// for(int i=0;i<stacks.size();i++)
// {
// curB->activeStack = i;
// if(stacks[i]->alive) //niech interfejs ruszy oddzialem
// {
// if(CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)]->human)
// {
// ((CPlayerInterface*)CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)])->activeStack(stacks[i]->ID);
// }
// else
// {
// //CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)]->activeStack(stacks[i]->ID);
// }
// }
// //sprawdzic czy po tej akcji ktoras strona nie wygrala bitwy
// }
//}
SDL_Thread * eventh = SDL_CreateThread(battleEventThread, NULL);
while(true) //do zwyciestwa jednej ze stron
{
for(int i=0;i<stacks.size();i++)
{
curB->activeStack = i;
if(stacks[i]->alive) //niech interfejs ruszy oddzialem
{
if(CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)]->human)
{
((CPlayerInterface*)CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)])->activeStack(stacks[i]->ID);
}
else
{
//CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)]->activeStack(stacks[i]->ID);
}
}
//sprawdzic czy po tej akcji ktoras strona nie wygrala bitwy
}
SDL_Delay(50);
}
for(int i=0;i<stacks.size();i++)
delete stacks[i];

View File

@ -636,12 +636,12 @@ void CHeroScript::onHeroVisit(CGObjectInstance *os, int heroID)
}
else
{
/*cb->startBattle(
cb->startBattle(
&(static_cast<CGHeroInstance*>(heroes[heroID]))->army,
&(static_cast<CGHeroInstance*>(os))->army,
os->pos,
static_cast<CGHeroInstance*>(heroes[heroID]),
static_cast<CGHeroInstance*>(os));*/
static_cast<CGHeroInstance*>(os));
}
}
std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are handled by script