mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
- if special victory condition is present AND there is only one player normal victory condition will be disabled - added new triggered condition, constant value - if target of CONTROL/DESTROY condition is removed from map, triggered condition will be replaced with constant - fixed randomization of armies with random stacks
This commit is contained in:
parent
30aa07f86c
commit
7f07a30d7d
@ -267,6 +267,8 @@ TSubgoal Win::whatToDoToAchieve()
|
||||
break; // goal.value = number of days to trigger this
|
||||
case EventCondition::IS_HUMAN:
|
||||
break; // Should be only used in calculation of candidates (see toBool lambda)
|
||||
case EventCondition::CONST_VALUE:
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ std::string CStackInstance::nodeName() const
|
||||
oss << "Stack of " << count << " of ";
|
||||
if(type)
|
||||
oss << type->namePl;
|
||||
else if(idRand)
|
||||
else if(idRand >= 0)
|
||||
oss << "[no type, idRand=" << idRand << "]";
|
||||
else
|
||||
oss << "[UNDEFINED TYPE]";
|
||||
|
@ -41,7 +41,11 @@ class DLL_LINKAGE CStackInstance : public CBonusSystemNode, public CStackBasicDe
|
||||
protected:
|
||||
const CArmedInstance *_armyObj; //stack must be part of some army, army must be part of some object
|
||||
public:
|
||||
int idRand; //hlp variable used during loading game -> "id" placeholder for randomization
|
||||
// hlp variable used during loading map, when object (hero or town) have creatures that must have same alignment.
|
||||
// idRand < 0 -> normal, non-random creature
|
||||
// idRand / 2 -> level
|
||||
// idRand % 2 -> upgrade number
|
||||
int idRand;
|
||||
|
||||
const CArmedInstance * const & armyObj; //stack must be part of some army, army must be part of some object
|
||||
TExpType experience;//commander needs same amount of exp as hero
|
||||
|
@ -2464,6 +2464,10 @@ bool CGameState::checkForVictory( PlayerColor player, const EventCondition & con
|
||||
else
|
||||
return false;
|
||||
}
|
||||
case EventCondition::CONST_VALUE:
|
||||
{
|
||||
return condition.value; // just convert to bool
|
||||
}
|
||||
}
|
||||
assert(0);
|
||||
return false;
|
||||
|
@ -7162,17 +7162,18 @@ void CGLighthouse::giveBonusTo( PlayerColor player ) const
|
||||
|
||||
void CArmedInstance::randomizeArmy(int type)
|
||||
{
|
||||
int max = VLC->creh->creatures.size();
|
||||
for (auto & elem : stacks)
|
||||
{
|
||||
int randID = elem.second->idRand;
|
||||
if(randID > max)
|
||||
int & randID = elem.second->idRand;
|
||||
if(randID >= 0)
|
||||
{
|
||||
int level = (randID-VLC->creh->creatures.size()) / 2 -1;
|
||||
bool upgrade = !(randID % 2);
|
||||
int level = randID / 2;
|
||||
bool upgrade = randID % 2;
|
||||
elem.second->setType(VLC->townh->factions[type]->town->creatures[level][upgrade]);
|
||||
}
|
||||
|
||||
randID = -1;
|
||||
}
|
||||
assert(elem.second->valid(false));
|
||||
assert(elem.second->armyObj == this);
|
||||
}
|
||||
return;
|
||||
|
@ -358,6 +358,27 @@ DLL_LINKAGE void RemoveObject::applyGs( CGameState *gs )
|
||||
}
|
||||
}
|
||||
|
||||
for (TriggeredEvent & event : gs->map->triggeredEvents)
|
||||
{
|
||||
auto patcher = [&](EventCondition & cond)
|
||||
{
|
||||
if (cond.object == obj)
|
||||
{
|
||||
if (cond.condition == EventCondition::DESTROY)
|
||||
{
|
||||
cond.condition = EventCondition::CONST_VALUE;
|
||||
cond.value = 1; // destroyed object, from now on always fulfilled
|
||||
}
|
||||
if (cond.condition == EventCondition::CONTROL)
|
||||
{
|
||||
cond.condition = EventCondition::CONST_VALUE;
|
||||
cond.value = 0; // destroyed object, from now on can not be fulfilled
|
||||
}
|
||||
}
|
||||
};
|
||||
event.trigger.forEach(patcher);
|
||||
}
|
||||
|
||||
gs->map->objects[id.getNum()].dellNull();
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,8 @@ struct DLL_LINKAGE EventCondition
|
||||
DAYS_PASSED, // value - number of days from start of the game
|
||||
IS_HUMAN, // value - 0 = player is AI, 1 = player is human
|
||||
DAYS_WITHOUT_TOWN, // value - how long player can live without town, 0=instakill
|
||||
STANDARD_WIN // normal defeat all enemies condition
|
||||
STANDARD_WIN, // normal defeat all enemies condition
|
||||
CONST_VALUE // condition that always evaluates to "value" (0 = false, 1 = true)
|
||||
};
|
||||
|
||||
EventCondition(EWinLoseType condition = STANDARD_WIN);
|
||||
|
@ -337,6 +337,17 @@ void CMapLoaderH3M::readVictoryLossConditions()
|
||||
bool allowNormalVictory = reader.readBool();
|
||||
bool appliesToAI = reader.readBool();
|
||||
|
||||
if (allowNormalVictory)
|
||||
{
|
||||
size_t playersOnMap = boost::range::count_if(mapHeader->players,[](const PlayerInfo & info) { return info.canAnyonePlay();});
|
||||
|
||||
if (playersOnMap == 1)
|
||||
{
|
||||
logGlobal->warnStream() << "Map " << mapHeader->name << " has only one player but allows normal victory?";
|
||||
allowNormalVictory = false; // makes sense? Not much. Works as H3? Yes!
|
||||
}
|
||||
}
|
||||
|
||||
switch(vicCondition)
|
||||
{
|
||||
case EVictoryConditionType::ARTIFACT:
|
||||
@ -1660,7 +1671,8 @@ void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number)
|
||||
count = reader.readUInt16();
|
||||
|
||||
// Empty slot
|
||||
if(creID == maxID) continue;
|
||||
if(creID == maxID)
|
||||
continue;
|
||||
|
||||
auto hlp = new CStackInstance();
|
||||
hlp->count = count;
|
||||
@ -1668,8 +1680,7 @@ void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number)
|
||||
if(creID > maxID - 0xf)
|
||||
{
|
||||
//this will happen when random object has random army
|
||||
creID = CreatureID(maxID + 1 - creID + VLC->creh->creatures.size());
|
||||
hlp->idRand = creID;
|
||||
hlp->idRand = maxID - creID - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -16,9 +16,9 @@
|
||||
#include "../VCMI_Lib.h"
|
||||
|
||||
static const std::string conditionNames[] = {
|
||||
"haveArtifact", "haveCreatures", "haveResources", "haveBuilding",
|
||||
"control", "destroy", "transport",
|
||||
"daysPassed", "isHuman", "daysWithoutTown", "standardWin"
|
||||
"haveArtifact", "haveCreatures", "haveResources", "haveBuilding",
|
||||
"control", "destroy", "transport", "daysPassed",
|
||||
"isHuman", "daysWithoutTown", "standardWin", "constValue"
|
||||
};
|
||||
|
||||
static const std::string typeNames[] = { "victory", "defeat" };
|
||||
|
Loading…
Reference in New Issue
Block a user