share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua
author unC0Rr
Fri, 19 Apr 2024 17:45:05 +0200
changeset 16011 52b51d92e88d
parent 15788 acf70c44065b
permissions -rw-r--r--
Fix build
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
     1
---------------------------------------
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
     2
-- CAPTURE_THE_FLAG GAMEPLAY MODE 0.5
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
     3
-- by mikade
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
     4
---------------------------------------
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
     5
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
     6
---- Script parameter
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
     7
-- With “captures=<number>” you can set your own capture limit, e.g. “captures=5” for 5 captures.
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
     8
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
     9
-- Version History
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    10
---------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    11
-- 0.1
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    12
---------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    13
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    14
-- [conversion from map-dependant CTF_Blizzard to map independant Capture the Flag]
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    15
-- added an intial starting stage where flagspawn is decided by the players (weapon set will require a jetpack unless I set)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    16
-- changed the flag from a crate to a visual gear, and all associated methods and checks relating to flags (five hours later, lol)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    17
-- changed starting/respawning positioning to accommodate different map sizes
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    18
-- added another circle to mark flag spawn
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    19
-- added gameFlag filter
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    20
-- changed scoring feedback
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    21
-- cleaned up some code
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    22
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    23
-- removing own flag from spawning point no longer possible
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    24
-- destroying flags no longer possible.
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    25
-- added basic glowing circle effect to spawn area
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    26
-- added expanding circle to fgear itself
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    27
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    28
-- removed teleporters
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    29
-- removed random crate drops (this should be decided by scheme)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    30
-- removed set map criteria like minesNum, turnTime, explosives etc. except for sudden death
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    31
-- removed weapon defintions
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    32
-- removed placement and respawning methods, hopefully divideTeams will have this covered
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    33
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    34
---------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    35
-- 0.2
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    36
---------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    37
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    38
-- [now with user friendliness]
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    39
-- flag is now placed wherever you end up at the end of your first turn, this ensures that it is always placed by turn 3
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    40
-- removed a bunch of backup code and no-longer needed variables / methods from CTF_Blizzard days
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    41
-- removed an aura that was still mistakenly hanging about
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    42
-- added an in-game note about placements
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    43
-- added an in-game note about the rules of the game
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    44
-- added translation support and loc()'ed everything
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    45
-- changed things so the seed is no longer always the same...
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    46
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    47
-- In this version:
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    48
---------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    49
-- 0.3
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    50
---------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    51
-- [fufufufu kamikaze fix]
15788
acf70c44065b Use the singular 'they' in code comments, where it makes sense
Wuzzy <Wuzzy2@mail.ru>
parents: 15252
diff changeset
    52
-- added nil checks to make sure the player doesn't generate errors by producing a nil value in hhs[] when using kamikaze
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    53
-- added a check to make sure the player doesn't kamikaze straight down and make the flag's starting point underwater
15788
acf70c44065b Use the singular 'they' in code comments, where it makes sense
Wuzzy <Wuzzy2@mail.ru>
parents: 15252
diff changeset
    54
-- added a check to make sure the player drops the flag if they have it and they use kamikaze
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    55
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    56
--------
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    57
-- 0.4
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    58
--------
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    59
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    60
-- remove user-branding and version numbers
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    61
-- removed some stuff that wasn't needed
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    62
-- fix piano strike exploit
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    63
-- changed delay to allow for better portals
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    64
-- changed starting feedback a little
15788
acf70c44065b Use the singular 'they' in code comments, where it makes sense
Wuzzy <Wuzzy2@mail.ru>
parents: 15252
diff changeset
    65
-- increased the radius around the circle indicating the flag thief so that it doesn't obscure their health
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
    66
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
    67
--------
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
    68
-- 0.5
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
    69
--------
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
    70
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
    71
-- add support for more players
5821
afb988c1a2fe Allow limited form of SuddenDeath (WaterRise = 0) in both CTF modes
mikade
parents: 5819
diff changeset
    72
-- allow limited sudden death
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
    73
-- stop TimeBox ruining my life
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
    74
-- profit???
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
    75
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    76
-----------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    77
--SCRIPT BEGINS
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    78
-----------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    79
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    80
-- enable awesome translaction support so we can use loc() wherever we want
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 7838
diff changeset
    81
HedgewarsScriptLoad("/Scripts/Locale.lua")
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
    82
HedgewarsScriptLoad("/Scripts/Params.lua")
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    83
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    84
---------------------------------------------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    85
----------lots of bad variables and things
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    86
----------because someone is too lazy
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    87
----------to read about tables properly
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    88
------------------ "Oh well, they probably have the memory"
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    89
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    90
local gameStarted = false
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
    91
