mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Fixed entering/leaving town.
This commit is contained in:
		| @@ -327,6 +327,43 @@ void CGameState::applyNL(IPack * pack) | ||||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| 	case 108: | ||||
| 		{ | ||||
| 			HeroVisitCastle *vc = static_cast<HeroVisitCastle*>(pack); | ||||
| 			CGHeroInstance *h = getHero(vc->hid); | ||||
| 			CGTownInstance *t = getTown(vc->tid); | ||||
| 			if(vc->start()) | ||||
| 			{ | ||||
| 				if(vc->garrison()) | ||||
| 				{ | ||||
| 					t->garrisonHero = h; | ||||
| 					h->visitedTown = t; | ||||
| 					h->inTownGarrison = true; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					t->visitingHero = h; | ||||
| 					h->visitedTown = t; | ||||
| 					h->inTownGarrison = false; | ||||
| 				} | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				if(vc->garrison()) | ||||
| 				{ | ||||
| 					t->garrisonHero = NULL; | ||||
| 					h->visitedTown = NULL; | ||||
| 					h->inTownGarrison = false; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					t->visitingHero = NULL; | ||||
| 					h->visitedTown = NULL; | ||||
| 					h->inTownGarrison = false; | ||||
| 				} | ||||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| 	case 500: | ||||
| 		{ | ||||
| 			RemoveObject *rh = static_cast<RemoveObject*>(pack); | ||||
| @@ -502,6 +539,12 @@ CGHeroInstance *CGameState::getHero(int objid) | ||||
| 		return NULL; | ||||
| 	return static_cast<CGHeroInstance *>(map->objects[objid]); | ||||
| } | ||||
| CGTownInstance *CGameState::getTown(int objid) | ||||
| { | ||||
| 	if(objid<0 || objid>=map->objects.size()) | ||||
| 		return NULL; | ||||
| 	return static_cast<CGTownInstance *>(map->objects[objid]); | ||||
| } | ||||
| std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj) | ||||
| { | ||||
| 	switch(obj->ID) | ||||
| @@ -788,6 +831,17 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed) | ||||
| 			int h=pickHero(i); | ||||
| 			CGHeroInstance * nnn =  static_cast<CGHeroInstance*>(createObject(34,h,hpos,i)); | ||||
| 			nnn->id = map->objects.size(); | ||||
| 			hpos = map->players[i].posOfMainTown;hpos.x+=2; | ||||
| 			for(int o=0;o<map->towns.size();o++) //find main town | ||||
| 			{ | ||||
| 				if(map->towns[o]->pos == hpos) | ||||
| 				{ | ||||
| 					map->towns[o]->visitingHero = nnn; | ||||
| 					nnn->visitedTown = map->towns[o]; | ||||
| 					nnn->inTownGarrison = false; | ||||
| 					break; | ||||
| 				} | ||||
| 			} | ||||
| 			//nnn->defInfo->handler = graphics->flags1[0]; | ||||
| 			map->heroes.push_back(nnn); | ||||
| 			map->objects.push_back(nnn); | ||||
|   | ||||
| @@ -135,6 +135,7 @@ private: | ||||
| 	int pickHero(int owner); | ||||
|  | ||||
| 	CGHeroInstance *getHero(int objid); | ||||
| 	CGTownInstance *getTown(int objid); | ||||
|  | ||||
| 	bool battleMoveCreatureStack(int ID, int dest); | ||||
| 	bool battleAttackCreatureStack(int ID, int dest); | ||||
|   | ||||
| @@ -131,6 +131,7 @@ void CGarrisonSlot::clickRight (tribool down) | ||||
| 		{ | ||||
| 			pom = new StackState(); | ||||
| 			const CGHeroInstance *h = static_cast<const CGHeroInstance *>(getObj()); | ||||
| 			pom->currentHealth = 0; | ||||
| 			pom->attackBonus = h->primSkills[0]; | ||||
| 			pom->defenseBonus = h->primSkills[1]; | ||||
| 			pom->luck = h->getCurrentLuck(); | ||||
| @@ -3023,7 +3024,7 @@ CCreInfoWindow::CCreInfoWindow | ||||
| 	printToWR(pom,276,137,GEOR13,zwykly,bitmap); | ||||
|  | ||||
| 	//remaining health | ||||
| 	if(State) | ||||
| 	if(State && State->currentHealth) | ||||
| 	{ | ||||
| 		printAt(CGI->preth->zelp[440].first,155,143,GEOR13,zwykly,bitmap); | ||||
| 		SDL_itoa(State->currentHealth,pom,10); | ||||
|   | ||||
| @@ -239,6 +239,17 @@ void CClient::process(int what) | ||||
| 				static_cast<CPlayerInterface*>(playerint[sii.player])->showComp(sc); | ||||
| 			break; | ||||
| 		} | ||||
| 	case 108: | ||||
| 		{ | ||||
| 			HeroVisitCastle vc; | ||||
| 			*serv >> vc; | ||||
| 			gs->apply(&vc); | ||||
| 			if(vc.start() && !vc.garrison() && vstd::contains(playerint,gs->getHero(vc.hid)->tempOwner)) | ||||
| 			{ | ||||
| 				playerint[gs->getHero(vc.hid)->tempOwner]->heroVisitsTown(gs->getHero(vc.hid),gs->getTown(vc.tid)); | ||||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| 	case 500: | ||||
| 		{ | ||||
| 			RemoveObject rh; | ||||
|   | ||||
| @@ -77,6 +77,25 @@ struct SetSecSkill : public CPack<SetSecSkill> //106 | ||||
| 		h & abs & id & which & val; | ||||
| 	} | ||||
| };  | ||||
| struct HeroVisitCastle : public CPack<HeroVisitCastle> //108 | ||||
| { | ||||
| 	HeroVisitCastle(){flags=0;type = 108;}; | ||||
| 	ui8 flags; //1 - start, 2 - garrison | ||||
| 	ui32 tid, hid; | ||||
|  | ||||
| 	bool start() //if hero is entering castle (if false - leaving) | ||||
| 	{ | ||||
| 		return flags & 1; | ||||
| 	} | ||||
| 	bool garrison() //if hero is entering/leaving garrison (if false - it's only visiting hero) | ||||
| 	{ | ||||
| 		return flags & 2; | ||||
| 	} | ||||
| 	template <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
| 		h & flags & tid & hid; | ||||
| 	} | ||||
| };  | ||||
| struct RemoveObject : public CPack<RemoveObject> //500 | ||||
| { | ||||
| 	RemoveObject(){type = 500;}; | ||||
|   | ||||
| @@ -553,7 +553,7 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c) | ||||
| 					{ | ||||
| 						tmh.result = 1; | ||||
|  | ||||
| 						BOOST_FOREACH(CGObjectInstance *obj, gs->map->terrain[start.x][start.y][start.z].visitableObjects) | ||||
| 						BOOST_FOREACH(CGObjectInstance *obj, gs->map->terrain[start.x-1][start.y][start.z].visitableObjects) | ||||
| 						{ | ||||
| 							//TODO: allow to handle this in script-languages | ||||
| 							if(obj->state) //hard-coded function | ||||
|   | ||||
| @@ -105,29 +105,19 @@ void CScriptCallback::showCompInfo(ShowInInfobox * comp) | ||||
| } | ||||
| void CScriptCallback::heroVisitCastle(int obj, int heroID) | ||||
| { | ||||
| 	//CGTownInstance * n; | ||||
| 	//if(n = dynamic_cast<CGTownInstance*>(ob)) | ||||
| 	//{ | ||||
| 	//	n->visitingHero = CGI->state->map->getHero(heroID,0); | ||||
| 	//	gh->gs->map->getHero(heroID,0)->visitedTown = n; | ||||
| 	//	sv->playerint[getHeroOwner(heroID)]->heroVisitsTown(CGI->state->map->getHero(heroID,0),n); | ||||
| 	//} | ||||
| 	//else | ||||
| 	//	return; | ||||
| 	HeroVisitCastle vc; | ||||
| 	vc.hid = heroID; | ||||
| 	vc.tid = obj; | ||||
| 	vc.flags |= 1; | ||||
| 	gh->sendAndApply(&vc); | ||||
| } | ||||
|  | ||||
| void CScriptCallback::stopHeroVisitCastle(int obj, int heroID) | ||||
| { | ||||
| 	//CGTownInstance * n; | ||||
| 	//if(n = dynamic_cast<CGTownInstance*>(ob)) | ||||
| 	//{ | ||||
| 	//	CGI->state->map->getHero(heroID,0)->visitedTown = NULL; | ||||
| 	//	if(n->visitingHero && n->visitingHero->type->ID == heroID) | ||||
| 	//		n->visitingHero = NULL; | ||||
| 	//	return; | ||||
| 	//} | ||||
| 	//else | ||||
| 	//	return; | ||||
| 	HeroVisitCastle vc; | ||||
| 	vc.hid = heroID; | ||||
| 	vc.tid = obj; | ||||
| 	gh->sendAndApply(&vc); | ||||
| } | ||||
| void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack | ||||
| { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user