User:Ivan/Victory conditions

From VCMI Project Wiki
< User:Ivan
Revision as of 11:10, 29 December 2013 by Ivan (talk | contribs) (List of victory/loss objectives)
Jump to: navigation, search

Main ideas

  • Use logical expressions to allow construction of complex conditions out of simple ones
  • Keep "logical expression" part generic enough to allow its usage in other areas (e.g. requirements for town buildings or any other allow/deny triggers)
  • Merge victory conditions with lose conditions - "do not lose hero" can be turned into more generic "control object(hero ID)" and "capture town" into more generic "control object(town ID)"
  • Json format so it can be used in future with map editor/json map format

Format considerarions

Why I prefer this format (see next section) over others:

  • I'm using prefix notation here to reduce probability of errors and to avoid thinking about operations priority which may be needed in case of mixing "or" with "and" in one expression:
"victory" :
[
    "conditionA",
    "and"         // this can be evaluated first
    "conditionB"
    "or"          // or this one
    "conditionC"
]
  • Json Vectors are used almost everywhere since json does not allows values with equal keys. Something like this is more logical but is not a valid json code:
"victory" :
{
    "allOf" :
    {
        "control" : { "position" : [0, 0, 0] }, // don't lose hero 1
        "control" : { "position" : [1, 1, 1] }, // don't lost hero 2
    }
}

Standard conditions:

"victory" :
[
    "standardWin"
],
"lose" :
[
    "daysWithoutTown", { "value" : 7 }
]

Current format

Map header format

// Text for victory conditions on map selection screen.
"victoryString" : "Defeat all enemies or find artifact",
// Icon, indicates index of frame in SCNRVICT.DEF file
"victoryIconIndex" : 12,

// Text for defeat conditions on map selection screen.
"defeatString" : "Lose your capital Steadwick or your hero Roland",
// Icon, indicates index of frame in SCNRLOSS.DEF file
"defeatIconIndex" : 1,

// list of triggered events that denote computer-readable victory/defeat conditions
"triggeredEvents" : { <list of triggered events, see below> }

Triggered events format

// Unique identifier of an event
"findTheBlade" :
{
	// Logical condition for this event to trigger, see below
	"condition" : [ "logical expression code" ],

	// TODO: Long description of this event/quest, will be displayed in quest window
	"description" : "Find ancient artifact, Armageddon's Blade to claim victory!",

	// Message that will be displayed to player that have triggered this event
	"message" : "You have found Armageddon's Blade. You won!",

	// Effect caused by this event, right now only win/loss effects are supported
	"effect" :
	{
		// Type of effect, can be either "victory" or "defeat"
		"type" : "victory",

		// Message that will be send to the rest of players to explain what happened
		"messageToSend" : "Enemy found AB. All is lost!"
	}
}

Logical conditions

Logical conditions for map events use same base system as buidings but with different base element

"condition"
[
    // To fulfill, all of below must be true
    "allOf",
    // 1) Have 100'000 gold
    [ "haveResources", { "type" : "resource.gold", "value" : 100000 }],
    // 2) 60 days have not passed since game start (aka time expires loss condition)
    [
      "noneOf",
      [ "daysPassed", { "value" : 60 } ]
    ],
    // 3) Player must control at least one of towns at positions specified below
    [
      "anyOf"
      [ "control", { "position" : [ 1, 4,0], "type" : "object.town" } ],
      [ "control", { "position" : [10,25,0], "type" : "object.town" } ]
    ]
]

Possible improvements to triggered events

  • Expand effects to cover all possibilities of Seer Huts/Town events/Timed map events
  • Add fields like "affected players" and "cooldown duration" similar to timed map events
  • Use it to "patch" map to fix remaining campaign issues like Mantis 1635
  • Possibility of multiple effects triggered by the same event
  • Some way to implement "7 days without town" as "7 days since event "no owned towns" triggered"

List of victory/loss objectives

List of objectives that I have at the moment. Unless I missed something, should fully cover H3 objectives including campaigns

HAVE_ARTIFACT

Any player hero must hold an artifact

  • position - N/A (TODO: hero that must obtain the artifact? Or even merge this with "transport"?)
  • type - required artifact ID
  • value - N/A

HAVE_CREATURES

Player must control certain number of creatures

  • position - N/A
  • type - creature ID to collect
  • value - required amount of creatures

HAVE_RESOURCES

Player must have certain amount of resources

  • position - N/A
  • type - resource ID
  • value - required amount of resource

HAVE_BUILDING

Player must control certain building, also includes H3 "build Grail" condition

  • position - town in which this structure must be built, optional
  • type - building ID to construct
  • value - N/A

Note: if position is not set - building can be built in any town

CONTROL

Covers all conditions that require certain object(s) to be controlled by player

  • position - position of object to control, optional
  • type - type of object to control.
  • value - N/A

Note: If position is not set - all objects of this type must be captured

DESTROY

Covers objections where player must destroy certain object(s)

  • position - position of object to destroy, optional
  • type - type of object to destroy
  • value - N/A

Note: If position is not set - all objects of this type must be destroyed

TRANSPORT

Transport artifact in certain town

  • position - town to which this artifact must be transported
  • type - artifact ID to transport
  • value - N/A

DAYS_PASSED

Player must survive or win in certain number of days

  • position - N/A
  • type - N/A
  • value - number of days for this objective to trigger

Note: covers both "win in X days" as well as "survive for X days" conditions, depending on block in which this objective will be placed.

IS_HUMAN

Helper condition to allow ai-only or human-only conditions

  • position - N/A
  • type - N/A
  • value - 0 will trigger this objective for AI players, 1 will trigger it for humans

STANDARD_WIN

Standard win condition - defeat all enemies

  • position - N/A
  • type - N/A
  • value - N/A

DAYS_WITHOUT_TOWN

Standard lose condition - stay for X days without towns

  • position - N/A
  • type - N/A
  • value - number of days to survive, 0 = player dies on the next day.

Note: another part of standard lose condition - no heroes/towns is hardcoded.

Possible additions

  • Player color test - to allow player-specific conditions. May not be the best place for this
  • Constant - condition that always evaluates to true or false. Not sure if necessary.

Other areas for logic expressions

Mod dependencies

Not really necessary right now but it is possible to use them to specify more complex set of dependencies, e.g.

"requirements" :
[
    "allOf",
    [ "modA" ],  // "normal" dependencies - this mod requires mod A
    [
        "modB",  // dependencies with specific version limitations
        { "minimum" : "1.0.1", "maximum" : "1.2.9" }
    ],
    [
        "anyOf"  // at least one mod out of this list should be installed
        [ "modC" ],
        [ "modD" ]
    ],
    [
        "noneOf",  // essentially list of conflicts - none of these mods should be present
        [ "modE" ]
    ]
]

Building requirements

Already implemented in code

Something that was requested quite often, usually as part of alternative creatures in towns feature. Should be simple to implement compared to "main" area - campaigns. Will probably try to do this area first due to its small scale (less chance to mess up bigger systems).

Format is pretty much same as in previous cases:

"requirements" :
[
    "allOf", // Normal H3 "build all" mode
    [ "mageGuild1" ],
    [
        "noneOf",  // available only if dwelling 5 "A" was not built
        [ "dwelling5A" ],
        [ "dwelling5AUpgrade" ]
    ],
    [
        "anyOf", // at least one must be built
        [ "tavern" ],
        [ "blacksmith" ]
    ]
]