share/hedgewars/Data/Scripts/SimpleMission.lua
author Wuzzy <Wuzzy2@mail.ru>
Wed, 09 Oct 2019 18:08:37 +0200
changeset 15455 47cf2cf736e7
parent 15096 5c8c729a16ce
permissions -rw-r--r--
Remove toupper in CMakeLists.txt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     1
--[=[
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     2
= Simple Mission Framework for Hedgewars =
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     3
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     4
This is a simple library intended to make setting up simple missions an
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     5
easy task for Lua scripters. The entire game logic and coding is
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     6
abtracted away in a single function which you just need to feed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     7
a large definition table in which you define gears, goals, etc.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     8
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     9
This is ideal for missions in which you set up the entire scenario
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    10
from the start and don't need any complex in-mission events.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    11
BUT! This is NOT suited for missions with scripted events, cut-scenes,
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    12
branching story, etc.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    13
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    14
This library has the following features:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    15
* Add teams, clans, hogs
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    16
* Spawn gears
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    17
* Sensible defaults for almost everything
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    18
* Set custom goals or use the default one (kill all enemies)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    19
* Add non-goals to fail the mission
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    20
* Checks victory and failure automatically
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    21
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    22
To use this library, you first have to load it and to call SimpleMission once with
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    23
the appropriate parameters.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    24
See the comment of SimpleMission for a specification of all parameters.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    25
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    26
]=]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    27
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    28
HedgewarsScriptLoad("/Scripts/Locale.lua")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    29
HedgewarsScriptLoad("/Scripts/Tracker.lua")
14816
d65e25e211d4 Add integerSqrt and integerHypotenuse to Utils lib
Wuzzy <Wuzzy2@mail.ru>
parents: 14489
diff changeset
    30
