mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Working mines and minor improvements.
This commit is contained in:
parent
736af28c05
commit
845d99a908
@ -38,10 +38,9 @@ void CCallback::newTurn()
|
||||
{
|
||||
//std::map<int, PlayerState>::iterator i = gs->players.begin() ;
|
||||
gs->day++;
|
||||
for (int i=0;i<CGI->objh->objInstances.size();i++)
|
||||
for (std::set<CCPPObjectScript *>::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++)
|
||||
{
|
||||
if (CGI->objh->objInstances[i]->state)
|
||||
CGI->objh->objInstances[i]->state->newTurn();
|
||||
(*i)->newTurn();
|
||||
}
|
||||
for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
{
|
||||
|
@ -1,11 +1,13 @@
|
||||
#ifndef CGAMESTATE_H
|
||||
#define CGAMESTATE_H
|
||||
#include "mapHandler.h"
|
||||
#include <set>
|
||||
class CScriptCallback;
|
||||
class CHeroInstance;
|
||||
class CTownInstance;
|
||||
class CCallback;
|
||||
class CLuaCallback;
|
||||
class CCPPObjectScript;
|
||||
struct PlayerState
|
||||
{
|
||||
public:
|
||||
@ -24,7 +26,8 @@ private:
|
||||
int currentPlayer;
|
||||
int day; //total number of days in game
|
||||
std::map<int,PlayerState> players; //color <-> playerstate
|
||||
std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts
|
||||
std::set<CCPPObjectScript *> cppscripts;
|
||||
std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts (as for now only Lua)
|
||||
|
||||
|
||||
bool checkFunc(int obid, std::string name)
|
||||
@ -58,6 +61,7 @@ public:
|
||||
friend int _tmain(int argc, _TCHAR* argv[]);
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
friend CScriptCallback;
|
||||
friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
|
||||
//CCallback * cb; //for communication between PlayerInterface/AI and GameState
|
||||
|
||||
friend SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap); //todo: wywalic koniecznie, tylko do flag obecnie!!!!
|
||||
|
66
CLua.cpp
66
CLua.cpp
@ -389,13 +389,59 @@ std::string CVisitableOPW::hoverText(CGObjectInstance *os)
|
||||
return CGI->objh->objects[os->defInfo->id].name + " " + ( (visited[os]) ? (CGI->generaltexth->allTexts[352]) : (CGI->generaltexth->allTexts[353])) ;
|
||||
}
|
||||
|
||||
//std::string SComponent::getSubtitle()
|
||||
//{
|
||||
// std::string ret;
|
||||
//
|
||||
//
|
||||
// return ret;
|
||||
//}
|
||||
//void SComponent::getDescription(Etype Type, int Subtype)
|
||||
//{
|
||||
//}
|
||||
void CMines::newObject(CGObjectInstance *os)
|
||||
{
|
||||
ourObjs.push_back(os);
|
||||
os->tempOwner = NEUTRAL_PLAYER;
|
||||
}
|
||||
void CMines::onHeroVisit(CGObjectInstance *os, int heroID)
|
||||
{
|
||||
int vv = 1;
|
||||
if (os->subID==0 || os->subID==2)
|
||||
vv++;
|
||||
else if (os->subID==6)
|
||||
vv = 1000;
|
||||
if (os->tempOwner == cb->getHeroOwner(heroID))
|
||||
{
|
||||
//TODO: garrison
|
||||
}
|
||||
else
|
||||
{
|
||||
if (os->subID==7)
|
||||
return; //TODO: support for abandoned mine
|
||||
os->tempOwner = cb->getHeroOwner(heroID);
|
||||
SComponent * com = new SComponent(SComponent::Etype::resource,os->subID,vv);
|
||||
com->subtitle+=CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
|
||||
std::vector<SComponent*> weko;
|
||||
weko.push_back(com);
|
||||
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->mines[os->subID].second,&weko);
|
||||
}
|
||||
}
|
||||
std::vector<int> CMines::yourObjects()
|
||||
{
|
||||
std::vector<int> ret(1);
|
||||
ret.push_back(53);
|
||||
return ret;
|
||||
}
|
||||
std::string CMines::hoverText(CGObjectInstance *os)
|
||||
{
|
||||
if (os->tempOwner == NEUTRAL_PLAYER)
|
||||
return CGI->objh->mines[os->subID].first;
|
||||
else
|
||||
return CGI->objh->mines[os->subID].first + " " + CGI->generaltexth->arraytxt[23+os->tempOwner];
|
||||
|
||||
}
|
||||
void CMines::newTurn ()
|
||||
{
|
||||
for (int i=0;i<ourObjs.size();i++)
|
||||
{
|
||||
if (ourObjs[i]->tempOwner == NEUTRAL_PLAYER)
|
||||
continue;
|
||||
int vv = 1;
|
||||
if (ourObjs[i]->subID==0 || ourObjs[i]->subID==2)
|
||||
vv++;
|
||||
else if (ourObjs[i]->subID==6)
|
||||
vv = 1000;
|
||||
cb->giveResource(ourObjs[i]->tempOwner,ourObjs[i]->subID,vv);
|
||||
}
|
||||
}
|
15
CLua.h
15
CLua.h
@ -114,3 +114,18 @@ class CVisitableOPW : public CCPPObjectScript //once per week
|
||||
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
||||
|
||||
class CMines : public CCPPObjectScript //flaggable, and giving resource at each day
|
||||
{
|
||||
CMines(CScriptCallback * CB):CCPPObjectScript(CB){};
|
||||
|
||||
std::vector<CGObjectInstance*> ourObjs;
|
||||
|
||||
void newObject(CGObjectInstance *os);
|
||||
void onHeroVisit(CGObjectInstance *os, int heroID);
|
||||
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
||||
std::string hoverText(CGObjectInstance *os);
|
||||
void newTurn ();
|
||||
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
2
CMT.cpp
2
CMT.cpp
@ -66,6 +66,7 @@ void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * sc
|
||||
{
|
||||
(*mapa)[tempv[i]]=script;
|
||||
}
|
||||
CGI->state->cppscripts.insert(script);
|
||||
}
|
||||
void initGameState(CGameInfo * cgi)
|
||||
{
|
||||
@ -221,6 +222,7 @@ void initGameState(CGameInfo * cgi)
|
||||
csc->gs = cgi->state;
|
||||
handleCPPObjS(&scripts,new CVisitableOPH(csc));
|
||||
handleCPPObjS(&scripts,new CVisitableOPW(csc));
|
||||
handleCPPObjS(&scripts,new CMines(csc));
|
||||
//created map
|
||||
|
||||
|
||||
|
@ -41,7 +41,11 @@ void CInfoWindow::okClicked(tribool down)
|
||||
void CInfoWindow::close()
|
||||
{
|
||||
for (int i=0;i<components.size();i++)
|
||||
{
|
||||
components[i]->deactivate();
|
||||
delete components[i];
|
||||
}
|
||||
components.clear();
|
||||
okb.deactivate();
|
||||
SDL_FreeSurface(bitmap);
|
||||
bitmap = NULL;
|
||||
@ -1195,7 +1199,7 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int
|
||||
}
|
||||
void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
|
||||
{
|
||||
adventureInt->hide();
|
||||
adventureInt->hide(); //dezaktywacja starego interfejsu
|
||||
CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
|
||||
LOCPLINT->objsToBlit.push_back(temp);
|
||||
temp->pos.x=300-(temp->pos.w/2);
|
||||
@ -1203,6 +1207,12 @@ void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*>
|
||||
temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
|
||||
temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
|
||||
temp->okb.activate();
|
||||
for (int i=0;i<temp->components.size();i++)
|
||||
{
|
||||
temp->components[i]->activate();
|
||||
temp->components[i]->pos.x += temp->pos.x;
|
||||
temp->components[i]->pos.y += temp->pos.y;
|
||||
}
|
||||
}
|
||||
void CPlayerInterface::removeObjToBlit(CSimpleWindow* obj)
|
||||
{
|
||||
|
2
global.h
2
global.h
@ -41,7 +41,7 @@ const int HEROES_QUANTITY=156;
|
||||
const int RESOURCE_QUANTITY=8;
|
||||
const int TERRAIN_TYPES=10;
|
||||
const int PRIMARY_SKILLS=4;
|
||||
|
||||
const int NEUTRAL_PLAYER=255;
|
||||
const int NAMES_PER_TOWN=16;
|
||||
|
||||
#define MARK_BLOCKED_POSITIONS false
|
||||
|
@ -36,13 +36,30 @@ void CObjectHandler::loadObjects()
|
||||
|
||||
buf = CGameInfo::mainObj->bitmaph->getTextFile("XTRAINFO.TXT");
|
||||
it=0;
|
||||
temp;
|
||||
while (it<buf.length()-1)
|
||||
{
|
||||
CGeneralTextHandler::loadToIt(temp,buf,it,3);
|
||||
xtrainfo.push_back(temp);
|
||||
}
|
||||
|
||||
buf = CGameInfo::mainObj->bitmaph->getTextFile("MINENAME.TXT");
|
||||
it=0;
|
||||
while (it<buf.length()-1)
|
||||
{
|
||||
CGeneralTextHandler::loadToIt(temp,buf,it,3);
|
||||
mines.push_back(std::pair<std::string,std::string>(temp,""));
|
||||
}
|
||||
|
||||
buf = CGameInfo::mainObj->bitmaph->getTextFile("MINEEVNT.TXT");
|
||||
it=0;
|
||||
int i=0;
|
||||
while (it<buf.length()-1)
|
||||
{
|
||||
CGeneralTextHandler::loadToIt(temp,buf,it,3);
|
||||
temp = temp.substr(1,temp.length()-2);
|
||||
mines[i++].second = temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CObjectInstance::operator <(const CObjectInstance &cmp) const
|
||||
|
@ -450,6 +450,7 @@ public:
|
||||
|
||||
std::vector<std::string> advobtxt;
|
||||
std::vector<std::string> xtrainfo;
|
||||
std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user