local gameOver = false
15252
515a4a317e52 CTF: Fix clan not winning if enemy hog was time-travelling
Wuzzy <Wuzzy2@mail.ru>
parents: 15130
diff changeset
    92
local winningClan = -1
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
    93
local captureLimit = 3
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    94
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    95
--------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    96
-- hog and team tracking variales
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    97
--------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    98
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
    99
local numhhs = 0 -- store number of hedgehogs
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   100
local hhs = {} -- store hedgehog gears
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   101
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   102
local teamSize = {}	-- store how many hogs per team
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   103
local teamIndex = {} -- at what point in the hhs{} does each team begin
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   104
13115
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   105
local mostCapturesHogName = nil -- name of hog who holds the record of most flags captured
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   106
local mostCapturesHogTeam = nil -- name of team who holds the record of most flags captured
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   107
local mostCaptures = 0 -- number of most per-hog captures
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   108
local capturesPerHog = {}
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   109
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   110
-------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   111
-- flag variables
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   112
-------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   113
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   114
local fGear = {}	-- pointer to the visual gears that represent the flag
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   115
local fGearX = {}
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   116
local fGearY = {}
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   117
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   118
local fThief = {}	-- pointer to the hogs who stole the flags
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   119
local fThiefFlag = {}   -- contains the stolen flag type of fThief
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   120
local fIsMissing = {}	-- have the flags been destroyed or captured
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   121
local fNeedsRespawn = {}	-- do the flags need to be respawned
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   122
local fCaptures = {}	-- the team "scores" how many captures
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   123
local fSpawnX = {}		-- spawn X for flags
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   124
local fSpawnY = {}		-- spawn Y for flags
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   125
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   126
local fThiefX = {}
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   127
local fThiefY = {}
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   128
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   129
local fSpawnC = {} -- spawn circle marker
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   130
local fCirc = {} -- flag/carrier marker circles
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   131
local fCol = {} -- colour of the clans
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   132
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   133
local fGearRad = 0
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   134
local fGearRadMin = 5
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   135
local fGearRadMax = 33
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   136
local fGearTimer = 0
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   137
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   138
------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   139
--flag methods
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   140
------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   141
14989
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   142
local RankTeams = function(teamList)
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   143
	local teamRank = function(a, b)
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   144
		if a.score ~= b.score then
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   145
			return a.score > b.score
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   146
		else
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   147
			return a.clan > b.clan
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   148
		end
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   149
	end
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   150
	table.sort(teamList, teamRank)
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   151
	local rank, plusRank, score, clan
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   152
	for i=1, #teamList do
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   153
		if i == 1 then
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   154
			rank = 1
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   155
			plusRank = 1
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   156
			score = teamList[i].score
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   157
			clan = teamList[i].clan
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   158
		end
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   159
		if (teamList[i].score < score) then
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   160
			rank = rank + plusRank
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   161
			plusRank = 1
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   162
		end
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   163
		if (teamList[i].score == score and teamList[i].clan ~= clan) then
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   164
			plusRank = plusRank + 1
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   165
		end
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   166
		teamList[i].rank = rank
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   167
		score = teamList[i].score
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   168
		clan = teamList[i].clan
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   169
	end
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   170
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   171
	for i=1, #teamList do
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   172
		SendStat(siPointType, "!POINTS")
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   173
		SendStat(siTeamRank, tostring(teamList[i].rank))
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   174
		SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   175
	end
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   176
end
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   177
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   178
function CheckScore(clanID)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   179
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   180
	if fCaptures[clanID] == captureLimit then
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   181
		gameOver = true
15252
515a4a317e52 CTF: Fix clan not winning if enemy hog was time-travelling
Wuzzy <Wuzzy2@mail.ru>
parents: 15130
diff changeset
   182
		winningClan = clanID
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   183
		-- Capture limit reached! We have a winner!
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   184
		for i = 0, (numhhs-1) do
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   185
			if hhs[i] ~= nil then
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   186
				-- Kill all losers
15252
515a4a317e52 CTF: Fix clan not winning if enemy hog was time-travelling
Wuzzy <Wuzzy2@mail.ru>
parents: 15130
diff changeset
   187
				if GetHogClan(hhs[i]) ~= winningClan then
7838
5c2337f8dbb2 Issue #443 - change in syntax for effects
nemo
parents: 5827
diff changeset
   188
					SetEffect(hhs[i], heResurrectable, 0)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   189
					SetHealth(hhs[i],0)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   190
				end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   191
			end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   192
		end
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   193
		if CurrentHedgehog ~= nil then