HedgewarsScriptLoad("/Scripts/Utils.lua")
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    31
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    32
--[[
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    33
SimpleMission(params)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    34
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    35
This function sets up the *entire* mission and needs one argument: params.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    36
The argument “params” is a table containing fields which describe the mission.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    37
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    38
	Mandatory fields:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    39
	- teams:		Table of teams. There must be 1-8 teams.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    40
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    41
	Optional fields
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    42
	- ammoConfig		Table containing basic ammo values (default: infinite skip only)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    43
	- initVars		Table where you set up environment parameters such as MinesNum.
13066
8d2087c85b8d Fix incorrect wind bar in some missions
Wuzzy <Wuzzy2@mail.ru>
parents: 13064
diff changeset
    44
	- wind			If set, the wind will permanently set to this value (-100..100). Implies gfDisableWind
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    45
	- gears:		Table of objects.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    46
	- girders		Table of girders
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    47
	- rubbers		Table of rubbers
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    48
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    49
	AMMO
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    50
	- ammoType		ammo type
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    51
	- delay			delay (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    52
	- numberInCrate		ammo per crate (default: 1)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    53
	- count			default starter ammo for everyone, 9 for infinite (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    54
	- probability		probability in crates (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    55
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    56
	TEAM DATA
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    57
	- isMissionTeam		if true, this is the player's chosen team for this mission (default: false)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    58
	- hogs			table of hedgehogs in this team (must contain at least 1 hog)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    59
	- clanID		ID of the clan to which this team belongs to. Counting starts at 0.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    60
				By default, each team goes into its own clan.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    61
				Important: The clan of the player and allies MUST be 0.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    62
				Important: You MUST either set the clan ID explicitly for all teams or none of them.
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    63
	These arguments will be ignored if this is a mission team:
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    64
	- name			team name
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    65
	- flag			flag name (default: hedgewars)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    66
	- grave			grave name (has default grave for each team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    67
	- fort			fort name (default: Castle)
14937
ff4003a90ff8 Enable automatic voicepack language selection for all missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14936
diff changeset
    68
	- voice			voicepack (default: Default_qau)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    69
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    70
	HEDGEHOG DATA:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    71
	- id			optional identifier for goals
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    72
	- health		hog health (default: 100)
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    73
	- ammo			table of ammo types
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    74
	- x, y			hog position (default: spawns randomly on land)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    75
	- poisoned		if true, hedgehog starts poisoned with 5 poison damage. Set to a number for other poison damage (default: false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    76
	- frozen		if true, hedgehogs starts frozen (default: false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    77
	- faceLeft		initial facing direction. true=left, false=false (default: false)
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    78
	These arguments will be ignored if the hog is in a mission team:
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    79
	- name			hog name
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    80
	- botLevel		1-5: Bot level (lower=stronger). 0=human player (default: 0)
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
    81
	- hat			hat name (default: NoHat)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    82
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    83
	GEAR TYPES:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    84
	- type			gear type
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    85
	ALL types:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    86
		id		optional identifier for goals
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    87
		x		x coordinate of starting position (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    88
		y		y coordinate of starting position (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    89
		dx		initial x speed (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    90
		dy		initial y speed (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    91
	- type=gtMine		Mine
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    92
		timer 		Mine timer (only for non-duds). Default: MinesTime
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    93
		isDud		Whether the mine is a dud. default: false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    94
		isFrozen	Whether the mine is frozen. If true, it implies being a dud as well. Default: false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    95
		health 		Initial health of dud mines. Has no effect if isDud=false. Default: 36
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    96
	- type=gtSMine		Sticky mine
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    97
		timer		Timer. Default: 500
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    98
	- type=gtAirMine	Air mine
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    99
		timer		Timer. Default: (MinesTime/1000 * 250)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   100
	- type=gtExplosives	Barrel
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   101
		health		Initial health. Default: 60
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   102
		isFrozen	Whether the barrel is frozen. Default: true with health > 60, false otherwise
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   103
		isRolling	Whether the barrel starts in “rolling” state. Default: false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   104
	- type=gtCase		Crate
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   105
		crateType	"health": Health crate
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   106
				"supply": Ammo or utility crate (select crate type automatically)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   107
				"supply_ammo_explicit": Ammo crate (not recommened)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   108
				"supply_utility_explicit": Utility crate (not recommededn)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   109
		ammoType	Contained ammo (only for ammo and utility crates).
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   110
		health		Contained health (only for health crates). Default: HealthCaseAmount
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   111
		isFrozen	Whether the crate is frozen. Default: false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   112
	- type=gtKnife		Cleaver
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   113
	- type=gtTarget		Target
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   114
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   115
	GOALS:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   116
	Note: If there are at least two opposing teams, a default goal is used, which is to defeat all the enemies of the
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   117
	player's team. If this is what you want, you can skip this section.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   118
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   119
	The default goal is overwritten as if customGoals has been set. Set customGoals and other related parameters for
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   120
	defining your own special goals. In this case, the mission is won if all customGoals are completed.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   121
	Note the mission will always fail if the player's hedgehogs and all their allies have been defeated.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   122
	If there is only one team (for the player), there is no default goal and one must be set explicitly.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   123
	- customGoals		Table of custom goals (see below). All of them must be met to win. Some goal types might fail,
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   124
				rendering the mission unwinnable and leading to the loss of the mission. An example is
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   125
				blowing up a crate which you should have collected.ed.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   126
	- customNonGoals	Table of non-goals, the player loses if one of them is achieved
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   127
	- customGoalCheck	When to check goals and non-goals. Values: "instant" (default), "turnStart", "turnEnd"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   128
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   129
	- missionTitle:		The name of the mission (highly recommended)
13062
8b44518d1002 Convert Newton and the Hammock to SimpleMission format
Wuzzy <Wuzzy2@mail.ru>
parents: 13060
diff changeset
   130
	- missionIcon:		Icon of the mission panel, see documentation of ShowMission in the Lua API
13058
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   131
	- goalText:		A short string explaining the goal of the mission (use this if you set custom goals).
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   132
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   133
	GOAL TYPES:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   134
	- type			name of goal type
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   135
	- failText		Optional. For non-goals, this text will be shown in the stats if mission fails due to this non-goal
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   136
				being completed. For goals which fail, this text will be displayed at failure. Note that
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   137
				all normal goals have sensible default fail texts.
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   138
	- type="destroy"	Gear must be destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   139
		- id		Gear to destroy
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   140
	- type="teamDefeat"	Team must be defeated
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   141
		- teamName	Name of team to defeat
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   142
	- type="collect"	Crate must be collected
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   143
		FAIL CONDITION:	Crate taken by enemy, or destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   144
		- id		ID of crate gear to collect
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   145
		- collectors	Optional table of gear IDs, any one of which must collect the gear (but nobody else!).
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   146
				By default, this is for the player's teams and allies.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   147
	- type="turns"		Achieved when a number of turns has been played
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   148
		- turns 	Number of played turns 
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   149
	- type="rounds"		Achieved when a number of rounds has been played
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   150
		- rounds	Number of played rounds
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   151
	- type="suddenDeath"	Sudden Death has started
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   152
	- type="inZone"		A gear is within given coordinate bounds. Each of xMin, xMax, yMin and yMax is a sub-goal.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   153
				Each sub-goal is only checked if not nil.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   154
				You can use this to check if a gear left, right, above or below a given coordinate.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   155
				To check if the gear is within a rectangle, just set all 4 sub-goals.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   156
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   157
		- id		Gear to watch
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   158
		- xMin		gear's X coordinate must be lower than this
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   159
		- xMax		gear's X coordinate must be higher than this
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   160
		- yMin		gear's Y coordinate must be lower than this
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   161
		- yMax		gear's Y coordinate must be higher than this
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   162
	- type="distGearPos"	Distance between a gear and a fixed position
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   163
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   164
		- distance	goal distance to compare to
14818
828dad84b968 SimpleMission: Fix incorrect documentation for distGearGear and distGearPos
Wuzzy <Wuzzy2@mail.ru>
parents: 14817
diff changeset
   165
		- relationship	"greaterThan" or "smallerThan"
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   166
		- id		gear to watch
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   167
		- x		x coordinate to reach
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   168
		- y		y coordinate to reach
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   169
	- type="distGearGear"	Distance between two gears
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   170
		FAIL CONDITION:	Any of both gears destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   171
		- distance	goal distance to compare to
14818
828dad84b968 SimpleMission: Fix incorrect documentation for distGearGear and distGearPos
Wuzzy <Wuzzy2@mail.ru>
parents: 14817
diff changeset
   172
		- relationship	"greaterThan" or "smallerThan"
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   173
		- id1		first gear to compare
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   174
		- id2		second gear to compare
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   175
	- type="damage"		Gear took damage or was destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   176
		- id		Gear to watch
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   177
		- damage	Minimum amount of damage to take at a single blow. Default: 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   178
		- canDestroy	If false, this goal will fail if the gear was destroyed without taking the required damage
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   179
	- type="drown"		Gear has drowned
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   180
		FAIL CONDITION:	Gear destroyed by other means
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   181
		- id		Gear to watch
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   182
	- type="poison"		Gear must be poisoned
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   183
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   184
		- id		Gear to be poisoned
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   185
	- type="cure"		Gear must exist and be free from poisoning
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   186
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   187
		- id		Gear to check
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   188
	- type="freeze"		Gear must exist and be frozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   189
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   190
		- id		Gear to be frozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   191
	- type="melt"		Gear must exist and be unfrozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   192
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   193
		- id		Gear to check
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   194
	- type="waterSkip"	Gear must have skipped over water
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   195
		FAIL CONDITION:	Gear destroyed before it reached the required number of skips
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   196
		- id
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   197
		- skips		Total number of water skips required at least (default: 1)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   198
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   199
]]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   200
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   201
local goals
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   202
local teamHogs = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   203
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   204
--[[
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   205
	HELPER VARIABLES
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   206
]]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   207
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   208
local defaultGraves = {
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   209
	"Grave", "Statue", "pyramid", "Simple", "skull", "Badger", "Duck2", "Flower"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   210
}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   211
local defaultFlags = {
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   212
	"hedgewars", "cm_birdy", "cm_eyes", "cm_spider", "cm_kiwi", "cm_scout", "cm_skull", "cm_bars"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   213
}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   214
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   215
-- Utility functions
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   216
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   217
-- Returns value if it is non-nil, otherwise returns default
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   218
local function def(value, default)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   219
	if value == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   220
		return default
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   221
	else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   222
		return value
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   223
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   224
end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   225
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   226
local errord = false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   227
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   228
-- This function generates the mission. See above for the meaning of params.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   229
function SimpleMission(params)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   230
	if params.missionTitle == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   231
		params.missionTitle = loc("Scenario")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   232
	end
13062
8b44518d1002 Convert Newton and the Hammock to SimpleMission format
Wuzzy <Wuzzy2@mail.ru>
parents: 13060
diff changeset
   233
	if params.missionIcon == nil then
8b44518d1002 Convert Newton and the Hammock to SimpleMission format
Wuzzy <Wuzzy2@mail.ru>
parents: 13060
diff changeset
   234
		params.missionIcon = 1 -- target icon
8b44518d1002 Convert Newton and the Hammock to SimpleMission format
Wuzzy <Wuzzy2@mail.ru>
parents: 13060
diff changeset
   235
	end
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   236
	if params.goalText == nil then
13064
2f21d92eae27 Convert Nobody Laugh to SimpleMission format
Wuzzy <Wuzzy2@mail.ru>
parents: 13062
diff changeset
   237
		params.goalText = loc("Eliminate the enemy.")
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   238
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   239
	if params.customGoalCheck == nil and (params.customGoals ~= nil or params.customNonGoals ~= nil) then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   240
		params.customGoalCheck = "instant"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   241
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   242
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   243
	_G.sm = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   244
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   245
	_G.sm.isInSuddenDeath = false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   246
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   247
	-- Number of completed turns
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   248
	_G.sm.gameTurns = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   249
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   250
	_G.sm.goalGears = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   251
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   252
	_G.sm.params = params
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   253
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   254
	_G.sm.gameEnded = false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   255
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   256
	_G.sm.playerClan = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   257
14469
ead8928a59f8 Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14236
diff changeset
   258
	_G.sm.wonVarWritten = false
ead8928a59f8 Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14236
diff changeset
   259
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   260
	_G.sm.makeStats = function(winningClan, customAchievements)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   261
		for t=0, TeamsCount-1 do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   262
			local team = GetTeamName(t)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   263
			local stats = GetTeamStats(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   264
			local clan = GetTeamClan(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   265
			if clan == winningClan then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   266
				SendStat(siPlayerKills, stats.Kills, team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   267
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   268
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   269
		for t=0, TeamsCount-1 do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   270
			local team = GetTeamName(t)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   271
			local stats = GetTeamStats(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   272
			local clan = GetTeamClan(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   273
			if clan ~= winningClan then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   274
				SendStat(siPlayerKills, stats.Kills, team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   275
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   276
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   277
		if customAchievements ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   278
			for a=1, #customAchievements do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   279
				SendStat(siCustomAchievement, customAchievements[a])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   280
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   281
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   282
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   283
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   284
	_G.sm.criticalGearFailText = function(gearSmid)
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   285
		local gear = _G.sm.goalGears[gearSmid]
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   286
		if GetGearType(gear) == gtHedgehog then
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   287
			return string.format(loc("%s is dead, who was critical to this mission!"), GetHogName(gear))
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   288
		else
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   289
			return loc("We have lost an object which was critical to this mission.")
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   290
		end
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   291
	end
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   292
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   293
	_G.sm.checkGoal = function(goal)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   294
		if goal.type == "destroy" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   295
			return getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   296
		elseif goal.type == "collect" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   297
			local collector = getGearValue(_G.sm.goalGears[goal.id], "sm_collected")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   298
			if collector then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   299
				if not goal.collectors then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   300
					if GetHogClan(collector) == _G.sm.playerClan then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   301
						return true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   302
					else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   303
						-- Fail if the crate was collected by enemy
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   304
						return "fail", loc("The enemy has taken a crate which we really needed!")
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   305
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   306
				else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   307
					for c=1, #goal.collectors do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   308
						if _G.sm.goalGears[goal.collectors[c]] == collector then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   309
							return true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   310
						end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   311
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   312
					-- Fail if the crate was collected by someone who was not supposed to get it
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   313
					return "fail", loc("The wrong hedgehog has taken the crate.")
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   314
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   315
			else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   316
				-- Fail goal if crate was destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   317
				if getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   318
					return "fail", loc("A crate critical to this mission has been destroyed.")
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   319
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   320
				return false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   321
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   322
		elseif goal.type == "turns" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   323
			return sm.gameTurns >= goal.turns
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   324
		elseif goal.type == "rounds" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   325
			return (TotalRounds) >= goal.rounds
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   326
		elseif goal.type == "inZone" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   327
			if getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   328
				return "fail", _G.sm.criticalGearFailText(goal.id)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   329
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   330
			local gX, gY = GetGearPosition(_G.sm.goalGears[goal.id])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   331
			-- 4 sub-goals, each optional
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   332
			local g1 = (not goal.xMin) or gX >= goal.xMin
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   333
			local g2 = (not goal.xMax) or gX <= goal.xMax
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   334
			local g3 = (not goal.yMin) or gY >= goal.yMin
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   335
			local g4 = (not goal.yMax) or gY <= goal.yMax
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   336
			return g1 and g2 and g3 and g4
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   337
		elseif goal.type == "distGearPos" or goal.type == "distGearGear" then
14236
74bf2d906097 Turn accidental globals to locals in Lua libraries
Wuzzy <Wuzzy2@mail.ru>
parents: 13648
diff changeset
   338
			local gX, gY, tX, tY
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   339
			if goal.type == "distGearPos" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   340
				if getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   341
					-- Fail if gear was destroyed
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   342
					return "fail", _G.sm.criticalGearFailText(goal.id)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   343
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   344
				gX, gY = GetGearPosition(_G.sm.goalGears[goal.id])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   345
				tX, tY = goal.x, goal.y
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   346
			elseif goal.type == "distGearGear" then
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   347
				-- Fail if one of the gears was destroyed
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   348
				if getGearValue(_G.sm.goalGears[goal.id1], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   349
					return "fail", _G.sm.criticalGearFailText(goal.id1)
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   350
				elseif getGearValue(_G.sm.goalGears[goal.id2], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   351
					return "fail", _G.sm.criticalGearFailText(goal.id2)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   352
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   353
				gX, gY = GetGearPosition(_G.sm.goalGears[goal.id1])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   354
				tX, tY = GetGearPosition(_G.sm.goalGears[goal.id2])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   355
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   356
14816
d65e25e211d4 Add integerSqrt and integerHypotenuse to Utils lib
Wuzzy <Wuzzy2@mail.ru>
parents: 14489
diff changeset
   357
			local h = integerHypotenuse(gX - tX, gY - tY)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   358
			if goal.relationship == "smallerThan" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   359
				return h < goal.distance
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   360
			elseif goal.relationship == "greaterThan" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   361
				return h > goal.distance
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   362
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   363
			-- Invalid parameters!
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   364
			error("SimpleMission: Invalid parameters for distGearPos/distGearGear!")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   365
			errord = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   366
			return false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   367
		elseif goal.type == "suddenDeath" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   368
			return sm.isInSuddenDeath
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   369
		elseif goal.type == "damage" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   370
			local damage = goal.damage or 1
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   371
			local gear = _G.sm.goalGears[goal.id]
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   372
			local tookEnoughDamage = getGearValue(gear, "sm_maxDamage") >= damage
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   373
			if getGearValue(gear, "sm_destroyed") then
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   374
				-- Fail if gear was destroyed without taking enough damage first
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   375
				if not tookEnoughDamage and goal.canDestroy == false then
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   376
					if GetGearType(gear) == gtHedgehog then
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   377
						return "fail", string.format(loc("%s has been killed before taking enough damage first."), GetHogName(gear))
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   378
					else
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   379
						return "fail", loc("An object has been destroyed before it took enough damage.")
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   380
					end
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   381
				else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   382
				-- By default, succeed if gear was destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   383
					return true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   384
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   385
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   386
			return tookEnoughDamage
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   387
		elseif goal.type == "drown" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   388
			local drowned = getGearValue(_G.sm.goalGears[goal.id], "sm_drowned")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   389
			-- Fail if gear was destroyed by something other than drowning
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   390
			if not drowned and getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   391
				return "fail", _G.sm.criticalGearFailText(goal.id)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   392
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   393
			return drowned
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   394
		elseif goal.type == "poison" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   395
			if getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   396
				return "fail", _G.sm.criticalGearFailText(goal.id)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   397
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   398
			return GetEffect(_G.sm.goalGears[goal.id], hePoisoned) >= 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   399
		elseif goal.type == "freeze" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   400
			if getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   401
				return "fail", _G.sm.criticalGearFailText(goal.id)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   402
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   403
			return GetEffect(_G.sm.goalGears[goal.id], heFrozen) >= 256
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   404
		elseif goal.type == "cure" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   405
			if getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   406
				return "fail", _G.sm.criticalGearFailText(goal.id)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   407
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   408
			return GetEffect(_G.sm.goalGears[goal.id], hePoisoned) == 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   409
		elseif goal.type == "melt" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   410
			if getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   411
				return "fail", _G.sm.criticalGearFailText(goal.id)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   412
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   413
			return GetEffect(_G.sm.goalGears[goal.id], heFrozen) == 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   414
		elseif goal.type == "waterSkip" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   415
			local skips = goal.skips or 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   416
			local hasEnoughSkips = getGearValue(_G.sm.goalGears[goal.id], "sm_waterSkips") >= skips
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   417
			-- Fail if gear was destroyed before it got the required number of skips
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   418
			if not hasEnoughSkips and getGearValue(_G.sm.goalGears[goal.id], "sm_destroyed") then
14817
16d5951d4044 SimpleMission: Fix Lua error spam when a goal fails
Wuzzy <Wuzzy2@mail.ru>
parents: 14816
diff changeset
   419
				return "fail", _G.sm.criticalGearFailText(goal.id)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   420
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   421
			return hasEnoughSkips
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   422
		elseif goal.type == "teamDefeat" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   423
			return #teamHogs[goal.teamName] == 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   424
		else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   425
			return false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   426
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   427
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   428
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   429
	--[[ Checks the custom goals.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   430
	Returns true when all custom goals are met.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   431
	Returns false when not all custom goals are met.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   432
	Returns "fail" if any of the goals has failed (i.e. is impossible to complete).
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   433
	Returns nil when there are no custom goals ]]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   434
	_G.sm.checkGoals = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   435
		if params.customGoals ~= nil and #params.customGoals > 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   436
			for key, goal in pairs(params.customGoals) do
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   437
				local done, defaultFailText = _G.sm.checkGoal(goal)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   438
				if done == false or done == "fail" then
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   439
					local failText
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   440
					if goal.failText then
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   441
						failText = goal.failText
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   442
					else
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   443
						failText = customFailText
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   444
					end
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   445
					return done, failText
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   446
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   447
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   448
			return true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   449
		else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   450
			return nil
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   451
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   452
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   453
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   454
	--[[ Checks the custom non-goals.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   455
	Returns true when any non-goal is met.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   456
	Returns false otherwise. ]]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   457
	_G.sm.checkNonGoals = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   458
		if params.customNonGoals ~= nil and #params.customNonGoals > 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   459
			for key, nonGoal in pairs(params.customNonGoals) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   460
				local done = _G.sm.checkGoal(nonGoal)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   461
				if done == true then
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   462
					return true, nonGoal.failText
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   463
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   464
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   465
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   466
		return false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   467
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   468
13058
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   469
	-- Declare the game ended if all enemy teams are dead and player teams or allies are still alive
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   470
	_G.sm.checkRegularVictory = function()
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   471
		local victory = true
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   472
		for t=0, TeamsCount-1 do
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   473
			local team = GetTeamName(t)
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   474
			local defeat = _G.sm.checkGoal({type="teamDefeat", teamName=team})
13060
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   475
			if not defeat then
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   476
				-- Deep check, also look at damage of all hogs
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   477
				local dead = 0
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   478
				for h=1, #teamHogs[team] do
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   479
					local _,_,_,_,_,_,_,_,_,_,_,Damage = GetGearValues(teamHogs[team][h])
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   480
					if Damage >= GetHealth(teamHogs[team][h]) then
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   481
						dead = dead + 1
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   482
					end
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   483
				end
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   484
				if dead >= #teamHogs[team] then
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   485
					defeat = true
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   486
				end
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   487
			end
13058
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   488
			if (defeat == true) and (GetTeamClan(team) == _G.sm.playerClan) then
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   489
				victory = false
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   490
				break
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   491
			elseif (defeat == false) and (GetTeamClan(team) ~= _G.sm.playerClan) then
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   492
				victory = false
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   493
				break
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   494
			end
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   495
		end
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   496
		if victory then
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   497
			_G.sm.gameEnded = true
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   498
		end
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   499
	end
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13054
diff changeset
   500
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   501
	-- Checks goals and non goals and wins or loses mission
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   502
	_G.sm.checkWinOrFail = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   503
		if errord then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   504
			return
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   505
		end
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   506
		local nonGoalStatus, nonGoalFailText = _G.sm.checkNonGoals()
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   507
		local goalStatus, goalFailText = _G.sm.checkGoals()
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   508
		if nonGoalStatus == true then
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   509
			_G.sm.lose(nonGoalFailText)
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   510
		elseif goalStatus == "fail" then
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   511
			_G.sm.lose(goalText)
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   512
		elseif goalStatus == true then
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   513
			_G.sm.win()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   514
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   515
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   516
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   517
	_G.sm.win = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   518
		if not _G.sm.gameEnded then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   519
			_G.sm.gameEnded = true
14469
ead8928a59f8 Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14236
diff changeset
   520
			if not _G.sm.wonVarWritten then
ead8928a59f8 Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14236
diff changeset
   521
				SaveMissionVar("Won", "true")
ead8928a59f8 Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14236
diff changeset
   522
				_G.sm.wonVarWritten = true
ead8928a59f8 Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14236
diff changeset
   523
			end
13648
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13592
diff changeset
   524
			AddCaption(loc("Victory!"), capcolDefault, capgrpGameState)
15096
5c8c729a16ce Scenarios: Show "Mission succeeded/failed!" in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 14937
diff changeset
   525
			SendStat(siGameResult, loc("Mission succeeded!"))
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   526
			_G.sm.makeStats(_G.sm.playerClan)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   527
			EndGame()
14933
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14818
diff changeset
   528
			if GetHogLevel(CurrentHedgehog) == 0 then
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14818
diff changeset
   529
				for team, hog in pairs(teamHogs[GetHogTeamName(CurrentHedgehog)]) do
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14818
diff changeset
   530
					SetState(hog, gstWinner)
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14818
diff changeset
   531
					PlaySound(sndVictory, hog)
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14818
diff changeset
   532
				end
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14818
diff changeset
   533
			end
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   534
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   535
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   536
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   537
	_G.sm.lose = function(failReason)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   538
		if not _G.sm.gameEnded then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   539
			_G.sm.gameEnded = true
15096
5c8c729a16ce Scenarios: Show "Mission succeeded/failed!" in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 14937
diff changeset
   540
			AddCaption(loc("Mission failed!"), capcolDefault, capgrpGameState)
5c8c729a16ce Scenarios: Show "Mission succeeded/failed!" in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 14937
diff changeset
   541
			SendStat(siGameResult, loc("Mission failed!"))
13059
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   542
			if failReason then
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   543
				SendStat(siCustomAchievement, failReason)
2d0f3e12fcad SimpleMission: Add support for failure texts in the stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13058
diff changeset
   544
			end
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   545
			if GetHogLevel(CurrentHedgehog) == 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   546
				SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstLoser))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   547
				SetState(CurrentHedgehog, band(GetState(CurrentHedgehog), bnot(gstHHDriven)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   548
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   549
			local clan = ClansCount-1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   550
			for t=0, TeamsCount-1 do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   551
				local team = GetTeamName(t)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   552
				-- Just declare any living team other than the player team the winner
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   553
				if (_G.sm.checkGoal({type="teamDefeat", teamName=team}) == false) and (GetTeamClan(team) ~= _G.sm.playerClan) then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   554
					clan = GetTeamClan(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   555
					break
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   556
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   557
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   558
			_G.sm.makeStats(clan)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   559
			EndGame()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   560
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   561
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   562
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   563
	_G.onSuddenDeath = function()
14236
74bf2d906097 Turn accidental globals to locals in Lua libraries
Wuzzy <Wuzzy2@mail.ru>
parents: 13648
diff changeset
   564
		_G.sm.isInSuddenDeath = true
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   565
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   566
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   567
	_G.onGearWaterSkip = function(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   568
		increaseGearValue(gear, "sm_waterSkips")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   569
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   570
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   571
	_G.onGearAdd = function(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   572
		if GetGearType(gear) == gtHedgehog then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   573
			local team = GetHogTeamName(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   574
			if teamHogs[team] == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   575
				teamHogs[team] = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   576
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   577
			table.insert(teamHogs[GetHogTeamName(gear)], gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   578
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   579
		setGearValue(gear, "sm_waterSkips", 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   580
		setGearValue(gear, "sm_maxDamage", 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   581
		setGearValue(gear, "sm_drowned", false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   582
		setGearValue(gear, "sm_destroyed", false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   583
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   584
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   585
	_G.onGearResurrect = function(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   586
		if GetGearType(gear) == gtHedgehog then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   587
			table.insert(teamHogs[GetHogTeamName(gear)], gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   588
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   589
		setGearValue(gear, "sm_destroyed", false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   590
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   591
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   592
	_G.onGearDelete = function(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   593
		if GetGearType(gear) == gtCase and band(GetGearMessage(gear), gmDestroy) ~= 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   594
			-- Set ID of collector
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   595
			setGearValue(gear, "sm_collected", CurrentHedgehog)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   596
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   597
		if GetGearType(gear) == gtHedgehog then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   598
			local team = GetHogTeamName(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   599
			local hogList = teamHogs[team]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   600
			for h=1, #hogList do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   601
				if hogList[h] == gear then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   602
					table.remove(hogList, h)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   603
					break
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   604
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   605
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   606
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   607
		if band(GetState(gear), gstDrowning) ~= 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   608
			setGearValue(gear, "sm_drowned", true)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   609
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   610
		setGearValue(gear, "sm_destroyed", true)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   611
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   612
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   613
	_G.onGearDamage = function(gear, damage)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   614
		local currentDamage = getGearValue(gear, "sm_maxDamage")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   615
		if damage > currentDamage then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   616
			setGearValue(gear, "sm_maxDamage", damage)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   617
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   618
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   619
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   620
	_G.onGameInit = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   621
		CaseFreq = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   622
		WaterRise = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   623
		HealthDecrease = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   624
		MinesNum = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   625
		Explosives = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   626
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   627
		for initVarName, initVarValue in pairs(params.initVars) do
13592
818134c33f54 Fix SimpleMission failure to init GameFlags correctly
Wuzzy <Wuzzy2@mail.ru>
parents: 13588
diff changeset
   628
			if initVarName == "GameFlags" then
13105
61076bb26cb3 SimpleMission: Set GameFlags more cleanly
Wuzzy <Wuzzy2@mail.ru>
parents: 13066
diff changeset
   629
				EnableGameFlags(initVarValue)
61076bb26cb3 SimpleMission: Set GameFlags more cleanly
Wuzzy <Wuzzy2@mail.ru>
parents: 13066
diff changeset
   630
			else
61076bb26cb3 SimpleMission: Set GameFlags more cleanly
Wuzzy <Wuzzy2@mail.ru>
parents: 13066
diff changeset
   631
				_G[initVarName] = initVarValue
61076bb26cb3 SimpleMission: Set GameFlags more cleanly
Wuzzy <Wuzzy2@mail.ru>
parents: 13066
diff changeset
   632
			end
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   633
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   634
		if #params.teams == 1 then
13105
61076bb26cb3 SimpleMission: Set GameFlags more cleanly
Wuzzy <Wuzzy2@mail.ru>
parents: 13066
diff changeset
   635
			EnableGameFlags(gfOneClanMode)
13066
8d2087c85b8d Fix incorrect wind bar in some missions
Wuzzy <Wuzzy2@mail.ru>
parents: 13064
diff changeset
   636
		end
8d2087c85b8d Fix incorrect wind bar in some missions
Wuzzy <Wuzzy2@mail.ru>
parents: 13064
diff changeset
   637
		if params.wind then
13105
61076bb26cb3 SimpleMission: Set GameFlags more cleanly
Wuzzy <Wuzzy2@mail.ru>
parents: 13066
diff changeset
   638
			EnableGameFlags(gfDisableWind)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   639
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   640
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   641
		local clanCounter = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   642
		for teamID, teamData in pairs(params.teams) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   643
			local name, clanID, grave, fort, voice, flag
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   644
			name = def(teamData.name, string.format(loc("Team %d"), teamID))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   645
			if teamData.clanID == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   646
				clanID = clanCounter
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   647
				clanCounter = clanCounter + 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   648
			else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   649
				clanID = teamData.clanID
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   650
			end
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   651
14489
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   652
			local realName
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   653
			if teamData.isMissionTeam then
14489
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   654
				realName = AddMissionTeam(-(clanID+1))
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   655
				_G.sm.playerClan = clanID
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   656
			else
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   657
				grave = def(teamData.grave, defaultGraves[math.min(teamID, 8)])
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   658
				fort = def(teamData.fort, "Castle")
14936
ba5fd934f49b Don't agressively select voicepack language automatically, must be now enabled explicitly with _qau suffix
Wuzzy <Wuzzy2@mail.ru>
parents: 14933
diff changeset
   659
				voice = def(teamData.voice, "Default_qau")
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   660
				flag = def(teamData.flag, defaultFlags[math.min(teamID, 8)])
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   661
14489
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   662
				realName = AddTeam(name, -(clanID+1), grave, fort, voice, flag)
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   663
			end
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   664
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   665
			-- Update all teamDefeat goals if the real team name differs from the
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   666
			-- team configuration.
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   667
			-- (AddTeam might change the name due to naming collisions)
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   668
			if name ~= realName then
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   669
				local checks = { params.customGoals, params.customNonGoals }
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   670
				for c=1, 2 do
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   671
					if checks[c] then
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   672
						for k,goal in pairs(checks[c]) do
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   673
							if goal.type == "teamDefeat" and goal.teamName == name then
764ba6182389 Change AddTeam/AddMissionTeam to return real team name and index (in that order)
Wuzzy <Wuzzy2@mail.ru>
parents: 14488
diff changeset
   674
								goal.teamName = realName
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   675
							end
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   676
						end
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   677
					end
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   678
				end
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   679
			end
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   680
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   681
			for hogID, hogData in pairs(teamData.hogs) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   682
				local name, botLevel, health, hat
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   683
				name = def(hogData.name, string.format(loc("Hog %d"), hogID))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   684
				botLevel = def(hogData.botLevel, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   685
				health = def(hogData.health, 100)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   686
				hat = def(hogData.hat, "NoHat")
14488
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   687
				local hog
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   688
				if teamData.isMissionTeam then
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   689
					hog = AddMissionHog(health)
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   690
				else
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   691
					hog = AddHog(name, botLevel, health, hat)
310b167141cc Use player's team identity for SimpleMission-based mission
Wuzzy <Wuzzy2@mail.ru>
parents: 14471
diff changeset
   692
				end
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   693
				if hogData.x ~= nil and hogData.y ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   694
					SetGearPosition(hog, hogData.x, hogData.y)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   695
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   696
				if hogData.faceLeft then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   697
					HogTurnLeft(hog, true)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   698
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   699
				if hogData.poisoned == true then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   700
					SetEffect(hog, hePoisoned, 5)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   701
				elseif type(hogData.poisoned) == "number" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   702
					SetEffect(hog, hePoisoned, hogData.poisoned)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   703
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   704
				if hogData.frozen then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   705
					SetEffect(hog, heFrozen, 199999)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   706
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   707
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   708
				if hog ~= nil and hogData.id ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   709
					_G.sm.goalGears[hogData.id] = hog
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   710
					setGearValue(hog, "sm_id", hogData.id)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   711
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   712
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   713
				-- Remember this hedgehog's gear ID for later use
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   714
				hogData.gearID = hog
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   715
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   716
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   717
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   718
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   719
	_G.onNewTurn = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   720
		_G.sm.gameStarted = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   721
14471
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   722
		if params.customGoalCheck == "turnStart" then
13060
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   723
			_G.sm.checkRegularVictory()
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   724
			_G.sm.checkWinOrFail()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   725
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   726
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   727
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   728
	_G.onEndTurn = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   729
		_G.sm.gameTurns = _G.sm.gameTurns + 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   730
14471
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   731
		if params.customGoalCheck == "turnEnd" then
13060
5ceb8b0632c4 SimpleMission: Check regular victory at turn and or start
Wuzzy <Wuzzy2@mail.ru>
parents: 13059
diff changeset
   732
			_G.sm.checkRegularVictory()
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   733
			_G.sm.checkWinOrFail()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   734
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   735
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   736
14471
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   737
	_G.onGameResult = function(winningClan)
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   738
		if (params.customGoals == nil) and (not _G.sm.wonVarWritten) and (winningClan == _G.sm.playerClan) then
15096
5c8c729a16ce Scenarios: Show "Mission succeeded/failed!" in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 14937
diff changeset
   739
			SendStat(siGameResult, loc("Mission succeeded!"))
14471
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   740
			SaveMissionVar("Won", "true")
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   741
			_G.sm.wonVarWritten = true
15096
5c8c729a16ce Scenarios: Show "Mission succeeded/failed!" in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 14937
diff changeset
   742
		else
5c8c729a16ce Scenarios: Show "Mission succeeded/failed!" in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 14937
diff changeset
   743
			SendStat(siGameResult, loc("Mission failed!"))
14471
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   744
		end
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   745
	end
734a7af2dfc2 Fix victory check of a few scenarios
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   746
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   747
	_G.onAmmoStoreInit = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   748
		local ammoTypesDone = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   749
		-- Read script's stated ammo wishes
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   750
		if params.ammoConfig ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   751
			for ammoType, v in pairs(params.ammoConfig) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   752
				SetAmmo(ammoType, def(v.count, 0), def(v.probability, 0), def(v.delay, 0), def(v.numberInCrate, 1))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   753
				ammoTypesDone[ammoType] = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   754
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   755
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   756
		-- Apply default values for all ammo types which have not been set
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   757
		for a=0, AmmoTypeMax do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   758
			if a ~= amNothing and ammoTypesDone[a] ~= true then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   759
				local count = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   760
				if a == amSkip then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   761
					count = 9
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   762
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   763
				SetAmmo(a, count, 0, 0, 1)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   764
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   765
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   766
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   767
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   768
	_G.onGameStart = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   769
		-- Mention mines timer
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   770
		if MinesTime ~= 3000 and MinesTime ~= nil then 
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   771
			if MinesTime < 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   772
				params.goalText = params.goalText .. "|" .. loc("Mines time: 0s-5s")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   773
			elseif (MinesTime % 1000) == 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   774
				params.goalText = params.goalText .. "|" .. string.format(loc("Mines time: %ds"), MinesTime/1000)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   775
			elseif (MinesTime % 100) == 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   776
				params.goalText = params.goalText .. "|" .. string.format(loc("Mines time: %.1fs"), MinesTime/1000)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   777
			else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   778
				params.goalText = params.goalText .. "|" .. string.format(loc("Mines time: %.2fs"), MinesTime/1000)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   779
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   780
		end
13066
8d2087c85b8d Fix incorrect wind bar in some missions
Wuzzy <Wuzzy2@mail.ru>
parents: 13064
diff changeset
   781
		if params.wind then
8d2087c85b8d Fix incorrect wind bar in some missions
Wuzzy <Wuzzy2@mail.ru>
parents: 13064
diff changeset
   782
			SetWind(params.wind)
8d2087c85b8d Fix incorrect wind bar in some missions
Wuzzy <Wuzzy2@mail.ru>
parents: 13064
diff changeset
   783
		end
13062
8b44518d1002 Convert Newton and the Hammock to SimpleMission format
Wuzzy <Wuzzy2@mail.ru>
parents: 13060
diff changeset
   784
		ShowMission(params.missionTitle, loc("Scenario"), params.goalText, params.missionIcon, 5000) 
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   785
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   786
		-- Spawn objects
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   787
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   788
		if params.gears ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   789
			for listGearID, gv in pairs(params.gears) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   790
				local timer, state, x, y, dx, dy
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   791
				local g
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   792
				state = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   793
				if gv.type == gtMine then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   794
					if gv.isFrozen then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   795
						state = gstFrozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   796
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   797
					g = AddGear(def(gv.x,0), def(gv.y,0), gv.type, state, def(gv.dx, 0), def(gv.dy, 0), def(gv.timer, MinesTime))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   798
					if gv.isDud then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   799
						SetHealth(g, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   800
						if gv.health ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   801
							SetGearValues(g, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 36 - gv.health)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   802
						end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   803
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   804
				elseif gv.type == gtSMine then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   805
					g = AddGear(def(gv.x,0), def(gv.y,0), gv.type, 0, def(gv.dx,0), def(gv.dy,0), def(gv.timer, 500))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   806
				elseif gv.type == gtAirMine then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   807
					if gv.isFrozen then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   808
						state = gstFrozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   809
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   810
					local timer = def(gv.timer, div(MinesTime, 1000) * 250)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   811
					g = AddGear(def(gv.x,0), def(gv.y,0), gv.type, state, def(gv.dx,0), def(gv.dy,0), timer)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   812
					SetGearValues(g, nil, nil, timer) -- WDTimer
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   813
				elseif gv.type == gtExplosives then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   814
					if gv.isRolling then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   815
						state = gsttmpFlag
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   816
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   817
					g = AddGear(def(gv.x,0), def(gv.y,0), gv.type, state, def(gv.dx,0), def(gv.dy,0), 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   818
					if gv.health then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   819
						SetHealth(g, gv.health)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   820
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   821
					if gv.isFrozen ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   822
						if gv.isFrozen == true then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   823
							SetState(g, bor(GetState(g, gstFrozen)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   824
						end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   825
					elseif GetHealth(g) > 60 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   826
						SetState(g, bor(GetState(g, gstFrozen)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   827
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   828
				elseif gv.type == gtCase then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   829
					local x, y, spawnTrick
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   830
					spawnTrick = false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   831
					x = def(gv.x, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   832
					y = def(gv.y, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   833
					if x==0 and y==0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   834
						x=1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   835
						y=1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   836
						spawnTrick = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   837
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   838
					g = AddGear(x, y, gv.type, 0, def(gv.dx,0), def(gv.dy,0), 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   839
					if spawnTrick then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   840
						SetGearPosition(g, 0, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   841
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   842
					if gv.crateType == "supply" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   843
						g = SpawnSupplyCrate(def(gv.x, 0), def(gv.y, 0), gv.ammoType)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   844
					elseif gv.crateType == "supply_ammo_explicit" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   845
						g = SpawnAmmoCrate(def(gv.x, 0), def(gv.y, 0), gv.ammoType)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   846
					elseif gv.crateType == "supply_utility_explicit" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   847
						g = SpawnUtilityCrate(def(gv.x, 0), def(gv.y, 0), gv.ammoType)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   848
					elseif gv.crateType == "health" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   849
						g = SpawnHealthCrate(def(gv.x, 0), def(gv.y, 0))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   850
						if gv.health ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   851
							SetHealth(g, gv.health)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   852
						end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   853
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   854
					if gv.isFrozen then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   855
						SetState(g, bor(GetState(g, gstFrozen)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   856
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   857
				elseif gv.type == gtKnife or gv.type == gtTarget then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   858
					g = AddGear(def(gv.x,0), def(gv.y,0), gv.type, 0, def(gv.dx,0), def(gv.dy,0), 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   859
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   860
				if g ~= nil and gv.id ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   861
					_G.sm.goalGears[gv.id] = g
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   862
					setGearValue(g, "sm_id", gv.id)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   863
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   864
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   865
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   866
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   867
		-- Spawn girders and rubbers
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   868
		if params.girders ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   869
			for i, girderData in pairs(params.girders) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   870
				PlaceGirder(girderData.x, girderData.y, girderData.frameIdx)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   871
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   872
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   873
		if params.rubbers ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   874
			for i, rubberData in pairs(params.rubbers) do
13648
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13592
diff changeset
   875
				PlaceSprite(rubberData.x, rubberData.y, sprAmRubber, capcolDefault, rubberData.frameIdx, false, false, false, lfBouncy)
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   876
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   877
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   878
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   879
		-- Per-hedgehog ammo loadouts
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   880
		for teamID, teamData in pairs(params.teams) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   881
			for hogID, hogData in pairs(teamData.hogs) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   882
				if hogData.ammo ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   883
					for ammoType, count in pairs(hogData.ammo) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   884
						AddAmmo(hogData.gearID, ammoType, count)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   885
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   886
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   887
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   888
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   889
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   890
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   891
	_G.onGameTick20 = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   892
		if params.customGoalCheck == "instant" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   893
			_G.sm.checkWinOrFail()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   894
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   895
	end
13066
8d2087c85b8d Fix incorrect wind bar in some missions
Wuzzy <Wuzzy2@mail.ru>
parents: 13064
diff changeset
   896
13054
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   897
end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   898