mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Further code for objects (mines) - not finished.
This commit is contained in:
parent
b4f383f196
commit
03287540c7
@ -10,6 +10,7 @@ class CCallback;
|
||||
class ICallback;
|
||||
class CGlobalAI;
|
||||
class CGHeroInstance;
|
||||
class Component;
|
||||
class CSelectableComponent;
|
||||
struct HeroMoveDetails;
|
||||
class CGHeroInstance;
|
||||
@ -59,6 +60,7 @@ public:
|
||||
virtual void tileRevealed(int3 pos){};
|
||||
virtual void tileHidden(int3 pos){};
|
||||
virtual void receivedResource(int type, int val){};
|
||||
virtual void showInfoDialog(std::string text, std::vector<Component*> &components)=0{};
|
||||
virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)=0{};
|
||||
virtual void garrisonChanged(const CGObjectInstance * obj){};
|
||||
virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
|
||||
|
@ -104,7 +104,6 @@ public:
|
||||
friend class CClient;
|
||||
friend void initGameState(Mapa * map, CGameInfo * cgi);
|
||||
friend class CScriptCallback;
|
||||
friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
|
||||
friend class CMapHandler;
|
||||
friend class CGameHandler;
|
||||
};
|
||||
|
@ -1034,10 +1034,10 @@ void LClickableArea::deactivate()
|
||||
}
|
||||
void LClickableArea::clickLeft(boost::logic::tribool down)
|
||||
{
|
||||
if(!down)
|
||||
{
|
||||
LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
|
||||
}
|
||||
//if(!down)
|
||||
//{
|
||||
// LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
|
||||
//}
|
||||
}
|
||||
|
||||
void RClickableArea::activate()
|
||||
@ -1050,10 +1050,10 @@ void RClickableArea::deactivate()
|
||||
}
|
||||
void RClickableArea::clickRight(boost::logic::tribool down)
|
||||
{
|
||||
if(!down)
|
||||
{
|
||||
LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
|
||||
}
|
||||
//if(!down)
|
||||
//{
|
||||
// LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
|
||||
//}
|
||||
}
|
||||
|
||||
void LRClickableAreaWText::clickLeft(boost::logic::tribool down)
|
||||
|
40
CLua.cpp
40
CLua.cpp
@ -291,7 +291,7 @@ void CVisitableOPH::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
|
||||
else
|
||||
{
|
||||
ot++;
|
||||
cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&std::vector<SComponent*>());
|
||||
//cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[ot],&std::vector<SComponent*>());
|
||||
}
|
||||
}
|
||||
|
||||
@ -415,36 +415,32 @@ void CMines::newObject(int objid)
|
||||
}
|
||||
void CMines::onHeroVisit(int objid, int heroID)
|
||||
{
|
||||
//TODO: this is code for standard mines, no support for abandoned mine (subId==7)
|
||||
DEFOS;
|
||||
const CGHeroInstance *h = cb->getHero(heroID);
|
||||
cb->setOwner(objid,h->tempOwner);
|
||||
MetaString ms;
|
||||
ms << std::pair<ui8,ui32>(9,os->subID) << " " << std::pair<ui8,ui32>(6,23+h->tempOwner);
|
||||
cb->setHoverName(objid,&ms);
|
||||
//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+=VLC->generaltexth->allTexts[3].substr(2,VLC->generaltexth->allTexts[3].length()-2);
|
||||
// std::vector<SComponent*> weko;
|
||||
// weko.push_back(com);
|
||||
// cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->mines[os->subID].second,&weko);
|
||||
//}
|
||||
ms.clear();
|
||||
|
||||
int vv=1; //amount of resource per turn
|
||||
if (os->subID==0 || os->subID==2)
|
||||
vv++;
|
||||
else if (os->subID==6)
|
||||
vv = 1000;
|
||||
|
||||
InfoWindow iw;
|
||||
iw.text << std::pair<ui8,ui32>(10,os->subID);
|
||||
iw.player = h->tempOwner;
|
||||
iw.components.push_back(Component(2,os->subID,vv,-1));
|
||||
cb->showInfoDialog(&iw);
|
||||
//TODO: leaving garrison
|
||||
|
||||
}
|
||||
std::vector<int> CMines::yourObjects()
|
||||
{
|
||||
std::vector<int> ret(1);
|
||||
std::vector<int> ret;
|
||||
ret.push_back(53);
|
||||
return ret;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "client/CCreatureAnimation.h"
|
||||
#include "client/Graphics.h"
|
||||
#include "map.h"
|
||||
#include "lib/NetPacks.h"
|
||||
using namespace CSDL_Ext;
|
||||
|
||||
extern TTF_Font * GEOR16;
|
||||
@ -41,6 +42,14 @@ CPlayerInterface * LOCPLINT;
|
||||
extern std::queue<SDL_Event> events;
|
||||
extern boost::mutex eventsM;
|
||||
|
||||
SComponent toSComponent(const Component *c)
|
||||
{
|
||||
SComponent ret((SComponent::Etype)c->type,c->subtype,c->val);
|
||||
if(c->type == 2)
|
||||
ret.subtitle+=CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
class OCM_HLP_CGIN
|
||||
{
|
||||
public:
|
||||
@ -2014,6 +2023,24 @@ void CPlayerInterface::showComp(SComponent comp)
|
||||
adventureInt->infoBar.showComp(&comp,4000);
|
||||
}
|
||||
|
||||
void CPlayerInterface::showInfoDialog(std::string text, std::vector<Component*> &components)
|
||||
{
|
||||
curint->deactivate(); //dezaktywacja starego interfejsu
|
||||
std::vector<SComponent*> intComps;
|
||||
CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,intComps);
|
||||
LOCPLINT->objsToBlit.push_back(temp);
|
||||
temp->pos.x=300-(temp->pos.w/2);
|
||||
temp->pos.y=300-(temp->pos.h/2);
|
||||
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::showInfoDialog(std::string text, std::vector<SComponent*> & components)
|
||||
{
|
||||
curint->deactivate(); //dezaktywacja starego interfejsu
|
||||
|
@ -154,7 +154,7 @@ public:
|
||||
};
|
||||
|
||||
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
|
||||
{ //okno usuwa swoje komponenty w chwili zamkniecia
|
||||
{ //window deletes its components when closed
|
||||
public:
|
||||
CSCButton<CInfoWindow> okb;
|
||||
std::vector<SComponent*> components;
|
||||
@ -320,6 +320,7 @@ public:
|
||||
void heroCreated(const CGHeroInstance* hero);
|
||||
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
|
||||
void receivedResource(int type, int val);
|
||||
void showInfoDialog(std::string text, std::vector<Component*> &components);
|
||||
void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID);
|
||||
void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
|
||||
void garrisonChanged(const CGObjectInstance * obj);
|
||||
@ -350,8 +351,8 @@ public:
|
||||
void handleMouseMotion(SDL_Event *sEvent);
|
||||
void init(ICallback * CB);
|
||||
int3 repairScreenPos(int3 pos);
|
||||
void removeObjToBlit(IShowable* obj);
|
||||
void showInfoDialog(std::string text, std::vector<SComponent*> & components);
|
||||
void removeObjToBlit(IShowable* obj);
|
||||
|
||||
CPlayerInterface(int Player, int serial);//c-tor
|
||||
};
|
||||
|
@ -29,20 +29,26 @@ std::string toString(MetaString &ms)
|
||||
else
|
||||
{
|
||||
std::vector<std::string> *vec;
|
||||
int type = ms.texts[-ms.message[i]-1].first;
|
||||
int type = ms.texts[-ms.message[i]-1].first,
|
||||
ser = ms.texts[-ms.message[i]-1].second;
|
||||
if(type == 5)
|
||||
{
|
||||
ret += CGI->arth->artifacts[ms.texts[-ms.message[i]-1].second].name;
|
||||
ret += CGI->arth->artifacts[ser].name;
|
||||
continue;
|
||||
}
|
||||
else if(type == 7)
|
||||
{
|
||||
ret += CGI->creh->creatures[ms.texts[-ms.message[i]-1].second].namePl;
|
||||
ret += CGI->creh->creatures[ser].namePl;
|
||||
continue;
|
||||
}
|
||||
else if(type == 9)
|
||||
{
|
||||
ret += CGI->objh->mines[ms.texts[-ms.message[i]-1].second].first;
|
||||
ret += CGI->objh->mines[ser].first;
|
||||
continue;
|
||||
}
|
||||
else if(type == 10)
|
||||
{
|
||||
ret += CGI->objh->mines[ser].second;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
@ -68,7 +74,7 @@ std::string toString(MetaString &ms)
|
||||
vec = &CGI->objh->creGens;
|
||||
break;
|
||||
}
|
||||
ret += (*vec)[ms.texts[-ms.message[i]-1].second];
|
||||
ret += (*vec)[ser];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,6 +165,22 @@ void CClient::process(int what)
|
||||
std::cout << "done!"<<std::endl;
|
||||
break;
|
||||
}
|
||||
case 102: //set resource amount
|
||||
{
|
||||
SetResource sr;
|
||||
*serv >> sr;
|
||||
std::cout << "Set amount of "<<CGI->objh->restypes[sr.resid]
|
||||
<< " of player "<<(unsigned)sr.player <<" to "<<sr.val<<std::endl;
|
||||
gs->apply(&sr);
|
||||
playerint[sr.player]->receivedResource(sr.resid,sr.val);
|
||||
break;
|
||||
}
|
||||
case 103: //show info dialog
|
||||
{
|
||||
InfoWindow iw;
|
||||
*serv >> iw;
|
||||
|
||||
}
|
||||
case 501: //hero movement response - we have to notify interfaces and callback
|
||||
{
|
||||
TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing
|
||||
|
@ -59,6 +59,18 @@ struct NewTurn : public CPack<NewTurn> //101
|
||||
h & heroes & res & day & resetBuilded;
|
||||
}
|
||||
};
|
||||
struct SetResource : public CPack<SetResource> //102
|
||||
{
|
||||
SetResource(){type = 102;};
|
||||
|
||||
ui8 player, resid;
|
||||
si32 val;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & player & resid & val;
|
||||
}
|
||||
};
|
||||
struct TryMoveHero : public CPack<TryMoveHero> //501
|
||||
{
|
||||
TryMoveHero(){type = 501;};
|
||||
@ -76,7 +88,7 @@ struct TryMoveHero : public CPack<TryMoveHero> //501
|
||||
struct MetaString : public CPack<MetaString> //2001 helper for object scrips
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
std::vector<std::pair<ui8,ui32> > texts; //pairs<text handler type, text number>; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first
|
||||
std::vector<std::pair<ui8,ui32> > texts; //pairs<text handler type, text number>; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first; 10 - objh->mines[ID].second
|
||||
std::vector<si32> message;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
@ -96,8 +108,40 @@ struct MetaString : public CPack<MetaString> //2001 helper for object scrips
|
||||
strings.push_back(txt);
|
||||
return *this;
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
strings.clear();
|
||||
texts.clear();
|
||||
message.clear();
|
||||
}
|
||||
|
||||
MetaString(){type = 2001;};
|
||||
};
|
||||
struct Component : public CPack<Component> //2002 helper for object scrips informations
|
||||
{
|
||||
ui16 type, subtype; //types: 0 - primskill; 1 - secskill; 2 - resource; 3 - creature; 4 - artifact; 5 - experience
|
||||
si32 val; // + give; - take
|
||||
si16 when; // 0 - now; +x - within x days; -x - per x days
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & type & subtype & val & when;
|
||||
}
|
||||
Component(){type = 2002;};
|
||||
Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):type(Type),subtype(Subtype),val(Val),when(When){type = 2002;};
|
||||
};
|
||||
|
||||
struct InfoWindow : public CPack<InfoWindow> //103 - displays simple info window
|
||||
{
|
||||
MetaString text;
|
||||
std::vector<Component> components;
|
||||
ui8 player;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & text & components & player;
|
||||
}
|
||||
InfoWindow(){type = 103;};
|
||||
};
|
||||
|
||||
struct SetObjectProperty : public CPack<SetObjectProperty>//1001
|
||||
|
@ -213,22 +213,6 @@ void CGameHandler::init(StartInfo *si, int Seed)
|
||||
gs = new CGameState();
|
||||
gs->init(si,map,Seed);
|
||||
|
||||
/****************************SCRIPTS************************************************/
|
||||
//std::map<int, std::map<std::string, CObjectScript*> > * skrypty = &objscr; //alias for easier access
|
||||
/****************************C++ OBJECT SCRIPTS************************************************/
|
||||
std::map<int,CCPPObjectScript*> scripts;
|
||||
CScriptCallback * csc = new CScriptCallback();
|
||||
csc->gh = this;
|
||||
handleCPPObjS(&scripts,new CVisitableOPH(csc));
|
||||
handleCPPObjS(&scripts,new CVisitableOPW(csc));
|
||||
handleCPPObjS(&scripts,new CPickable(csc));
|
||||
handleCPPObjS(&scripts,new CMines(csc));
|
||||
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************************************************/
|
||||
//std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
|
||||
//for (int i=0; i<lf->size(); i++)
|
||||
@ -252,25 +236,6 @@ void CGameHandler::init(StartInfo *si, int Seed)
|
||||
// delete temp;
|
||||
// }HANDLE_EXCEPTION
|
||||
//}
|
||||
/****************************INITIALIZING OBJECT SCRIPTS************************************************/
|
||||
//std::string temps("newObject");
|
||||
for (unsigned i=0; i<map->objects.size(); i++)
|
||||
{
|
||||
//c++ scripts
|
||||
if (scripts.find(map->objects[i]->ID) != scripts.end())
|
||||
{
|
||||
map->objects[i]->state = scripts[map->objects[i]->ID];
|
||||
map->objects[i]->state->newObject(map->objects[i]->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
map->objects[i]->state = NULL;
|
||||
}
|
||||
|
||||
//// lua scripts
|
||||
//if(checkFunc(map->objects[i]->ID,temps))
|
||||
// (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
|
||||
}
|
||||
|
||||
//delete lf;
|
||||
}
|
||||
@ -363,6 +328,42 @@ void CGameHandler::run()
|
||||
|
||||
boost::thread(boost::bind(&CGameHandler::handleConnection,this,pom,boost::ref(**i)));
|
||||
}
|
||||
|
||||
/****************************SCRIPTS************************************************/
|
||||
//std::map<int, std::map<std::string, CObjectScript*> > * skrypty = &objscr; //alias for easier access
|
||||
/****************************C++ OBJECT SCRIPTS************************************************/
|
||||
std::map<int,CCPPObjectScript*> scripts;
|
||||
CScriptCallback * csc = new CScriptCallback();
|
||||
csc->gh = this;
|
||||
handleCPPObjS(&scripts,new CVisitableOPH(csc));
|
||||
handleCPPObjS(&scripts,new CVisitableOPW(csc));
|
||||
handleCPPObjS(&scripts,new CPickable(csc));
|
||||
handleCPPObjS(&scripts,new CMines(csc));
|
||||
handleCPPObjS(&scripts,new CTownScript(csc));
|
||||
handleCPPObjS(&scripts,new CHeroScript(csc));
|
||||
handleCPPObjS(&scripts,new CMonsterS(csc));
|
||||
handleCPPObjS(&scripts,new CCreatureGen(csc));
|
||||
|
||||
/****************************INITIALIZING OBJECT SCRIPTS************************************************/
|
||||
//std::string temps("newObject");
|
||||
for (unsigned i=0; i<gs->map->objects.size(); i++)
|
||||
{
|
||||
//c++ scripts
|
||||
if (scripts.find(gs->map->objects[i]->ID) != scripts.end())
|
||||
{
|
||||
gs->map->objects[i]->state = scripts[gs->map->objects[i]->ID];
|
||||
gs->map->objects[i]->state->newObject(gs->map->objects[i]->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
gs->map->objects[i]->state = NULL;
|
||||
}
|
||||
|
||||
//// lua scripts
|
||||
//if(checkFunc(map->objects[i]->ID,temps))
|
||||
// (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
|
||||
}
|
||||
|
||||
while (!end)
|
||||
{
|
||||
newTurn();
|
||||
|
@ -87,8 +87,9 @@ int CScriptCallback::getHeroOwner(int heroID)
|
||||
//return hero->getOwner();
|
||||
return -1;
|
||||
}
|
||||
void CScriptCallback::showInfoDialog(int player, std::string text, std::vector<SComponent*> * components)
|
||||
void CScriptCallback::showInfoDialog(InfoWindow *iw)
|
||||
{
|
||||
gh->sendToAllClients(iw);
|
||||
//TODO: upewniac sie ze mozemy to zrzutowac (przy customowych interfejsach cos moze sie kopnac)
|
||||
//if (player>=0)
|
||||
//{
|
||||
@ -153,6 +154,11 @@ int CScriptCallback::getDate(int mode)
|
||||
}
|
||||
void CScriptCallback::giveResource(int player, int which, int val)
|
||||
{
|
||||
SetResource sr;
|
||||
sr.player = player;
|
||||
sr.resid = which;
|
||||
sr.val = (gh->gs->players[player].resources[which]+val);
|
||||
gh->sendAndApply(&sr);
|
||||
//gh->gs->players[player].resources[which]+=val;
|
||||
//sv->playerint[player]->receivedResource(which,val);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ class CGTownInstance;
|
||||
class CGameState;
|
||||
struct lua_State;
|
||||
struct MetaString;
|
||||
struct InfoWindow;
|
||||
class CScriptCallback
|
||||
{
|
||||
CScriptCallback(void);
|
||||
@ -35,7 +36,7 @@ public:
|
||||
void setOwner(int objid, ui8 owner);
|
||||
void setHoverName(int objid, MetaString * name);
|
||||
void changePrimSkill(int ID, int which, int val);
|
||||
void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components); //TODO: obslugiwac nulle
|
||||
void showInfoDialog(InfoWindow *iw);
|
||||
void showSelDialog(int player, std::string text, std::vector<CSelectableComponent*>*components, IChosen * asker);
|
||||
void giveResource(int player, int which, int val);
|
||||
void showCompInfo(int player, SComponent * comp);
|
||||
|
Loading…
Reference in New Issue
Block a user