13643
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13630
diff changeset
   194
			AddCaption(string.format(loc("Victory for %s!"), GetHogTeamName(CurrentHedgehog)), capcolDefault, capgrpGameState)
13019
880662cf41ee Add team score next to team bars for CTF_Blizard, Control, CTF, Mutant, Space Invasion
Wuzzy <Wuzzy2@mail.ru>
parents: 12079
diff changeset
   195
			updateScores()
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   196
		end
13113
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   197
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   198
		-- Calculate team rankings
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   199
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   200
		local teamList = {}
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   201
		for i=0, TeamsCount-1 do
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   202
			local name = GetTeamName(i)
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   203
			local clan = GetTeamClan(name)
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   204
			table.insert(teamList, { score = fCaptures[clan], name = name, clan = clan })
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   205
		end
14989
5188ecbf726f Rank tied teams properly in Control, CTF and Mutant
Wuzzy <Wuzzy2@mail.ru>
parents: 14578
diff changeset
   206
		RankTeams(teamList)
13115
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   207
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   208
		if mostCaptures >= 2 then
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   209
			SendStat(siCustomAchievement, string.format(loc("%s (%s) has captured the flag %d times."), mostCapturesHogName, mostCapturesHogTeam, mostCaptures))
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   210
		end
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   211
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   212
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   213
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   214
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   215
function DoFlagStuff(flag, flagClan)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   216
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   217
	if not CurrentHedgehog then
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   218
		return
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   219
	end
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   220
	local wtf = flagClan
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   221
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   222
	local thiefClan
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   223
	for i=0, ClansCount - 1 do
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   224
		if CurrentHedgehog == fThief[i] then
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   225
			thiefClan = i
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   226
		end
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   227
	end
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   228
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   229
	-- player has successfully captured the enemy flag
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   230
	if (GetHogClan(CurrentHedgehog) == flagClan) and (thiefClan ~= nil) and (fIsMissing[flagClan] == false) then
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   231
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   232
		fIsMissing[thiefClan] = false
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   233
		fNeedsRespawn[thiefClan] = true
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   234
		fCaptures[flagClan] = fCaptures[flagClan] +1
13643
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13630
diff changeset
   235
		AddCaption(string.format(loc("%s has scored!"), GetHogName(CurrentHedgehog)), capcolDefault, capgrpGameState)
13019
880662cf41ee Add team score next to team bars for CTF_Blizard, Control, CTF, Mutant, Space Invasion
Wuzzy <Wuzzy2@mail.ru>
parents: 12079
diff changeset
   236
		updateScores()
11907
ce9e0f8e43f4 CTF: Play sound when capturing flag
Wuzzy <almikes@aol.com>
parents: 11906
diff changeset
   237
		PlaySound(sndHomerun)
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   238
		fThief[thiefClan] = nil -- player no longer has the enemy flag
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   239
		fThiefFlag[flagClan] = nil
13115
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   240
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   241
		capturesPerHog[CurrentHedgehog] = capturesPerHog[CurrentHedgehog] + 1
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   242
		if capturesPerHog[CurrentHedgehog] > mostCaptures then
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   243
			mostCaptures = capturesPerHog[CurrentHedgehog]
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   244
			mostCapturesHogName = GetHogName(CurrentHedgehog)
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   245
			mostCapturesHogTeam = GetHogTeamName(CurrentHedgehog)
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   246
		end
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   247
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   248
		CheckScore(flagClan)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   249
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   250
	--if the player is returning the flag
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   251
	elseif (GetHogClan(CurrentHedgehog) == flagClan) and (fIsMissing[flagClan] == true) then
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   252
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   253
		DeleteVisualGear(fGear[flagClan])
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   254
		fGear[flagClan] = nil -- the flag has now disappeared
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   255
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   256
		fNeedsRespawn[flagClan] = true
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   257
		HandleRespawns() -- this will set fIsMissing[flagClan] to false :)
13643
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13630
diff changeset
   258
		AddCaption(loc("Flag returned!"), capcolDefault, capgrpMessage2)
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   259
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   260
	--if the player is taking the enemy flag (not possible if already holding a flag)
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   261
	elseif GetHogClan(CurrentHedgehog) ~= flagClan and (thiefClan == nil) then
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   262
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   263
		DeleteVisualGear(fGear[flagClan])
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   264
		fGear[flagClan] = nil -- the flag has now disappeared
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   265
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   266
		fIsMissing[flagClan] = true
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   267
		for i = 0,numhhs-1 do
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   268
			if CurrentHedgehog ~= nil then
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   269
				if CurrentHedgehog == hhs[i] then
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   270
					fThief[flagClan] = hhs[i]
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   271
					fThiefFlag[flagClan] = flagClan
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   272
				end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   273
			end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   274
		end
