share/hedgewars/Data/Scripts/SimpleMission.lua
author Wuzzy <Wuzzy2@mail.ru>
Wed, 21 Feb 2018 22:43:03 +0100
changeset 13053 8b42562dcada
parent 13049 f18cefc4309d
child 13054 2d0f3e12fcad
permissions -rw-r--r--
SimpleMission: Check regular victory before anything else
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13049
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")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    30
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
SimpleMission(params)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    33
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    34
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
    35
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
    36
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    37
	Mandatory fields:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    38
	- 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
    39
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    40
	Optional fields
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    41
	- 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
    42
	- initVars		Table where you set up environment parameters such as MinesNum.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    43
	- wind			If set, the wind will permanently set to this value (-100..100)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    44
	- gears:		Table of objects.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    45
	- girders		Table of girders
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    46
	- rubbers		Table of rubbers
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    47
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    48
	AMMO
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    49
	- ammoType		ammo type
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    50
	- delay			delay (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    51
	- numberInCrate		ammo per crate (default: 1)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    52
	- 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
    53
	- probability		probability in crates (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    54
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    55
	TEAM DATA
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    56
	- 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
    57
	- name			team name
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    58
	- 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
    59
				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
    60
				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
    61
				Important: You MUST either set the clan ID explicitly for all teams or none of them.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    62
	- flag			flag name (default: hedgewars)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    63
	- 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
    64
	- fort			fort name (default: Castle)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    65
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    66
	HEDGEHOG DATA:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    67
	- id			optional identifier for goals
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    68
	- name			hog name
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    69
	- 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
    70
	- botLevel		1-5: Bot level (lower=stronger). 0=human player (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    71
	- hat			hat name (default: NoHat)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    72
	- health		hog health (default: 100)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    73
	- 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
    74
	- frozen		if true, hedgehogs starts frozen (default: false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    75
	- faceLeft		initial facing direction. true=left, false=false (default: false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    76
	- ammo			table of ammo types
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    77
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    78
	GEAR TYPES:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    79
	- type			gear type
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    80
	ALL types:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    81
		id		optional identifier for goals
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    82
		x		x coordinate of starting position (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    83
		y		y coordinate of starting position (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    84
		dx		initial x speed (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    85
		dy		initial y speed (default: 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    86
	- type=gtMine		Mine
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    87
		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
    88
		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
    89
		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
    90
		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
    91
	- type=gtSMine		Sticky mine
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    92
		timer		Timer. Default: 500
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    93
	- type=gtAirMine	Air mine
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    94
		timer		Timer. Default: (MinesTime/1000 * 250)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    95
	- type=gtExplosives	Barrel
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    96
		health		Initial health. Default: 60
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    97
		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
    98
		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
    99
	- type=gtCase		Crate
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   100
		crateType	"health": Health crate
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   101
				"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
   102
				"supply_ammo_explicit": Ammo crate (not recommened)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   103
				"supply_utility_explicit": Utility crate (not recommededn)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   104
		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
   105
		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
   106
		isFrozen	Whether the crate is frozen. Default: false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   107
	- type=gtKnife		Cleaver
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   108
	- type=gtTarget		Target
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   109
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   110
	GOALS:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   111
	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
   112
	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
   113
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   114
	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
   115
	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
   116
	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
   117
	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
   118
	- 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
   119
				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
   120
				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
   121
	- 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
   122
	- 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
   123
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   124
	- missionTitle:		The name of the mission (highly recommended)
13053
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   125
	- goalText:		A short string explaining the goal of the mission (use this if you set custom goals).
13049
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   126
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   127
	GOAL TYPES:
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   128
	- type			name of goal type
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   129
	- type="destroy"	Gear must be destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   130
		- id		Gear to destroy
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   131
	- type="teamDefeat"	Team must be defeated
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   132
		- teamName	Name of team to defeat
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   133
	- type="collect"	Crate must be collected
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   134
		FAIL CONDITION:	Crate taken by enemy, or destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   135
		- id		ID of crate gear to collect
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   136
		- 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
   137
				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
   138
	- 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
   139
		- turns 	Number of played turns 
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   140
	- 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
   141
		- rounds	Number of played rounds
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   142
	- type="suddenDeath"	Sudden Death has started
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   143
	- 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
   144
				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
   145
				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
   146
				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
   147
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   148
		- id		Gear to watch
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   149
		- 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
   150
		- 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
   151
		- 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
   152
		- 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
   153
	- 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
   154
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   155
		- distance	goal distance to compare to
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   156
		- relationship	"greaterThan" or "lowerThan"
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
		- x		x coordinate to reach
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   159
		- y		y coordinate to reach
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   160
	- type="distGearGear"	Distance between two gears
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   161
		FAIL CONDITION:	Any of both gears destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   162
		- distance	goal distance to compare to
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   163
		- relationship	"greaterThan" or "lowerThan"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   164
		- id1		first gear to compare
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   165
		- id2		second gear to compare
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   166
	- type="damage"		Gear took damage or was destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   167
		- id		Gear to watch
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   168
		- 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
   169
		- 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
   170
	- type="drown"		Gear has drowned
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   171
		FAIL CONDITION:	Gear destroyed by other means
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   172
		- id		Gear to watch
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   173
	- type="poison"		Gear must be poisoned
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   174
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   175
		- id		Gear to be poisoned
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   176
	- 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
   177
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   178
		- id		Gear to check
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   179
	- type="freeze"		Gear must exist and be frozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   180
		FAIL CONDITION:	Gear destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   181
		- id		Gear to be frozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   182
	- type="melt"		Gear must exist and be unfrozen
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 check
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   185
	- type="waterSkip"	Gear must have skipped over water
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   186
		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
   187
		- id
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   188
		- 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
   189
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   190
]]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   191
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   192
local goals
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   193
local teamHogs = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   194
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   195
--[[
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   196
	HELPER VARIABLES
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   197
]]
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
local defaultClanColors = {
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   200
	[0] = 0xff0204,	-- red
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   201
	[1] = 0x4980c1,	-- blue
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   202
	[2] = 0x1de6ba,	-- cyan
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   203
	[3] = 0xb541ef,	-- purple
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   204
	[4] = 0xe55bb0,	-- magenta
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   205
	[5] = 0x20bf00,	-- green
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   206
	[6] = 0xfe8b0e,	-- orange
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   207
	[7] = 0x5f3605,	-- brown
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   208
	[8] = 0xffff01,	-- yellow
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   209
}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   210
local defaultGraves = {
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   211
	"Grave", "Statue", "pyramid", "Simple", "skull", "Badger", "Duck2", "Flower"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   212
}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   213
local defaultFlags = {
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   214
	"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
   215
}
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
-- Utility functions
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   218
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   219
-- 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
   220
local function def(value, default)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   221
	if value == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   222
		return default
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   223
	else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   224
		return value
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   225
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   226
end
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
-- Get hypotenuse of a triangle with legs x and y
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   229
local function hypot(x, y)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   230
	local t
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   231
	x = math.abs(x)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   232
	y = math.abs(y)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   233
	t = math.min(x, y)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   234
	x = math.max(x, y)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   235
	if x == 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   236
		return 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   237
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   238
	t = t / x
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   239
	return x * math.sqrt(1 + t * t)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   240
end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   241
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   242
local errord = false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   243
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   244
-- 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
   245
function SimpleMission(params)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   246
	if params.missionTitle == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   247
		params.missionTitle = loc("Scenario")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   248
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   249
	if params.goalText == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   250
		params.goalText = loc("Defeat the enemy!")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   251
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   252
	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
   253
		params.customGoalCheck = "instant"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   254
	end
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 = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   257
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   258
	_G.sm.isInSuddenDeath = false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   259
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   260
	-- Number of completed turns
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   261
	_G.sm.gameTurns = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   262
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   263
	_G.sm.goalGears = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   264
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   265
	_G.sm.params = params
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   266
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   267
	_G.sm.gameEnded = false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   268
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   269
	_G.sm.playerClan = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   270
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   271
	_G.sm.makeStats = function(winningClan, customAchievements)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   272
		for t=0, TeamsCount-1 do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   273
			local team = GetTeamName(t)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   274
			local stats = GetTeamStats(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   275
			local clan = GetTeamClan(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   276
			if clan == winningClan then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   277
				SendStat(siPlayerKills, stats.Kills, team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   278
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   279
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   280
		for t=0, TeamsCount-1 do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   281
			local team = GetTeamName(t)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   282
			local stats = GetTeamStats(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   283
			local clan = GetTeamClan(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   284
			if clan ~= winningClan then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   285
				SendStat(siPlayerKills, stats.Kills, team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   286
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   287
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   288
		if customAchievements ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   289
			for a=1, #customAchievements do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   290
				SendStat(siCustomAchievement, customAchievements[a])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   291
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   292
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   293
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   294
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   295
	_G.sm.checkGoal = function(goal)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   296
		if goal.type == "destroy" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   297
			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
   298
		elseif goal.type == "collect" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   299
			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
   300
			if collector then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   301
				if not goal.collectors then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   302
					if GetHogClan(collector) == _G.sm.playerClan then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   303
						return true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   304
					else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   305
						-- Fail if the crate was collected by enemy
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   306
						return "fail"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   307
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   308
				else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   309
					for c=1, #goal.collectors do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   310
						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
   311
							return true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   312
						end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   313
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   314
					-- Fail if the crate was collected by someone who was not supposed to get it
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   315
					return "fail"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   316
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   317
			else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   318
				-- Fail goal if crate was destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   319
				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
   320
					return "fail"
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
				return false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   323
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   324
		elseif goal.type == "turns" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   325
			return sm.gameTurns >= goal.turns
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   326
		elseif goal.type == "rounds" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   327
			return (TotalRounds) >= goal.rounds
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   328
		elseif goal.type == "inZone" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   329
			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
   330
				return "fail"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   331
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   332
			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
   333
			-- 4 sub-goals, each optional
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   334
			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
   335
			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
   336
			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
   337
			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
   338
			return g1 and g2 and g3 and g4
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   339
		elseif goal.type == "distGearPos" or goal.type == "distGearGear" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   340
			local gX, tY, tX, tY
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   341
			if goal.type == "distGearPos" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   342
				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
   343
					-- Fail if gear was destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   344
					return "fail"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   345
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   346
				gX, gY = GetGearPosition(_G.sm.goalGears[goal.id])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   347
				tX, tY = goal.x, goal.y
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   348
			elseif goal.type == "distGearGear" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   349
				if getGearValue(_G.sm.goalGears[goal.id1], "sm_destroyed") or getGearValue(_G.sm.goalGears[goal.id2], "sm_destroyed") then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   350
					-- Fail if one of the gears was destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   351
					return "fail"
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
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   357
			local h = hypot(gX - tX, gY - tY)
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
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   371
			local tookEnoughDamage = getGearValue(_G.sm.goalGears[goal.id], "sm_maxDamage") >= damage
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   372
			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
   373
				-- 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
   374
				if not tookEnoughDamage and goal.canDestroy == false then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   375
					return "fail"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   376
				else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   377
				-- By default, succeed if gear was destroyed
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   378
					return true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   379
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   380
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   381
			return tookEnoughDamage
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   382
		elseif goal.type == "drown" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   383
			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
   384
			-- 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
   385
			if not drowned and 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
   386
				return "fail"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   387
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   388
			return drowned
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   389
		elseif goal.type == "poison" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   390
			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
   391
				return "fail"
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 GetEffect(_G.sm.goalGears[goal.id], hePoisoned) >= 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   394
		elseif goal.type == "freeze" 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
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   396
				return "fail"
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], heFrozen) >= 256
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   399
		elseif goal.type == "cure" 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
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   401
				return "fail"
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], hePoisoned) == 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   404
		elseif goal.type == "melt" 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
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   406
				return "fail"
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], heFrozen) == 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   409
		elseif goal.type == "waterSkip" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   410
			local skips = goal.skips or 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   411
			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
   412
			-- 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
   413
			if not hasEnoughSkips and 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
   414
				return "fail"
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   415
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   416
			return hasEnoughSkips
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   417
		elseif goal.type == "teamDefeat" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   418
			return #teamHogs[goal.teamName] == 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   419
		else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   420
			return false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   421
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   422
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   423
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   424
	--[[ Checks the custom goals.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   425
	Returns true when all custom goals are met.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   426
	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
   427
	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
   428
	Returns nil when there are no custom goals ]]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   429
	_G.sm.checkGoals = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   430
		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
   431
			for key, goal in pairs(params.customGoals) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   432
				local done = _G.sm.checkGoal(goal)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   433
				if done == false or done == "fail" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   434
					return done
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   435
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   436
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   437
			return true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   438
		else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   439
			return nil
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   440
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   441
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   442
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   443
	--[[ Checks the custom non-goals.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   444
	Returns true when any non-goal is met.
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   445
	Returns false otherwise. ]]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   446
	_G.sm.checkNonGoals = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   447
		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
   448
			for key, nonGoal in pairs(params.customNonGoals) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   449
				local done = _G.sm.checkGoal(nonGoal)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   450
				if done == true then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   451
					return true
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
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   454
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   455
		return false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   456
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   457
13053
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   458
	-- 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: 13049
diff changeset
   459
	_G.sm.checkRegularVictory = function()
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   460
		local victory = true
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   461
		for t=0, TeamsCount-1 do
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   462
			local team = GetTeamName(t)
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   463
			local defeat = _G.sm.checkGoal({type="teamDefeat", teamName=team})
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   464
			if (defeat == true) and (GetTeamClan(team) == _G.sm.playerClan) then
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   465
				victory = false
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   466
				break
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   467
			elseif (defeat == false) and (GetTeamClan(team) ~= _G.sm.playerClan) then
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   468
				victory = false
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   469
				break
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   470
			end
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   471
		end
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   472
		if victory then
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   473
			_G.sm.gameEnded = true
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   474
		end
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   475
	end
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   476
13049
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   477
	-- 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
   478
	_G.sm.checkWinOrFail = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   479
		if errord then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   480
			return
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   481
		end
13053
8b42562dcada SimpleMission: Check regular victory before anything else
Wuzzy <Wuzzy2@mail.ru>
parents: 13049
diff changeset
   482
		_G.sm.checkRegularVictory()
13049
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   483
		if _G.sm.checkNonGoals() == true or _G.sm.checkGoals() == "fail" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   484
			_G.sm.lose()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   485
		elseif _G.sm.checkGoals() == true then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   486
			_G.sm.win()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   487
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   488
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   489
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   490
	_G.sm.win = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   491
		if not _G.sm.gameEnded then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   492
			_G.sm.gameEnded = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   493
			AddCaption(loc("Victory!"), 0xFFFFFFFF, capgrpGameState)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   494
			SendStat(siGameResult, loc("You win!"))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   495
			if GetHogLevel(CurrentHedgehog) == 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   496
				SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstWinner))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   497
				SetState(CurrentHedgehog, band(GetState(CurrentHedgehog), bnot(gstHHDriven)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   498
				PlaySound(sndVictory, CurrentHedgehog)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   499
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   500
			_G.sm.makeStats(_G.sm.playerClan)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   501
			EndGame()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   502
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   503
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   504
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   505
	_G.sm.lose = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   506
		if not _G.sm.gameEnded then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   507
			_G.sm.gameEnded = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   508
			AddCaption(loc("Scenario failed!"), 0xFFFFFFFF, capgrpGameState)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   509
			SendStat(siGameResult, loc("You lose!"))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   510
			if GetHogLevel(CurrentHedgehog) == 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   511
				SetState(CurrentHedgehog, bor(GetState(CurrentHedgehog), gstLoser))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   512
				SetState(CurrentHedgehog, band(GetState(CurrentHedgehog), bnot(gstHHDriven)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   513
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   514
			local clan = ClansCount-1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   515
			for t=0, TeamsCount-1 do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   516
				local team = GetTeamName(t)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   517
				-- 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
   518
				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
   519
					clan = GetTeamClan(team)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   520
					break
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   521
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   522
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   523
			_G.sm.makeStats(clan)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   524
			EndGame()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   525
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   526
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   527
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   528
	_G.onSuddenDeath = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   529
		sm.isInSuddenDeath = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   530
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   531
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   532
	_G.onGearWaterSkip = function(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   533
		increaseGearValue(gear, "sm_waterSkips")
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
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   536
	_G.onGearAdd = function(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   537
		if GetGearType(gear) == gtHedgehog then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   538
			local team = GetHogTeamName(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   539
			if teamHogs[team] == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   540
				teamHogs[team] = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   541
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   542
			table.insert(teamHogs[GetHogTeamName(gear)], gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   543
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   544
		setGearValue(gear, "sm_waterSkips", 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   545
		setGearValue(gear, "sm_maxDamage", 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   546
		setGearValue(gear, "sm_drowned", false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   547
		setGearValue(gear, "sm_destroyed", false)
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
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   550
	_G.onGearResurrect = function(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   551
		if GetGearType(gear) == gtHedgehog then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   552
			table.insert(teamHogs[GetHogTeamName(gear)], gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   553
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   554
		setGearValue(gear, "sm_destroyed", false)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   555
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   556
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   557
	_G.onGearDelete = function(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   558
		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
   559
			-- Set ID of collector
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   560
			setGearValue(gear, "sm_collected", CurrentHedgehog)
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
		if GetGearType(gear) == gtHedgehog then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   563
			local team = GetHogTeamName(gear)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   564
			local hogList = teamHogs[team]
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   565
			for h=1, #hogList do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   566
				if hogList[h] == gear then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   567
					table.remove(hogList, h)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   568
					break
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
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   571
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   572
		if band(GetState(gear), gstDrowning) ~= 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   573
			setGearValue(gear, "sm_drowned", true)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   574
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   575
		setGearValue(gear, "sm_destroyed", true)
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
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   578
	_G.onGearDamage = function(gear, damage)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   579
		local currentDamage = getGearValue(gear, "sm_maxDamage")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   580
		if damage > currentDamage then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   581
			setGearValue(gear, "sm_maxDamage", damage)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   582
		end
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.onGameInit = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   586
		CaseFreq = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   587
		WaterRise = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   588
		HealthDecrease = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   589
		MinesNum = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   590
		Explosives = 0
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
		for initVarName, initVarValue in pairs(params.initVars) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   593
			_G[initVarName] = initVarValue
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   594
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   595
		if #params.teams == 1 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   596
			EnableGameFlags(gfOneClanMode)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   597
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   598
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   599
		local clanCounter = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   600
		for teamID, teamData in pairs(params.teams) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   601
			local name, clanID, grave, fort, voice, flag
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   602
			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
   603
			if teamData.clanID == nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   604
				clanID = clanCounter
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   605
				clanCounter = clanCounter + 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   606
			else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   607
				clanID = teamData.clanID
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   608
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   609
			grave = def(teamData.grave, defaultGraves[math.min(teamID, 8)])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   610
			fort = def(teamData.fort, "Castle")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   611
			voice = def(teamData.voice, "Default")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   612
			flag = def(teamData.flag, defaultFlags[math.min(teamID, 8)])
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   613
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   614
			AddTeam(name, defaultClanColors[clanID], grave, fort, voice, flag)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   615
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   616
			for hogID, hogData in pairs(teamData.hogs) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   617
				local name, botLevel, health, hat
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   618
				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
   619
				botLevel = def(hogData.botLevel, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   620
				health = def(hogData.health, 100)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   621
				hat = def(hogData.hat, "NoHat")
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   622
				local hog = AddHog(name, botLevel, health, hat)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   623
				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
   624
					SetGearPosition(hog, hogData.x, hogData.y)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   625
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   626
				if hogData.faceLeft then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   627
					HogTurnLeft(hog, true)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   628
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   629
				if hogData.poisoned == true then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   630
					SetEffect(hog, hePoisoned, 5)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   631
				elseif type(hogData.poisoned) == "number" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   632
					SetEffect(hog, hePoisoned, hogData.poisoned)
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 hogData.frozen then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   635
					SetEffect(hog, heFrozen, 199999)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   636
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   637
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   638
				if hog ~= nil and hogData.id ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   639
					_G.sm.goalGears[hogData.id] = hog
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   640
					setGearValue(hog, "sm_id", hogData.id)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   641
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   642
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   643
				-- 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
   644
				hogData.gearID = hog
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   645
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   646
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   647
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   648
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   649
	_G.onNewTurn = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   650
		if params.wind ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   651
			SetWind(params.wind)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   652
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   653
		_G.sm.gameStarted = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   654
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   655
		if params.customGoalCheck == "turnStart" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   656
			_G.sm.checkWinOrFail()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   657
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   658
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   659
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   660
	_G.onEndTurn = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   661
		_G.sm.gameTurns = _G.sm.gameTurns + 1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   662
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   663
		if params.customGoalCheck == "turnEnd" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   664
			_G.sm.checkWinOrFail()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   665
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   666
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   667
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   668
	_G.onAmmoStoreInit = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   669
		local ammoTypesDone = {}
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   670
		-- Read script's stated ammo wishes
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   671
		if params.ammoConfig ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   672
			for ammoType, v in pairs(params.ammoConfig) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   673
				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
   674
				ammoTypesDone[ammoType] = true
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   675
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   676
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   677
		-- 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
   678
		for a=0, AmmoTypeMax do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   679
			if a ~= amNothing and ammoTypesDone[a] ~= true then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   680
				local count = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   681
				if a == amSkip then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   682
					count = 9
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   683
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   684
				SetAmmo(a, count, 0, 0, 1)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   685
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   686
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   687
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   688
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   689
	_G.onGameStart = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   690
		-- Mention mines timer
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   691
		if MinesTime ~= 3000 and MinesTime ~= nil then 
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   692
			if MinesTime < 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   693
				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
   694
			elseif (MinesTime % 1000) == 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   695
				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
   696
			elseif (MinesTime % 100) == 0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   697
				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
   698
			else
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   699
				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
   700
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   701
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   702
		ShowMission(params.missionTitle, loc("Scenario"), params.goalText, 1, 5000) 
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   703
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   704
		-- Spawn objects
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   705
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   706
		if params.gears ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   707
			for listGearID, gv in pairs(params.gears) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   708
				local timer, state, x, y, dx, dy
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   709
				local g
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   710
				state = 0
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   711
				if gv.type == gtMine then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   712
					if gv.isFrozen then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   713
						state = gstFrozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   714
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   715
					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
   716
					if gv.isDud then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   717
						SetHealth(g, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   718
						if gv.health ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   719
							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
   720
						end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   721
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   722
				elseif gv.type == gtSMine then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   723
					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
   724
				elseif gv.type == gtAirMine then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   725
					if gv.isFrozen then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   726
						state = gstFrozen
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   727
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   728
					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
   729
					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
   730
					SetGearValues(g, nil, nil, timer) -- WDTimer
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   731
				elseif gv.type == gtExplosives then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   732
					if gv.isRolling then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   733
						state = gsttmpFlag
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
					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
   736
					if gv.health then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   737
						SetHealth(g, gv.health)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   738
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   739
					if gv.isFrozen ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   740
						if gv.isFrozen == true then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   741
							SetState(g, bor(GetState(g, gstFrozen)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   742
						end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   743
					elseif GetHealth(g) > 60 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   744
						SetState(g, bor(GetState(g, gstFrozen)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   745
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   746
				elseif gv.type == gtCase then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   747
					local x, y, spawnTrick
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   748
					spawnTrick = false
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   749
					x = def(gv.x, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   750
					y = def(gv.y, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   751
					if x==0 and y==0 then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   752
						x=1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   753
						y=1
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   754
						spawnTrick = true
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
					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
   757
					if spawnTrick then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   758
						SetGearPosition(g, 0, 0)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   759
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   760
					if gv.crateType == "supply" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   761
						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
   762
					elseif gv.crateType == "supply_ammo_explicit" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   763
						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
   764
					elseif gv.crateType == "supply_utility_explicit" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   765
						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
   766
					elseif gv.crateType == "health" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   767
						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
   768
						if gv.health ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   769
							SetHealth(g, gv.health)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   770
						end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   771
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   772
					if gv.isFrozen then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   773
						SetState(g, bor(GetState(g, gstFrozen)))
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   774
					end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   775
				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
   776
					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
   777
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   778
				if g ~= nil and gv.id ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   779
					_G.sm.goalGears[gv.id] = g
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   780
					setGearValue(g, "sm_id", gv.id)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   781
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   782
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   783
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   784
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   785
		-- Spawn girders and rubbers
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   786
		if params.girders ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   787
			for i, girderData in pairs(params.girders) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   788
				PlaceGirder(girderData.x, girderData.y, girderData.frameIdx)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   789
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   790
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   791
		if params.rubbers ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   792
			for i, rubberData in pairs(params.rubbers) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   793
				PlaceSprite(rubberData.x, rubberData.y, sprAmRubber, 0xFFFFFFFF, rubberData.frameIdx, false, false, false, lfBouncy)
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   794
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   795
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   796
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   797
		-- Per-hedgehog ammo loadouts
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   798
		for teamID, teamData in pairs(params.teams) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   799
			for hogID, hogData in pairs(teamData.hogs) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   800
				if hogData.ammo ~= nil then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   801
					for ammoType, count in pairs(hogData.ammo) do
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   802
						AddAmmo(hogData.gearID, ammoType, count)
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
				end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   805
			end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   806
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   807
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   808
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   809
	_G.onGameTick20 = function()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   810
		if params.customGoalCheck == "instant" then
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   811
			_G.sm.checkWinOrFail()
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   812
		end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   813
	end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   814
end
f18cefc4309d Add SimpleMission lua library for easier mission creation
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   815