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