1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Experimental support for Veil of Darkness - messing around with new bonus style. Fixed Cover of Darkness for many players.

Minor fixes, as always.
This commit is contained in:
DjWarmonger 2010-06-07 05:28:12 +00:00
parent e0dc6573bf
commit 6869551510
8 changed files with 124 additions and 30 deletions

View File

@ -46,6 +46,8 @@ extern boost::rand48 ran;
std::map <ui8, std::set <ui8> > CGKeys::playerKeyMap;
std::map <si32, std::vector<si32> > CGMagi::eyelist;
BankConfig CGPyramid::pyramidConfig;
std::map<ui16, Component*> CGArtMerchant::advMapArts;
std::map<ui16, Component*> CGArtMerchant::townArts;
ui8 CGObelisk::obeliskCount; //how many obelisks are on map
std::map<ui8, ui8> CGObelisk::visited; //map: color_id => how many obelisks has been visited
@ -1686,7 +1688,8 @@ void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const
}
void CGTownInstance::initObj()
{
///initialize town structures
{
blockVisit = true;
hoverName = name + ", " + town->Name();
@ -1711,6 +1714,19 @@ void CGTownInstance::initObj()
case 7:
bonusingBuildings.push_back (new CTownBonus(17, this));
break;
case 4:
if (vstd::contains(builtBuildings, 17))
{
GiveBonus gb(GiveBonus::TOWN); //magic
gb.bonus.type = Bonus::DARKNESS;
gb.bonus.val = 20;
gb.id = id;
gb.bonus.duration = Bonus::PERMANENT;
gb.bonus.source = Bonus::TOWN_STRUCTURE;
gb.bonus.id = id;
cb->sendAndApply(&gb);
}
break;
}
}
@ -1756,6 +1772,27 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result )
{
if(result->winner == 0)
{
if (hasBonusOfType(Bonus::DARKNESS))
{
//TODO: Make some 'change owner' function for bonus, or bonuses independent of player
/*
RemoveBonus rb(RemoveBonus::PLAYER);
rb.whoID = getOwner();
rb.source = Bonus::TOWN_STRUCTURE;
rb.id = id;
cb->sendAndApply(&rb);
GiveBonus gb(GiveBonus::PLAYER);
gb.bonus.type = Bonus::DARKNESS;
gb.bonus.val = 20;
gb.id = h->tempOwner;
gb.bonus.duration = Bonus::PERMANENT;
gb.bonus.source = Bonus::TOWN_STRUCTURE;
gb.bonus.id = id;
cb->sendAndApply(&gb);
*/
}
removeCapitols (h->getOwner());
cb->setOwner (id, h->tempOwner); //give control after checkout is done
FoWChange fw;
@ -1763,6 +1800,8 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result )
fw.mode = 1;
getSightTiles (fw.tiles); //update visibility for castle structures
cb->sendAndApply (&fw);
}
}
@ -4401,14 +4440,14 @@ void CGObservatory::onHeroVisit( const CGHeroInstance * h ) const
case 15://cover of darkness
{
iw.text.addTxt (MetaString::ADVOB_TXT, 31);
for (int i = 0; i < cb->gameState()->players.size(); ++i)
for (std::map<ui8, PlayerState>::iterator i = cb->gameState()->players.begin(); i != cb->gameState()->players.end(); i++)
{
if ((h->tempOwner != i) && (cb->gameState()->getPlayer(i)->status == PlayerState::INGAME)) //TODO: team support
if (h->tempOwner != i->first && i->second.status == PlayerState::INGAME) //TODO: team support
{
FoWChange fw;
fw.mode = 0;
fw.player = i;
cb->getTilesInRange (fw.tiles, pos, 20, i, -1);
fw.player = i->first;
cb->getTilesInRange (fw.tiles, pos, 20, i->first, -1);
cb->sendAndApply (&fw);
}
}
@ -5667,11 +5706,6 @@ void CShop::setPropertyDer (ui8 what, ui32 val)
{
switch (what)
{
case 13: //sweep
available.clear();
chosen.clear();
bought.clear();
break;
case 14: //reset - get new items
reset(val);
break;
@ -5705,7 +5739,7 @@ void CGArtMerchant::reset(ui32 val)
{
index = arts.begin() + val % arts.size();
available [available.size()] = new Component (Component::ARTIFACT, (*index)->id, 0, 0);
advMapArts [advMapArts.size()] = new Component (Component::ARTIFACT, (*index)->id, 0, 0);
arts.erase(index);
val *= (id + n * i); //randomize
}
@ -5715,10 +5749,7 @@ void CGArtMerchant::reset(ui32 val)
void CGRefugeeCamp::reset(ui32 val)
{
/*int creid = creh->creatures[val%creh->creatures.size()]->idNumber;
VLC->creh->creatures[creatures[creid].second[0]]->growth;
available[0] = new Component (Component::CREATURE, creid, 0, 0);
*/
creatureID = VLC->creh->creatures[val%VLC->creh->creatures.size()]->idNumber;
}

View File

@ -1078,11 +1078,6 @@ class DLL_EXPORT CShop : public CGObjectInstance
{
///base class for university, art merchant, slave market etc.
public:
std::map<ui16, Component*> available;
std::map<ui16, Component*> chosen, bought; //redundant?
//keys are unique for all three maps
std::map<ui16, ui32> price;
void initObj() {};
void setPropertyDer (ui8 what, ui32 val);
void newTurn() const;
@ -1092,22 +1087,36 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & available & chosen & bought & price;
h & static_cast<CGObjectInstance&>(*this);
}
};
class DLL_EXPORT CGArtMerchant : public CShop
{
///aka Black Market
public:
static std::map<ui16, Component*> advMapArts;
static std::map<ui16, Component*> townArts;
void reset (ui32 val);
void onHeroVisit (const CGHeroInstance * h) const {};
template <typename Handler> void serialize(Handler &h, const int version)
{
h & advMapArts & townArts & static_cast<CShop&>(*this);
}
};
class DLL_EXPORT CGRefugeeCamp : public CShop
{
public:
ui16 creatureID;
void reset (ui32 val);
void onHeroVisit (const CGHeroInstance * h) const {};
template <typename Handler> void serialize(Handler &h, const int version)
{
h & creatureID & static_cast<CShop&>(*this);
}
};
class DLL_EXPORT CGDenOfthieves : public CGObjectInstance

View File

@ -14,6 +14,7 @@
#include "../hch/CHeroHandler.h"
#include "../hch/CObjectHandler.h"
#include "../hch/CCreatureHandler.h"
//#include "../lib/IGameCallback.h"
#include "VCMI_Lib.h"
#include "Connection.h"
#include "map.h"
@ -29,6 +30,7 @@
#include <numeric>
boost::rand48 ran;
class CGObjectInstance;
#ifdef min
#undef min
@ -912,16 +914,18 @@ std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
return std::pair<int,int>(5,VLC->arth->majors[ran()%VLC->arth->majors.size()]->id);
case 69: //random relic artifact
return std::pair<int,int>(5,VLC->arth->relics[ran()%VLC->arth->relics.size()]->id);
/*case 65: //random artifact //TODO: apply new randndomization system
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_TREASURE | CArtifact::ART_MINOR | CArtifact::ART_MAJOR | CArtifact::ART_RELIC));
/*
case 65: //random artifact //how the hell use IGameCallback for this?
return std::pair<int,int>(5, obj->cb->getRandomArt (CArtifact::ART_TREASURE | CArtifact::ART_MINOR | CArtifact::ART_MAJOR | CArtifact::ART_RELIC));
case 66: //random treasure artifact
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_TREASURE));
return std::pair<int,int>(5, cb->getRandomArt(CArtifact::ART_TREASURE));
case 67: //random minor artifact
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_MINOR));
return std::pair<int,int>(5, cb->getRandomArt (CArtifact::ART_MINOR));
case 68: //random major artifact
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_MAJOR));
return std::pair<int,int>(5, cb->getRandomArt (CArtifact::ART_MAJOR));
case 69: //random relic artifact
return std::pair<int,int>(5, cb.getRandomArt (CArtifact::ART_RELIC));*/
return std::pair<int,int>(5, cb->getRandomArt (CArtifact::ART_RELIC));
*/
case 70: //random hero
{
return std::pair<int,int>(HEROI_TYPE,pickHero(obj->tempOwner));

View File

@ -35,6 +35,7 @@
class CTown;
class CScriptCallback;
class CCallback;
class IGameCallback;
class CLuaCallback;
class CCPPObjectScript;
class CCreatureSet;

View File

@ -146,7 +146,8 @@ namespace PrimarySkill
BONUS_NAME(FORGETFULL) /*forgetfulness spell effect, value - level*/ \
BONUS_NAME(NOT_ACTIVE) \
BONUS_NAME(NO_LUCK) /*eg. when fighting on cursed ground*/ \
BONUS_NAME(NO_MORALE) /*eg. when fighting on cursed ground*/
BONUS_NAME(NO_MORALE) /*eg. when fighting on cursed ground*/ \
BONUS_NAME(DARKNESS) /*val = radius */
struct DLL_EXPORT Bonus
{

View File

@ -368,7 +368,7 @@ struct GiveBonus : public CPackForClient //115
void applyCl(CClient *cl);
DLL_EXPORT void applyGs(CGameState *gs);
enum {HERO, PLAYER};
enum {HERO, PLAYER, TOWN};
ui8 who; //who receives bonus, uses enum above
ui32 id; //hero or player id
Bonus bonus;

View File

@ -228,6 +228,12 @@ DLL_EXPORT void GiveBonus::applyGs( CGameState *gs )
bonuses = &p->bonuses;
}
break;
case TOWN:
{
CGTownInstance *t = gs->getTown(id);
assert(t);
bonuses = &t->bonuses;
}
}
bonuses->push_back(bonus);

View File

@ -1026,7 +1026,29 @@ void CGameHandler::newTurn()
}
}
n.res[player][6] += (**j).dailyIncome();
}
}
if ((**j).subID == 2 && vstd::contains((**j).builtBuildings, 26)) // Skyship, probably easier to handle same as Veil of darkness
{ //do it every new day after veils apply
FoWChange fw;
fw.mode = 1;
fw.player = player;
getAllTiles(fw.tiles, player, -1, 0);
sendAndApply (&fw);
}
if ((**j).hasBonusOfType (Bonus::DARKNESS))
{
for (std::map<ui8, PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
{
if (player != i->first && i->second.status == PlayerState::INGAME) //TODO: team support
{
FoWChange fw;
fw.mode = 0;
fw.player = i->first;
getTilesInRange (fw.tiles, (**j).getSightCenter(), (**j).getBonus(Selector::type(Bonus::DARKNESS))->val, i->first, -1);
sendAndApply (&fw);
}
}
}
}
sendAndApply(&n);
@ -2473,6 +2495,17 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid )
ns.bid.insert(28);
else if(bid == 13)
ns.bid.insert(29);
else if (t->subID == 4 && bid == 17) //veil of darkness
{
GiveBonus gb(GiveBonus::PLAYER);
gb.bonus.type = Bonus::DARKNESS;
gb.bonus.val = 20;
gb.id = t->tempOwner;
gb.bonus.duration = Bonus::PERMANENT;
gb.bonus.source = Bonus::TOWN_STRUCTURE;
gb.bonus.id = t->id;
sendAndApply(&gb);
}
ns.bid.insert(bid);
ns.builded = t->builded + 1;
@ -2518,6 +2551,15 @@ bool CGameHandler::razeStructure (si32 tid, si32 bid)
rs.bid.insert(bid);
rs.destroyed = t->destroyed + 1;
sendAndApply(&rs);
//TODO: Remove dwellers
if (t->subID == 4 && bid == 17) //Veil of Darkness
{
RemoveBonus rb(RemoveBonus::PLAYER);
rb.whoID = t->getOwner();
rb.source = Bonus::TOWN_STRUCTURE;
rb.id = t->id;
sendAndApply(&rb);
}
return true;
}