mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Mines and object visitable once per week working.
This commit is contained in:
parent
03287540c7
commit
28d5c184a9
@ -122,6 +122,12 @@ void CGameState::apply(IPack * pack)
|
||||
t->builded = 0;
|
||||
break;
|
||||
}
|
||||
case 102: //set resource amount
|
||||
{
|
||||
SetResource *sr = static_cast<SetResource*>(pack);
|
||||
players[sr->player].resources[sr->resid] = sr->val;
|
||||
break;
|
||||
}
|
||||
case 501://hero try-move
|
||||
{
|
||||
TryMoveHero * n = static_cast<TryMoveHero*>(pack);
|
||||
|
143
CLua.cpp
143
CLua.cpp
@ -201,7 +201,6 @@ void CVisitableOPH::newObject(int objid)
|
||||
default:
|
||||
throw new std::exception("Unsupported ID in CVisitableOPH::hoverText");
|
||||
}
|
||||
|
||||
hovername << std::pair<ui8,ui32>(3,os->ID) << " " << std::pair<ui8,ui32>(2,pom);
|
||||
cb->setHoverName(objid,&hovername);
|
||||
|
||||
@ -308,74 +307,88 @@ std::vector<int> CVisitableOPH::yourObjects()
|
||||
|
||||
void CVisitableOPW::onNAHeroVisit(int objid, int heroID, bool alreadyVisited)
|
||||
{
|
||||
//int mid;
|
||||
//switch (os->ID)
|
||||
//{
|
||||
//case 55:
|
||||
// mid = 92;
|
||||
// break;
|
||||
//case 112:
|
||||
// mid = 170;
|
||||
// break;
|
||||
//case 109:
|
||||
// mid = 164;
|
||||
// break;
|
||||
//}
|
||||
//if (alreadyVisited)
|
||||
//{
|
||||
// if (os->ID!=112)
|
||||
// mid++;
|
||||
// else
|
||||
// mid--;
|
||||
// cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[mid],&std::vector<SComponent*>()); //TODO: maybe we have memory leak with these windows
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// int type, sub, val;
|
||||
// type = SComponent::resource;
|
||||
// switch (os->ID)
|
||||
// {
|
||||
// case 55:
|
||||
// if (rand()%2)
|
||||
// {
|
||||
// sub = 5;
|
||||
// val = 5;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sub = 6;
|
||||
// val = 500;
|
||||
// }
|
||||
// break;
|
||||
// case 112:
|
||||
// mid = 170;
|
||||
// sub = (rand() % 5) + 1;
|
||||
// val = (rand() % 4) + 3;
|
||||
// break;
|
||||
// case 109:
|
||||
// mid = 164;
|
||||
// sub = 6;
|
||||
// if(cb->getDate(2)<2)
|
||||
// val = 500;
|
||||
// else
|
||||
// val = 1000;
|
||||
// }
|
||||
// SComponent * com = new SComponent((SComponent::Etype)type,sub,val);
|
||||
// std::vector<SComponent*> weko;
|
||||
// weko.push_back(com);
|
||||
// cb->giveResource(cb->getHeroOwner(heroID),sub,val);
|
||||
// cb->showInfoDialog(cb->getHeroOwner(heroID),VLC->objh->advobtxt[mid],&weko);
|
||||
// visited[os] = true;
|
||||
//}
|
||||
DEFOS;
|
||||
int mid;
|
||||
switch (os->ID)
|
||||
{
|
||||
case 55:
|
||||
mid = 92;
|
||||
break;
|
||||
case 112:
|
||||
mid = 170;
|
||||
break;
|
||||
case 109:
|
||||
mid = 164;
|
||||
break;
|
||||
}
|
||||
if (alreadyVisited)
|
||||
{
|
||||
if (os->ID!=112)
|
||||
mid++;
|
||||
else
|
||||
mid--;
|
||||
|
||||
InfoWindow iw;
|
||||
iw.player = cb->getHero(heroID)->tempOwner;
|
||||
iw.text << std::pair<ui8,ui32>(11,mid);
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
else
|
||||
{
|
||||
int type, sub, val;
|
||||
type = 2;
|
||||
switch (os->ID)
|
||||
{
|
||||
case 55:
|
||||
if (rand()%2)
|
||||
{
|
||||
sub = 5;
|
||||
val = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
sub = 6;
|
||||
val = 500;
|
||||
}
|
||||
break;
|
||||
case 112:
|
||||
mid = 170;
|
||||
sub = (rand() % 5) + 1;
|
||||
val = (rand() % 4) + 3;
|
||||
break;
|
||||
case 109:
|
||||
mid = 164;
|
||||
sub = 6;
|
||||
if(cb->getDate(2)<2)
|
||||
val = 500;
|
||||
else
|
||||
val = 1000;
|
||||
}
|
||||
int player = cb->getHeroOwner(heroID);
|
||||
cb->giveResource(player,sub,val);
|
||||
InfoWindow iw;
|
||||
iw.player = player;
|
||||
iw.components.push_back(Component(type,sub,val,0));
|
||||
iw.text << std::pair<ui8,ui32>(11,mid);
|
||||
cb->showInfoDialog(&iw);
|
||||
visited[objid] = true;
|
||||
MetaString ms; //set text to "visited"
|
||||
ms << std::pair<ui8,ui32>(3,os->ID) << " " << std::pair<ui8,ui32>(1,352);
|
||||
cb->setHoverName(objid,&ms);
|
||||
}
|
||||
}
|
||||
void CVisitableOPW::newTurn ()
|
||||
{
|
||||
if (cb->getDate(1)==1)
|
||||
if (cb->getDate(1)==1) //first day of week
|
||||
{
|
||||
for (std::map<int,bool>::iterator i = visited.begin(); i != visited.end(); i++)
|
||||
{
|
||||
(*i).second = false;
|
||||
MetaString ms; //set text to "not visited"
|
||||
ms << std::pair<ui8,ui32>(3,cb->getObj(i->first)->ID) << " " << std::pair<ui8,ui32>(1,353);
|
||||
cb->setHoverName(i->first,&ms);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void CVisitableOPW::newObject(int objid)
|
||||
@ -418,6 +431,8 @@ 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);
|
||||
if(h->tempOwner == os->tempOwner)
|
||||
return; //TODO: leaving garrison
|
||||
cb->setOwner(objid,h->tempOwner);
|
||||
MetaString ms;
|
||||
ms << std::pair<ui8,ui32>(9,os->subID) << " " << std::pair<ui8,ui32>(6,23+h->tempOwner);
|
||||
@ -435,8 +450,6 @@ void CMines::onHeroVisit(int objid, int heroID)
|
||||
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()
|
||||
{
|
||||
@ -471,10 +484,10 @@ void CPickable::newObject(int objid)
|
||||
switch (os->ID)
|
||||
{
|
||||
case 79:
|
||||
ms << std::pair<ui8,ui32>(4,os->ID);
|
||||
ms << std::pair<ui8,ui32>(4,os->subID);
|
||||
break;
|
||||
case 5:
|
||||
ms << std::pair<ui8,ui32>(5,os->ID);
|
||||
ms << std::pair<ui8,ui32>(5,os->subID);
|
||||
break;
|
||||
default:
|
||||
ms << std::pair<ui8,ui32>(3,os->ID);
|
||||
|
@ -42,13 +42,6 @@ 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
|
||||
{
|
||||
@ -537,7 +530,7 @@ void CInfoPopup::show(SDL_Surface * to)
|
||||
blitAt(bitmap,pos.x,pos.y,(to)?(to):(screen));
|
||||
}
|
||||
|
||||
SComponent::SComponent(Etype Type, int Subtype, int Val)
|
||||
void SComponent::init(Etype Type, int Subtype, int Val)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
switch (Type)
|
||||
@ -565,7 +558,22 @@ SComponent::SComponent(Etype Type, int Subtype, int Val)
|
||||
pos.w = temp->w;
|
||||
pos.h = temp->h;
|
||||
}
|
||||
SComponent::SComponent(Etype Type, int Subtype, int Val)
|
||||
{
|
||||
init(Type,Subtype,Val);
|
||||
}
|
||||
|
||||
SComponent::SComponent(const Component &c)
|
||||
{
|
||||
init((Etype)c.id,c.subtype,c.val);
|
||||
switch(c.id)
|
||||
{
|
||||
case resource:
|
||||
if(c.when==1)
|
||||
subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDL_Surface * SComponent::getImg()
|
||||
{
|
||||
switch (type)
|
||||
@ -2027,6 +2035,8 @@ void CPlayerInterface::showInfoDialog(std::string text, std::vector<Component*>
|
||||
{
|
||||
curint->deactivate(); //dezaktywacja starego interfejsu
|
||||
std::vector<SComponent*> intComps;
|
||||
for(int i=0;i<components.size();i++)
|
||||
intComps.push_back(new SComponent(*components[i]));
|
||||
CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,intComps);
|
||||
LOCPLINT->objsToBlit.push_back(temp);
|
||||
temp->pos.x=300-(temp->pos.w/2);
|
||||
|
@ -207,8 +207,9 @@ public:
|
||||
std::string description; //r-click
|
||||
std::string subtitle;
|
||||
|
||||
void init(Etype Type, int Subtype, int Val);
|
||||
SComponent(Etype Type, int Subtype, int Val);
|
||||
//SComponent(const & SComponent r);
|
||||
SComponent(const Component &c);
|
||||
|
||||
void clickRight (boost::logic::tribool down);
|
||||
virtual SDL_Surface * getImg();
|
||||
|
@ -73,6 +73,8 @@ std::string toString(MetaString &ms)
|
||||
case 8:
|
||||
vec = &CGI->objh->creGens;
|
||||
break;
|
||||
case 11:
|
||||
vec = &CGI->objh->advobtxt;
|
||||
}
|
||||
ret += (*vec)[ser];
|
||||
}
|
||||
@ -179,7 +181,11 @@ void CClient::process(int what)
|
||||
{
|
||||
InfoWindow iw;
|
||||
*serv >> iw;
|
||||
|
||||
std::vector<Component*> comps;
|
||||
for(int i=0;i<iw.components.size();i++)
|
||||
comps.push_back(&iw.components[i]);
|
||||
playerint[iw.player]->showInfoDialog(toString(iw.text),comps);
|
||||
break;
|
||||
}
|
||||
case 501: //hero movement response - we have to notify interfaces and callback
|
||||
{
|
||||
|
@ -88,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; 10 - objh->mines[ID].second
|
||||
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; 11 - objh->advobtxt
|
||||
std::vector<si32> message;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
@ -119,16 +119,16 @@ struct MetaString : public CPack<MetaString> //2001 helper for object scrips
|
||||
};
|
||||
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
|
||||
ui16 id, subtype; //ids: 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;
|
||||
h & id & 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;};
|
||||
Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):id(Type),subtype(Subtype),val(Val),when(When){type = 2002;};
|
||||
};
|
||||
|
||||
struct InfoWindow : public CPack<InfoWindow> //103 - displays simple info window
|
||||
|
@ -297,10 +297,10 @@ void CGameHandler::newTurn()
|
||||
n.res.insert(r);
|
||||
}
|
||||
sendAndApply(&n);
|
||||
//for (std::set<CCPPObjectScript *>::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++)
|
||||
//{
|
||||
// (*i)->newTurn();
|
||||
//}
|
||||
for (std::set<CCPPObjectScript *>::iterator i=cppscripts.begin();i!=cppscripts.end();i++)
|
||||
{
|
||||
(*i)->newTurn();
|
||||
}
|
||||
}
|
||||
void CGameHandler::run()
|
||||
{
|
||||
|
@ -83,9 +83,7 @@ void CScriptCallback::changePrimSkill(int ID, int which, int val)
|
||||
|
||||
int CScriptCallback::getHeroOwner(int heroID)
|
||||
{
|
||||
//CGHeroInstance * hero = CGI->state->map->getHero(heroID,0);
|
||||
//return hero->getOwner();
|
||||
return -1;
|
||||
return gh->gs->map->objects[heroID]->tempOwner;
|
||||
}
|
||||
void CScriptCallback::showInfoDialog(InfoWindow *iw)
|
||||
{
|
||||
@ -127,30 +125,7 @@ int CScriptCallback::getSelectedHero()
|
||||
}
|
||||
int CScriptCallback::getDate(int mode)
|
||||
{
|
||||
int temp;
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
return gh->gs->day;
|
||||
break;
|
||||
case 1:
|
||||
temp = (gh->gs->day)%7;
|
||||
if (temp)
|
||||
return temp;
|
||||
else return 7;
|
||||
break;
|
||||
case 2:
|
||||
temp = ((gh->gs->day-1)/7)+1;
|
||||
if (!(temp%4))
|
||||
return 4;
|
||||
else
|
||||
return (temp%4);
|
||||
break;
|
||||
case 3:
|
||||
return ((gh->gs->day-1)/28)+1;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
return gh->gs->getDate(mode);
|
||||
}
|
||||
void CScriptCallback::giveResource(int player, int which, int val)
|
||||
{
|
||||
@ -159,8 +134,6 @@ void CScriptCallback::giveResource(int player, int which, int val)
|
||||
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);
|
||||
}
|
||||
void CScriptCallback::showCompInfo(int player, SComponent * comp)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user