13643
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13630
diff changeset
   275
		AddCaption(loc("Flag captured!"), capcolDefault, capgrpMessage2)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   276
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   277
	end
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   278
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   279
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   280
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   281
function CheckFlagProximity()
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   282
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   283
	for i = 0, ClansCount-1 do
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   284
		if fGear[i] ~= nil then
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   285
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   286
			local g1X = fGearX[i]
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   287
			local g1Y = fGearY[i]
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   288
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   289
			local g2X, g2Y = GetGearPosition(CurrentHedgehog)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   290
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   291
			local q = g1X - g2X
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   292
			local w = g1Y - g2Y
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   293
			local dist = (q*q) + (w*w)
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   294
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   295
			if dist < 500 then
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   296
				DoFlagStuff(fGear[i], i)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   297
			end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   298
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   299
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   300
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   301
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   302
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   303
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   304
function HandleRespawns()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   305
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   306
	for i = 0, ClansCount-1 do
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   307
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   308
		if fNeedsRespawn[i] == true then
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   309
			fGear[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   310
			fGearX[i] = fSpawnX[i]
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   311
			fGearY[i] = fSpawnY[i]
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
   312
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   313
			fNeedsRespawn[i] = false
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   314
			fIsMissing[i] = false -- new, this should solve problems of a respawned flag being "returned" when a player tries to score
13643
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13630
diff changeset
   315
			AddCaption(loc("Flag respawned!"), capcolDefault, capgrpMessage2)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   316
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   317
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   318
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   319
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   320
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   321
13113
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   322
-- Advance the clan score graph by one step
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   323
function DrawScores()
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   324
	local clansUsed = {}
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   325
	for i=0, TeamsCount-1 do
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   326
		local team = GetTeamName(i)
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   327
		local clan = GetTeamClan(team)
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   328
		if not clansUsed[clan] then
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   329
			local captures = fCaptures[clan]
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   330
			SendStat(siClanHealth, captures, team)
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   331
			clansUsed[clan] = true
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   332
		end
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   333
	end
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   334
end
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   335
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   336
function FlagThiefDead(gear)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   337
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   338
	local thiefClan
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   339
	local stolenFlagClan
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   340
	for i=0, ClansCount-1 do
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   341
		if (gear == fThief[i]) then
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   342
			thiefClan = i
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   343
			stolenFlagClan = fThiefFlag[i]
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   344
			break
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   345
		end
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   346
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   347
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   348
	if stolenFlagClan ~= nil then
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   349
		-- falls into water
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   350
		if (LAND_HEIGHT - fThiefY[thiefClan]) < 15 then
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   351
			fIsMissing[stolenFlagClan] = true
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   352
			fNeedsRespawn[stolenFlagClan] = true
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   353
			HandleRespawns()
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   354
		else	--normally
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   355
			fGearX[stolenFlagClan] = fThiefX[thiefClan]
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   356
			fGearY[stolenFlagClan] = fThiefY[thiefClan]
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   357
			fGear[stolenFlagClan] = AddVisualGear(fGearX[stolenFlagClan], fGearY[stolenFlagClan], vgtCircle, 0, true)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   358
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   359
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   360
		AddVisualGear(fThiefX[thiefClan], fThiefY[thiefClan], vgtBigExplosion, 0, false)
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   361
		fThief[thiefClan] = nil
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   362
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   363
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   364
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   365
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   366
function HandleCircles()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   367
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   368
	fGearTimer = fGearTimer + 1
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   369
	if fGearTimer == 50 then
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   370
		fGearTimer = 0
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   371
		fGearRad = fGearRad + 1
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   372
		if fGearRad > fGearRadMax then
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   373
			fGearRad = fGearRadMin
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   374
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   375
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   376
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   377
	for i = 0, ClansCount-1 do
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   378
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   379
		if fIsMissing[i] == false then -- draw a flag marker at the flag's spawning place
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   380
			SetVisualGearValues(fCirc[i], fSpawnX[i],fSpawnY[i], 20, 20, 0, 10, 0, 33, 3, fCol[i])
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   381
			if fGear[i] ~= nil then -- draw the flag gear itself
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   382
				SetVisualGearValues(fGear[i], fSpawnX[i],fSpawnY[i], 20, 200, 0, 0, 100, fGearRad, 2, fCol[i])
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   383
			end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   384
		elseif (fIsMissing[i] == true) and (fNeedsRespawn[i] == false) then
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
   385
			if fThief[i] ~= nil then -- draw circle round flag carrier			-- 33
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
   386
				SetVisualGearValues(fCirc[i], fThiefX[i], fThiefY[i], 20, 200, 0, 0, 100, 50, 3, fCol[i])
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   387
			elseif fThief[i] == nil then -- draw cirle round dropped flag
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   388
				SetVisualGearValues(fCirc[i], fGearX[i], fGearY[i], 20, 200, 0, 0, 100, 33, 3, fCol[i])
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   389
				if fGear[i] ~= nil then -- flag gear itself
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   390
					SetVisualGearValues(fGear[i], fGearX[i], fGearY[i], 20, 200, 0, 0, 100, fGearRad, 2, fCol[i])
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   391
				end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   392
			end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   393
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   394
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   395
		if fNeedsRespawn[i] == true then -- if the flag has been destroyed, no need for a circle
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   396
			SetVisualGearValues(fCirc[i], fSpawnX[i],fSpawnY[i], 20, 200, 0, 0, 100, 0, 0, fCol[i])
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   397
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   398
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   399
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   400
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   401
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   402
------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   403
-- general methods
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   404
------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   405
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   406
function CheckDistance(gear1, gear2)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   407
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   408
	local g1X, g1Y = GetGearPosition(gear1)
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   409
	local g2X, g2Y = GetGearPosition(gear2)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   410
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   411
	g1X = g1X - g2X
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   412
	g1Y = g1Y - g2Y
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   413
	local dist = (g1X*g1X) + (g1Y*g1Y)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   414
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   415
	return dist
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   416
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   417
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   418
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   419
function RebuildTeamInfo()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   420
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   421
	-- make a list of teams
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   422
	for i = 0, (TeamsCount-1) do
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   423
		teamSize[i] = 0
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   424
		teamIndex[i] = 0
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   425
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   426
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   427
	-- find out how many hogs per team, and the index of the first hog in hhs
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   428
	for i = 0, (TeamsCount-1) do
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   429
		for z = 0, numhhs-1 do
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   430
			if GetHogTeamName(hhs[z]) == GetTeamName(i) then
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   431
				if teamSize[i] == 0 then
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   432
					teamIndex[i] = z -- should give starting index
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   433
				end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   434
				teamSize[i] = teamSize[i] + 1
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   435
				--add a pointer so this hog appears at i in hhs
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   436
			end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   437
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   438
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   439
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   440
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   441
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   442
function StartTheGame()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   443
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   444
	gameStarted = true
13643
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13630
diff changeset
   445
	AddCaption(loc("Game Started!"), capcolDefault, capgrpGameState)
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   446
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   447
	for i = 0, ClansCount-1 do
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   448
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   449
		fGear[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   450
		fCirc[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   451
		fSpawnC[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   452
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   453
		fGearX[i] = fSpawnX[i]
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   454
		fGearY[i] = fSpawnY[i]
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   455
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   456
		fCol[i] = GetClanColor(i)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   457
		fIsMissing[i] = false
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   458
		fNeedsRespawn[i] = false
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   459
		fCaptures[i] = 0
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   460
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   461
		SetVisualGearValues(fSpawnC[i], fSpawnX[i],fSpawnY[i], 20, 100, 0, 10, 0, 75, 5, fCol[i])
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   462
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   463
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   464
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   465
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   466
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   467
------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   468
-- game methods
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   469
------------------------
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   470
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   471
function onParameters()
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   472
	parseParams()
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   473
	if params["captures"] ~= nil then
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   474
		local s = string.match(params["captures"], "(%d*)")
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   475
		if s ~= nil then
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   476
			captureLimit = math.max(1, tonumber(s))
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   477
		end
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   478
	end
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   479
end
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   480
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   481
function onGameInit()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   482
13103
cf2a58dccc4a CTF: Remove tardis and resurrector
Wuzzy <Wuzzy2@mail.ru>
parents: 13019
diff changeset
   483
	DisableGameFlags(gfKing, gfAISurvival)
10036
3be36d2fdca6 use new API for changing GameFlags
sheepluva
parents: 8043
diff changeset
   484
	EnableGameFlags(gfDivideTeams)
3be36d2fdca6 use new API for changing GameFlags
sheepluva
parents: 8043
diff changeset
   485
12079
8f222872d432 Disable SD for a couple of scripts and mission maps
Wuzzy <almikes@aol.com>
parents: 11907
diff changeset
   486
	-- Disable Sudden Death
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   487
	WaterRise = 0
12079
8f222872d432 Disable SD for a couple of scripts and mission maps
Wuzzy <almikes@aol.com>
parents: 11907
diff changeset
   488
	HealthDecrease = 0
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   489
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   490
13019
880662cf41ee Add team score next to team bars for CTF_Blizard, Control, CTF, Mutant, Space Invasion
Wuzzy <Wuzzy2@mail.ru>
parents: 12079
diff changeset
   491
function showCTFMission()
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   492
	local captures
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   493
	if captureLimit == 1 then
13114
c3fc9157f740 CTF: Say "clan" instead of "team" in mission panel
Wuzzy <Wuzzy2@mail.ru>
parents: 13113
diff changeset
   494
		captures = string.format(loc("- First clan to capture the flag wins"), captureLimit)
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   495
	else
13114
c3fc9157f740 CTF: Say "clan" instead of "team" in mission panel
Wuzzy <Wuzzy2@mail.ru>
parents: 13113
diff changeset
   496
		captures = string.format(loc("- First clan to score %d captures wins"), captureLimit)
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   497
	end
11905
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   498
13114
c3fc9157f740 CTF: Say "clan" instead of "team" in mission panel
Wuzzy <Wuzzy2@mail.ru>
parents: 13113
diff changeset
   499
	local rules = loc("Rules:") .. "|" ..
c3fc9157f740 CTF: Say "clan" instead of "team" in mission panel
Wuzzy <Wuzzy2@mail.ru>
parents: 13113
diff changeset
   500
		loc("- Place your clan flag at the end of your first turn") .. "|" ..
11905
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   501
		loc("- Return the enemy flag to your base to score") .."|"..
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   502
		captures .. "|" ..
11905
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   503
		loc("- You may only score when your flag is in your base") .."|"..
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   504
		loc("- Hogs will drop the flag when killed") .."|"..
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   505
		loc("- Dropped flags may be returned or recaptured").."|"..
11906
0e943402b94f CTF: Allow to set capture limit with script param
Wuzzy <almikes@aol.com>
parents: 11905
diff changeset
   506
		loc("- Hogs will be revived")
11905
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   507
15067
d59da429d22c Add 2 mission panel icons: hedgehog and flags
Wuzzy <Wuzzy2@mail.ru>
parents: 14989
diff changeset
   508
	ShowMission(loc("Capture The Flag"), loc("A Hedgewars minigame"), rules, 11, 0)
13019
880662cf41ee Add team score next to team bars for CTF_Blizard, Control, CTF, Mutant, Space Invasion
Wuzzy <Wuzzy2@mail.ru>
parents: 12079
diff changeset
   509
end
11905
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   510
13019
880662cf41ee Add team score next to team bars for CTF_Blizard, Control, CTF, Mutant, Space Invasion
Wuzzy <Wuzzy2@mail.ru>
parents: 12079
diff changeset
   511
function updateScores()
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   512
	for i=0, TeamsCount-1 do
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   513
		local team = GetTeamName(i)
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   514
		local clan = GetTeamClan(team)
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   515
		SetTeamLabel(team, tostring(fCaptures[clan]))
11905
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   516
	end
71ebc4c19b7f CTF: Clean up mission panel
Wuzzy <almikes@aol.com>
parents: 11904
diff changeset
   517
end
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   518
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   519
function onGameStart()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   520
13019
880662cf41ee Add team score next to team bars for CTF_Blizard, Control, CTF, Mutant, Space Invasion
Wuzzy <Wuzzy2@mail.ru>
parents: 12079
diff changeset
   521
	showCTFMission()
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   522
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   523
	RebuildTeamInfo()
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   524
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   525
	for i=0, ClansCount-1 do
13104
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   526
		fCaptures[i] = 0
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   527
	end
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   528
15130
13e7d4eccb67 CTF/Control: Fix incomplete hedgehog loop bounds
Wuzzy <Wuzzy2@mail.ru>
parents: 15129
diff changeset
   529
	for h=0, numhhs-1 do
13103
cf2a58dccc4a CTF: Remove tardis and resurrector
Wuzzy <Wuzzy2@mail.ru>
parents: 13019
diff changeset
   530
		-- Hogs are resurrected for free, so this is pointless
cf2a58dccc4a CTF: Remove tardis and resurrector
Wuzzy <Wuzzy2@mail.ru>
parents: 13019
diff changeset
   531
		AddAmmo(hhs[h], amResurrector, 0)
15129
a41b8b154f74 Remove kamikaze and piano strike from CTF and Control
Wuzzy <Wuzzy2@mail.ru>
parents: 15067
diff changeset
   532
		-- Remove suicidal weapons as they might wipe out the team
a41b8b154f74 Remove kamikaze and piano strike from CTF and Control
Wuzzy <Wuzzy2@mail.ru>
parents: 15067
diff changeset
   533
		AddAmmo(hhs[h], amKamikaze, 0)
a41b8b154f74 Remove kamikaze and piano strike from CTF and Control
Wuzzy <Wuzzy2@mail.ru>
parents: 15067
diff changeset
   534
		AddAmmo(hhs[h], amPiano, 0)
13103
cf2a58dccc4a CTF: Remove tardis and resurrector
Wuzzy <Wuzzy2@mail.ru>
parents: 13019
diff changeset
   535
	end
cf2a58dccc4a CTF: Remove tardis and resurrector
Wuzzy <Wuzzy2@mail.ru>
parents: 13019
diff changeset
   536
13104
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   537
	updateScores()
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   538
13113
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   539
	SendStat(siGraphTitle, loc("Score graph"))
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   540
	SendHealthStatsOff()
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   541
	SendRankingStatsOff()
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   542
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   543
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   544
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   545
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   546
function onNewTurn()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   547
13113
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   548
	if gameStarted == true and not gameOver then
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   549
		HandleRespawns()
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   550
	end
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   551
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   552
	local flagsPlaced = 0
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   553
	for i=0, ClansCount-1 do
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   554
		if fSpawnX[i] and fSpawnY[i] then
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   555
			flagsPlaced = flagsPlaced + 1
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   556
		end
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   557
	end
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   558
	if not gameStarted and flagsPlaced == ClansCount then
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   559
		StartTheGame()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   560
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   561
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   562
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   563
function onEndTurn()
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   564
	 -- if the game hasn't started yet, keep track of where we are gonna put the flags on turn end
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   565
	if not gameStarted and CurrentHedgehog ~= nil then
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   566
		local clan = GetHogClan(CurrentHedgehog)
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   567
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   568
		if GetX(CurrentHedgehog) and not fSpawnX[clan] then
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   569
			fSpawnX[clan] = GetX(CurrentHedgehog)
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   570
			fSpawnY[clan] = GetY(CurrentHedgehog)
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   571
		end
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   572
	end
13113
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   573
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   574
	if gameStarted == true then
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   575
		DrawScores()
75afd374b764 CTF: Show team scores and score graph in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13112
diff changeset
   576
	end
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   577
end
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   578
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   579
function onGameTick()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   580
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   581
	for i = 0, ClansCount-1 do
13106
115d7438aa3d CTF: Dumb out-commented code
Wuzzy <Wuzzy2@mail.ru>
parents: 13104
diff changeset
   582
		if fThief[i] ~= nil then
115d7438aa3d CTF: Dumb out-commented code
Wuzzy <Wuzzy2@mail.ru>
parents: 13104
diff changeset
   583
			fThiefX[i] = GetX(fThief[i])
115d7438aa3d CTF: Dumb out-commented code
Wuzzy <Wuzzy2@mail.ru>
parents: 13104
diff changeset
   584
			fThiefY[i] = GetY(fThief[i])
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   585
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   586
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   587
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   588
	if gameStarted == true and not gameOver then
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   589
		HandleCircles()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   590
		if CurrentHedgehog ~= nil then
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   591
			CheckFlagProximity()
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   592
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   593
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   594
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   595
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   596
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   597
function onGearResurrect(gear)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   598
13110
efcdf31684ca CTF: Drop flag when carrier uses piano strike
Wuzzy <Wuzzy2@mail.ru>
parents: 13109
diff changeset
   599
	if GetGearType(gear) == gtHedgehog then
15788
acf70c44065b Use the singular 'they' in code comments, where it makes sense
Wuzzy <Wuzzy2@mail.ru>
parents: 15252
diff changeset
   600
		-- mark the flag thief as dead if they needed a respawn
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   601
		for i = 0, ClansCount-1 do
13110
efcdf31684ca CTF: Drop flag when carrier uses piano strike
Wuzzy <Wuzzy2@mail.ru>
parents: 13109
diff changeset
   602
			if gear == fThief[i] then
efcdf31684ca CTF: Drop flag when carrier uses piano strike
Wuzzy <Wuzzy2@mail.ru>
parents: 13109
diff changeset
   603
				FlagThiefDead(gear)
efcdf31684ca CTF: Drop flag when carrier uses piano strike
Wuzzy <Wuzzy2@mail.ru>
parents: 13109
diff changeset
   604
			end
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   605
		end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   606
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   607
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   608
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   609
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   610
function InABetterPlaceNow(gear)
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   611
	for h = 0, (numhhs-1) do
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   612
		if gear == hhs[h] then
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   613
			for i = 0, ClansCount-1 do
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   614
				if gear == fThief[i] then
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   615
					FlagThiefDead(gear)
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   616
				end
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   617
			end
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   618
			hhs[h] = nil
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   619
		end
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   620
	end
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   621
end
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   622
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   623
function onHogHide(gear)
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   624
	 InABetterPlaceNow(gear)
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   625
end
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   626
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   627
function onHogRestore(gear)
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   628
	for i = 0, (numhhs-1) do
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   629
		if (hhs[i] == nil) then
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   630
			hhs[i] = gear
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   631
			break
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   632
		end
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   633
	end
15252
515a4a317e52 CTF: Fix clan not winning if enemy hog was time-travelling
Wuzzy <Wuzzy2@mail.ru>
parents: 15130
diff changeset
   634
	if gameOver and GetHogClan(gear) ~= winningClan then
515a4a317e52 CTF: Fix clan not winning if enemy hog was time-travelling
Wuzzy <Wuzzy2@mail.ru>
parents: 15130
diff changeset
   635
		SetEffect(gear, heResurrectable, 0)
515a4a317e52 CTF: Fix clan not winning if enemy hog was time-travelling
Wuzzy <Wuzzy2@mail.ru>
parents: 15130
diff changeset
   636
		SetHealth(gear, 0)
515a4a317e52 CTF: Fix clan not winning if enemy hog was time-travelling
Wuzzy <Wuzzy2@mail.ru>
parents: 15130
diff changeset
   637
	end
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   638
end
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   639
13104
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   640
function onHogAttack(ammoType)
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   641
	if not gameStarted and ammoType == amTardis then
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   642
		local i = GetHogClan(CurrentHedgehog)
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   643
		fSpawnX[i] = GetX(CurrentHedgehog)
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   644
		fSpawnY[i] = GetY(CurrentHedgehog)
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   645
	end
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   646
end
5819
e23ced69e03d Add support for more players.
mikade
parents: 5277
diff changeset
   647
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   648
function onGearAdd(gear)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   649
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   650
	if GetGearType(gear) == gtHedgehog then
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   651
		hhs[numhhs] = gear
13115
64d84011a48e CTF: Write hog with most captures in stats screen
Wuzzy <Wuzzy2@mail.ru>
parents: 13114
diff changeset
   652
		capturesPerHog[gear] = 0
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   653
		numhhs = numhhs + 1
7838
5c2337f8dbb2 Issue #443 - change in syntax for effects
nemo
parents: 5827
diff changeset
   654
		SetEffect(gear, heResurrectable, 1)
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   655
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
   656
	elseif GetGearType(gear) == gtPiano then
13111
10c914738f22 CTF: Allow to be played with more than 2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13110
diff changeset
   657
		for i = 0, ClansCount-1 do
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
   658
			if CurrentHedgehog == fThief[i] then
13110
efcdf31684ca CTF: Drop flag when carrier uses piano strike
Wuzzy <Wuzzy2@mail.ru>
parents: 13109
diff changeset
   659
				FlagThiefDead(CurrentHedgehog)
5277
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
   660
			end
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
   661
		end
09beef0752ab PianoStrike exploit fix for Capture The Flag.
mikade
parents: 4662
diff changeset
   662
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   663
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   664
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   665
end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   666
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   667
function onGearDelete(gear)
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   668
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   669
	if GetGearType(gear) == gtHedgehog then
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5821
diff changeset
   670
		InABetterPlaceNow(gear)
13104
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   671
	elseif GetGearType(gear) == gtKamikaze and not gameStarted then
e0ec37c8104d CTF: Fix Lua errors when using kamikaze or tardis
Wuzzy <Wuzzy2@mail.ru>
parents: 13103
diff changeset
   672
		local i = GetHogClan(CurrentHedgehog)
13109
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   673
		if i <= 1 then
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   674
			fSpawnX[i] = GetX(CurrentHedgehog)
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   675
			fSpawnY[i] = GetY(CurrentHedgehog)
59ebdb80d693 Capture the Flag: Fix many Lua errors when playing with >2 clans
Wuzzy <Wuzzy2@mail.ru>
parents: 13106
diff changeset
   676
		end
4662
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   677
	end
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   678
63aafc9c2a81 Add a bunch of lua from mikade, update translation files
mikade+nemo
parents:
diff changeset
   679
end