1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-21 21:17:49 +02:00
- ally support: adventure map
This commit is contained in:
Ivan Savenko 2010-08-13 10:46:08 +00:00
parent 520d40cc59
commit fd45cd0a6d
10 changed files with 43 additions and 38 deletions

View File

@ -184,7 +184,7 @@ bool CCallback::getTownInfo( const CGObjectInstance *town, InfoAboutTown &dest )
bool detailed = hasAccess(town->tempOwner); bool detailed = hasAccess(town->tempOwner);
//TODO vision support, info about allies //TODO vision support
if(town->ID == TOWNI_TYPE) if(town->ID == TOWNI_TYPE)
dest.initFromTown(static_cast<const CGTownInstance *>(town), detailed); dest.initFromTown(static_cast<const CGTownInstance *>(town), detailed);
else if(town->ID == 33 || town->ID == 219) else if(town->ID == 33 || town->ID == 219)
@ -249,7 +249,7 @@ bool CCallback::getHeroInfo( const CGObjectInstance *hero, InfoAboutHero &dest )
if(!h || !isVisible(h->getPosition(false))) //it's not a hero or it's not visible for layer if(!h || !isVisible(h->getPosition(false))) //it's not a hero or it's not visible for layer
return false; return false;
//TODO vision support, info about allies //TODO vision support
dest.initFromHero(h, hasAccess(h->tempOwner)); dest.initFromHero(h, hasAccess(h->tempOwner));
return true; return true;
} }
@ -956,7 +956,7 @@ void CCallback::castSpell(const CGHeroInstance *hero, int spellID, const int3 &p
bool CCallback::hasAccess(int playerId) const bool CCallback::hasAccess(int playerId) const
{ {
return playerId == player || player < 0; return gs->getPlayerRelations( playerId, player ) || player < 0;
} }
si8 CCallback::battleHasDistancePenalty( int stackID, int destHex ) si8 CCallback::battleHasDistancePenalty( int stackID, int destHex )

View File

@ -1771,14 +1771,17 @@ void CAdvMapInt::tileLClicked(const int3 &mp)
} }
return; return;
} }
//check if we can select this object
bool canSelect = topBlocking && topBlocking->ID == HEROI_TYPE && topBlocking->tempOwner == LOCPLINT->playerID;
canSelect |= topBlocking && topBlocking->ID == TOWNI_TYPE && CGI->state->getPlayerRelations(topBlocking->tempOwner, LOCPLINT->playerID);
if (selection->ID != HEROI_TYPE) //hero is not selected (presumably town) if (selection->ID != HEROI_TYPE) //hero is not selected (presumably town)
{ {
assert(!terrain.currentPath); //path can be active only when hero is selected assert(!terrain.currentPath); //path can be active only when hero is selected
if(selection == topBlocking) //selected town clicked if(selection == topBlocking) //selected town clicked
LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(topBlocking)); LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(topBlocking));
else if(topBlocking && (topBlocking->ID == TOWNI_TYPE || topBlocking->ID == HEROI_TYPE) && topBlocking->tempOwner == LOCPLINT->playerID) //our town/hero clicked else if ( canSelect )
select(static_cast<const CArmedInstance*>(topBlocking), false); select(static_cast<const CArmedInstance*>(topBlocking), false);
return; return;
} }
else if(const CGHeroInstance * currentHero = curHero()) //hero is selected else if(const CGHeroInstance * currentHero = curHero()) //hero is selected
@ -1789,8 +1792,7 @@ void CAdvMapInt::tileLClicked(const int3 &mp)
LOCPLINT->openHeroWindow(currentHero); LOCPLINT->openHeroWindow(currentHero);
return; return;
} }
else if(topBlocking && (topBlocking->ID == HEROI_TYPE || topBlocking->ID == TOWNI_TYPE) //clicked our town or hero else if(canSelect && pn->turns == 255 ) //selectable object at inaccessible tile
&& pn->turns == 255 && topBlocking->tempOwner == LOCPLINT->playerID) //at inaccessible tile
{ {
select(static_cast<const CArmedInstance*>(topBlocking), false); select(static_cast<const CArmedInstance*>(topBlocking), false);
return; return;
@ -1877,11 +1879,11 @@ void CAdvMapInt::tileHovered(const int3 &tile)
if(selection->ID == TOWNI_TYPE) if(selection->ID == TOWNI_TYPE)
{ {
if(objAtTile && objAtTile->tempOwner == LOCPLINT->playerID) if(objAtTile)
{ {
if(objAtTile->ID == TOWNI_TYPE) if(objAtTile->ID == TOWNI_TYPE && CGI->state->getPlayerRelations(objAtTile->tempOwner, LOCPLINT->playerID))
CGI->curh->changeGraphic(0, 3); CGI->curh->changeGraphic(0, 3);
else if(objAtTile->ID == HEROI_TYPE) else if(objAtTile->ID == HEROI_TYPE && objAtTile->tempOwner == LOCPLINT->playerID)
CGI->curh->changeGraphic(0, 2); CGI->curh->changeGraphic(0, 2);
} }
else else
@ -1893,14 +1895,14 @@ void CAdvMapInt::tileHovered(const int3 &tile)
{ {
if(objAtTile->ID == HEROI_TYPE) if(objAtTile->ID == HEROI_TYPE)
{ {
if(objAtTile->tempOwner != LOCPLINT->playerID) //enemy hero TODO: allies if(!CGI->state->getPlayerRelations( objAtTile->tempOwner, LOCPLINT->playerID)) //enemy hero
{ {
if(accessible) if(accessible)
CGI->curh->changeGraphic(0, 5 + turns*6); CGI->curh->changeGraphic(0, 5 + turns*6);
else else
CGI->curh->changeGraphic(0, 0); CGI->curh->changeGraphic(0, 0);
} }
else //our hero else //our or ally hero
{ {
if(selection == objAtTile) if(selection == objAtTile)
CGI->curh->changeGraphic(0, 2); CGI->curh->changeGraphic(0, 2);
@ -1912,7 +1914,7 @@ void CAdvMapInt::tileHovered(const int3 &tile)
} }
else if(objAtTile->ID == TOWNI_TYPE) else if(objAtTile->ID == TOWNI_TYPE)
{ {
if(objAtTile->tempOwner != LOCPLINT->playerID) //enemy town TODO: allies if(!CGI->state->getPlayerRelations( objAtTile->tempOwner, LOCPLINT->playerID)) //enemy town
{ {
if(accessible) if(accessible)
{ {
@ -1930,7 +1932,7 @@ void CAdvMapInt::tileHovered(const int3 &tile)
CGI->curh->changeGraphic(0, 0); CGI->curh->changeGraphic(0, 0);
} }
} }
else //our town else //our or ally town
{ {
if(accessible) if(accessible)
CGI->curh->changeGraphic(0, 9 + turns*6); CGI->curh->changeGraphic(0, 9 + turns*6);
@ -1952,7 +1954,8 @@ void CAdvMapInt::tileHovered(const int3 &tile)
const CGGarrison* garrObj = dynamic_cast<const CGGarrison*>(objAtTile); //TODO evil evil cast! const CGGarrison* garrObj = dynamic_cast<const CGGarrison*>(objAtTile); //TODO evil evil cast!
// Show battle cursor for guarded enemy garrisons, otherwise movement cursor. // Show battle cursor for guarded enemy garrisons, otherwise movement cursor.
if (garrObj && garrObj->tempOwner != LOCPLINT->playerID && garrObj->stacksCount()) if (garrObj&& garrObj->stacksCount()
&& !CGI->state->getPlayerRelations( garrObj->tempOwner, LOCPLINT->playerID) )
CGI->curh->changeGraphic(0, 5 + turns*6); CGI->curh->changeGraphic(0, 5 + turns*6);
else else
CGI->curh->changeGraphic(0, 9 + turns*6); CGI->curh->changeGraphic(0, 9 + turns*6);

View File

@ -782,7 +782,7 @@ void CKingdomInterface::CHeroItem::setHero(const CGHeroInstance * newHero)
artLeft->block(hero->artifacts.size() <= 8); artLeft->block(hero->artifacts.size() <= 8);
artRight->block(hero->artifacts.size() <= 8); artRight->block(hero->artifacts.size() <= 8);
garr = new CGarrisonInt(pos.x+6, pos.y+78, 4, Point(), parent->slots->ourImages[parent->PicCount].bitmap, garr = new CGarrisonInt(pos.x+6, pos.y+78, 4, Point(), parent->slots->ourImages[parent->PicCount].bitmap,
Point(6,78), hero, NULL, true, false, true); Point(6,78), hero, NULL, true, true, true);
for (int i=0; i<artifacts.size(); i++) for (int i=0; i<artifacts.size(); i++)
{ {

View File

@ -1207,6 +1207,7 @@ void CList::fixPos()
amin(from, size() - SIZE); amin(from, size() - SIZE);
amax(from, 0); amax(from, 0);
draw(screen);
} }
CHeroList::CHeroList(int Size) CHeroList::CHeroList(int Size)
@ -1270,6 +1271,8 @@ void CHeroList::select(int which)
selected = which; selected = which;
adventureInt->select(LOCPLINT->wanderingHeroes[which]); adventureInt->select(LOCPLINT->wanderingHeroes[which]);
fixPos();
draw(screen);
} }
void CHeroList::clickLeft(tribool down, bool previousState) void CHeroList::clickLeft(tribool down, bool previousState)
@ -1551,6 +1554,7 @@ void CTownList::select(int which)
selected = which; selected = which;
if(!fun.empty()) if(!fun.empty())
fun(); fun();
fixPos();
} }
void CTownList::mouseMoved (const SDL_MouseMotionEvent & sEvent) void CTownList::mouseMoved (const SDL_MouseMotionEvent & sEvent)

View File

@ -928,7 +928,7 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
if (ID == HEROI_TYPE) //hero if (ID == HEROI_TYPE) //hero
{ {
if( cb->getPlayerRelations(tempOwner, h->tempOwner)) //our or ally hero if( cb->gameState()->getPlayerRelations(tempOwner, h->tempOwner)) //our or ally hero
{ {
//exchange //exchange
cb->heroExchange(h->id, id); cb->heroExchange(h->id, id);
@ -1664,7 +1664,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
return; return;
} }
int relations = cb->getPlayerRelations( h->tempOwner, tempOwner ); int relations = cb->gameState()->getPlayerRelations( h->tempOwner, tempOwner );
if ( relations == 1 )//ally if ( relations == 1 )//ally
return;//do not allow recruiting or capturing return;//do not allow recruiting or capturing
@ -2047,7 +2047,7 @@ bool CGTownInstance::needsLastStack() const
void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
{ {
if( !cb->getPlayerRelations( getOwner(), h->getOwner() ))//if this is enemy if( !cb->gameState()->getPlayerRelations( getOwner(), h->getOwner() ))//if this is enemy
{ {
if(stacksCount() > 0 || visitingHero) if(stacksCount() > 0 || visitingHero)
{ {
@ -3118,7 +3118,7 @@ void CGCreature::flee( const CGHeroInstance * h ) const
void CGMine::onHeroVisit( const CGHeroInstance * h ) const void CGMine::onHeroVisit( const CGHeroInstance * h ) const
{ {
int relations = cb->getPlayerRelations(h->tempOwner, tempOwner); int relations = cb->gameState()->getPlayerRelations(h->tempOwner, tempOwner);
if(relations == 2) //we're visiting our mine if(relations == 2) //we're visiting our mine
{ {
@ -5260,7 +5260,7 @@ void CGScholar::initObj()
void CGGarrison::onHeroVisit (const CGHeroInstance *h) const void CGGarrison::onHeroVisit (const CGHeroInstance *h) const
{ {
int ally = cb->getPlayerRelations(h->tempOwner, tempOwner); int ally = cb->gameState()->getPlayerRelations(h->tempOwner, tempOwner);
if (!ally && stacksCount() > 0) { if (!ally && stacksCount() > 0) {
//TODO: Find a way to apply magic garrison effects in battle. //TODO: Find a way to apply magic garrison effects in battle.
cb->startBattleI(h, this, boost::bind(&CGGarrison::fightOver, this, h, _1)); cb->startBattleI(h, this, boost::bind(&CGGarrison::fightOver, this, h, _1));
@ -6279,7 +6279,7 @@ void CGShipyard::getOutOffsets( std::vector<int3> &offsets ) const
void CGShipyard::onHeroVisit( const CGHeroInstance * h ) const void CGShipyard::onHeroVisit( const CGHeroInstance * h ) const
{ {
if(!cb->getPlayerRelations(tempOwner, h->tempOwner)) if(!cb->gameState()->getPlayerRelations(tempOwner, h->tempOwner))
cb->setOwner(id, h->tempOwner); cb->setOwner(id, h->tempOwner);
int s = state(); int s = state();

View File

@ -2008,6 +2008,16 @@ UpgradeInfo CGameState::getUpgradeInfo(const CStackInstance &stack)
return ret; return ret;
} }
int CGameState::getPlayerRelations( ui8 color1, ui8 color2 )
{
if ( color1 == color2 )
return 2;
const TeamState * ts = getPlayerTeam(color1);
if (ts && vstd::contains(ts->players, color2))
return 1;
return 0;
}
void CGameState::loadTownDInfos() void CGameState::loadTownDInfos()
{ {
for(int i=0;i<F_NUMBER;i++) for(int i=0;i<F_NUMBER;i++)

View File

@ -428,6 +428,7 @@ public:
si8 battleMaxSpellLevel(); //calculates maximum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, SPELL_LEVELS is returned si8 battleMaxSpellLevel(); //calculates maximum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, SPELL_LEVELS is returned
bool battleCanShoot(int ID, int dest); //determines if stack with given ID shoot at the selected destination bool battleCanShoot(int ID, int dest); //determines if stack with given ID shoot at the selected destination
UpgradeInfo getUpgradeInfo(const CStackInstance &stack); UpgradeInfo getUpgradeInfo(const CStackInstance &stack);
int getPlayerRelations(ui8 color1, ui8 color2);// 0 = enemy, 1 = ally, 2 = same player
//float getMarketEfficiency(int player, int mode=0); //float getMarketEfficiency(int player, int mode=0);
std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID); std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID);
int canBuildStructure(const CGTownInstance *t, int ID);// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements int canBuildStructure(const CGTownInstance *t, int ID);// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements

View File

@ -239,18 +239,6 @@ const PlayerState * IGameCallback::getPlayerState( int color )
return gs->getPlayer(color, false); return gs->getPlayer(color, false);
} }
int IGameCallback::getPlayerRelations( ui8 color1, ui8 color2 )
{
if ( color1 == color2 )
return 2;
if ( color1 == 255 || color2 == 255)
return 0;
const TeamState * ts = gs->getPlayerTeam(color1);
if (ts && vstd::contains(ts->players, color2))
return 1;
return 0;
}
const CTown * IGameCallback::getNativeTown(int color) const CTown * IGameCallback::getNativeTown(int color)
{ {
return &VLC->townh->towns[gs->scenarioOps->getIthPlayersSettings(color).castle]; return &VLC->townh->towns[gs->scenarioOps->getIthPlayersSettings(color).castle];

View File

@ -68,7 +68,6 @@ public:
virtual int3 getMapSize(); //returns size of the map virtual int3 getMapSize(); //returns size of the map
virtual TerrainTile * getTile(int3 pos); virtual TerrainTile * getTile(int3 pos);
virtual const PlayerState * getPlayerState(int color); virtual const PlayerState * getPlayerState(int color);
virtual int getPlayerRelations(ui8 color1, ui8 color2);// -1 = enemy, 0 = neutral, 1 = ally, 2 = same player
virtual const CTown *getNativeTown(int color); virtual const CTown *getNativeTown(int color);
//do sth //do sth

View File

@ -1888,7 +1888,7 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*
{ {
CGHeroInstance *dh = static_cast<CGHeroInstance *>(obj); CGHeroInstance *dh = static_cast<CGHeroInstance *>(obj);
if( getPlayerRelations(dh->tempOwner, h->tempOwner)) if( gameState()->getPlayerRelations(dh->tempOwner, h->tempOwner))
{ {
heroExchange(h->id, dh->id); heroExchange(h->id, dh->id);
return true; return true;
@ -2355,7 +2355,7 @@ void CGameHandler::heroExchange(si32 hero1, si32 hero2)
ui8 player1 = getHero(hero1)->tempOwner; ui8 player1 = getHero(hero1)->tempOwner;
ui8 player2 = getHero(hero2)->tempOwner; ui8 player2 = getHero(hero2)->tempOwner;
if( getPlayerRelations( player1, player2)) if( gameState()->getPlayerRelations( player1, player2))
{ {
OpenWindow hex; OpenWindow hex;
hex.window = OpenWindow::EXCHANGE_WINDOW; hex.window = OpenWindow::EXCHANGE_WINDOW;
@ -4553,7 +4553,7 @@ void CGameHandler::checkLossVictory( ui8 player )
sendAndApply(&iw); sendAndApply(&iw);
peg.player = i->first; peg.player = i->first;
peg.victory = getPlayerRelations(player, i->first) == 1; // ally of winner peg.victory = gameState()->getPlayerRelations(player, i->first) == 1; // ally of winner
sendAndApply(&peg); sendAndApply(&peg);
} }
} }