share/hedgewars/Data/Maps/ClimbHome/map.lua
author Wuzzy <Wuzzy2@mail.ru>
Fri, 07 Jun 2019 15:09:42 +0200
changeset 15135 13e7d4eccb67
parent 14945 8b848c2939da
child 15506 5a30396f8fb2
permissions -rw-r--r--
CTF/Control: Fix incomplete hedgehog loop bounds
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     1
HedgewarsScriptLoad("/Scripts/Locale.lua")
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     2
HedgewarsScriptLoad("/Scripts/Utils.lua")
10810
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
     3
HedgewarsScriptLoad("/Scripts/Params.lua")
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     4
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     5
local hTag = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     6
local hTagHeight = 33000
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     7
local tTag = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     8
local rTag = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     9
local startTime = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    10
local MaxHeight = 32640
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    11
local RecordHeight = 33000
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    12
local RecordHeightHogName = nil
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    13
local Fire = {}
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    14
--local BoomFire = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    15
local HH = {}
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    16
local totalHedgehogs = 0
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    17
local deadHedgehogs = 0
10632
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
    18
local currTeam = ''
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
    19
local teams = {}
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    20
local teamScoreStats = {}
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    21
local teamBests = {}
11640
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
    22
local teamTimes = {}
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    23
local MrMine -- in honour of sparkle's first arrival in the cabin
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    24
local YouWon = false
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    25
local YouLost = false
10580
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
    26
local HogsAreInvulnerable = false
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    27
local WaterRise = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    28
local Cake = nil
13160
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
    29
local CakeWarning = false
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
    30
local CakeFireWarning = false
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    31
local CakeTries = 0
10810
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    32
local addCake = true
13160
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
    33
local takeASeat = false
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    34
local Stars = {}
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    35
local jokeAwardNavy = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    36
local jokeAwardSpeed = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    37
local jokeAwardDamage = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    38
local recordBroken = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    39
local dummyHog = nil
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
    40
local dummySkip = 0
10810
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    41
local baseWaterSpeed = 2
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    42
local waterSpeed = 0
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    43
local waterAccel = 0
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    44
local delayHeight = 32000
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    45
local delayTime = 0
10824
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    46
local airMineX = {}
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    47
local airMineY = {}
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    48
local airMine = {}
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    49
local init = true
12658
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    50
local multiplayerVictoryDelay = -1
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    51
local multiplayerWinningHogs = {}
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    52
local multiplayerWins = 0
12759
c7224d202e8b 2nd try... just shortcircuit most of onGameTick20 when we are between turns.
nemo
parents: 12758
diff changeset
    53
local racing = false
12658
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    54
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    55
-- Placement positions of winning hogs
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    56
local victoryPosses = { }
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    57
do
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    58
    local m = 0
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    59
    for y=108, 39, -32 do
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    60
        for x=1820+m, 1972-m, 22 do
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    61
            table.insert(victoryPosses, {x=x, y=y})
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    62
        end
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    63
        m = m + 32
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    64
    end
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
    65
end
10810
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    66
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    67
function onParameters()
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    68
    parseParams()
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    69
10811
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    70
    if params["speed"] ~= nil then
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    71
        baseWaterSpeed = params["speed"]
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    72
    end
10812
38dc8445d7a7 fix typo
nemo
parents: 10811
diff changeset
    73
    if params["accel"] ~= nil then
10811
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    74
        waterAccel = params["accel"]
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    75
        if waterAccel ~= 0 then waterAccel = div(32640000,waterAccel) end
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    76
    end
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    77
    if params["delaytime"] ~= nil then
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    78
        delayTime = params["delaytime"]
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    79
    end
11618
66880a42c2d7 Fix typo
unC0Rr
parents: 11067
diff changeset
    80
    if params["delayheight"] ~= nil then
10811
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    81
        delayHeight = 32768-params["delayheight"]
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    82
    end
10810
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    83
    if params["nocake"] ~= nil then addCake = false end
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
    84
end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    85
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    86
function onGameInit()
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    87
    -- Ensure people get same map for same theme
13755
110d6c1e817f Lua: Rename globals: NoPointX→NO_CURSOR, cMaxTurnTime→MAX_TURN_TIME, cMaxHogHealth→MAX_HOG_HEALTH
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
    88
    TurnTime = MAX_TURN_TIME
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    89
    CaseFreq = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    90
    Explosives = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    91
    MineDudPercent = 0
10598
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
    92
    EnableGameFlags(gfOneClanMode)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    93
    DisableGameFlags(gfBottomBorder+gfBorder)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    94
    --This reduced startup time by only about 15% and looked ugly
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    95
    --EnableGameFlags(gfDisableLandObjects) 
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    96
    -- force seed instead.  Some themes will still be easier, but at least you won't luck out on the same theme
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    97
    Seed = ClimbHome
12084
8f222872d432 Disable SD for a couple of scripts and mission maps
Wuzzy <almikes@aol.com>
parents: 12082
diff changeset
    98
    -- Disable Sudden Death
8f222872d432 Disable SD for a couple of scripts and mission maps
Wuzzy <almikes@aol.com>
parents: 12082
diff changeset
    99
    WaterRise = 0
8f222872d432 Disable SD for a couple of scripts and mission maps
Wuzzy <almikes@aol.com>
parents: 12082
diff changeset
   100
    HealthDecrease = 0
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   101
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   102
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   103
function onGearAdd(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   104
    if GetGearType(gear) == gtHedgehog then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   105
        HH[gear] = 1
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   106
        totalHedgehogs = totalHedgehogs + 1
10632
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
   107
        teams[GetHogTeamName(gear)] = 1
10824
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   108
    elseif init and GetGearType(gear) == gtAirMine then
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   109
        airMine[gear] = 1
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   110
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   111
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   112
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   113
function onGearDelete(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   114
    if gear == MrMine then
13648
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13175
diff changeset
   115
        AddCaption(loc("Once you set off the proximity trigger, Mr. Mine is not your friend"), capcolDefault, capgrpMessage2)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   116
        MrMine = nil
12832
b7453ae2c44d Fix incorrect check for cake gear type in ClimbHome
Wuzzy <Wuzzy2@mail.ru>
parents: 12831
diff changeset
   117
    elseif GetGearType(gear) == gtCake then
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   118
        Cake = nil
13160
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   119
        CakeWarning = false
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   120
    elseif GetGearType(gear) == gtHedgehog then
11067
c632b47b8ff0 Trying to get these scripts to behave properly, still WIP though.
nemo
parents: 10824
diff changeset
   121
	onGameTick20()
c632b47b8ff0 Trying to get these scripts to behave properly, still WIP though.
nemo
parents: 10824
diff changeset
   122
	onGearDamage(gear, 0)
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   123
        HH[gear] = nil
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   124
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   125
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   126
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   127
function onGameStart()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   128
    --SetClanColor(ClansCount-1, 0x0000ffff) appears to be broken
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   129
    SendHealthStatsOff()
14480
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   130
    local recordInfo = ""
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   131
    if isSinglePlayer then
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   132
        recordInfo = getReadableChallengeRecord("Highscore")
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   133
    end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   134
    ShowMission(loc("Climb Home"),
12082
ce3860c82c8b Rewrite 2nd line of mission panel of most missions for consistency
Wuzzy <almikes@aol.com>
parents: 11894
diff changeset
   135
                loc("Challenge"),
14480
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   136
                loc("You are far from home, and the water is rising, climb up as high as you can!|Your score will be based on your height.")
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   137
                .. "|" .. recordInfo,
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   138
                -amRope, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   139
    local x = 1818
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   140
    for h,i in pairs(HH) do
10598
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   141
        if h ~= nil then
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   142
            -- SetGearPosition(h,x,32549)
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   143
            SetGearPosition(h,x,108)
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   144
            SetHealth(h,1)
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   145
            if x < 1978 then x = x+32 else x = 1818 end
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   146
            if GetEffect(h,heInvulnerable) == 0 then
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   147
                SetEffect(h,heInvulnerable,1)
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   148
            else
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   149
                HogsAreInvulnerable = true
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   150
            end
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   151
            SetState(h,bor(GetState(h),gstInvisible))
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   152
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   153
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   154
-- 1925,263 - Mr. Mine position
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   155
    MrMine = AddGear(1925,263,gtMine,0,0,0,0)
13028
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   156
    for i=0, TeamsCount-1 do
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   157
        SetTeamLabel(GetTeamName(i), "0")
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   158
    end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   159
end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   160
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   161
function onAmmoStoreInit()
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   162
    SetAmmo(amRope, 9, 0, 0, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   163
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   164
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   165
function onNewTurn()
10824
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   166
    if init then
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   167
        init = false
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   168
        for a,i in pairs(airMine) do
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   169
            x,y = GetGearPosition(a)
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   170
            airMineX[a] = x
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   171
            airMineY[a] = y
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   172
        end
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   173
    else
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   174
        for a,i in pairs(airMine) do
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   175
            local x,y = GetGearPosition(a)
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   176
            if not x or airMineX[a] ~= x or airMineY[a] ~= y then
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   177
                DeleteGear(a)
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   178
                AddGear(airMineX[a],airMineY[a], gtAirMine, gsttmpFlag, 0, 0, 0)
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   179
            end
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   180
        end
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   181
    end
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   182
        
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   183
    startTime = GameTime
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   184
    --disable to preserve highest over multiple turns
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   185
    --will need to change water check too ofc
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   186
    MaxHeight = 32640
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   187
    hTagHeight = 33000
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   188
    SetWaterLine(32768)
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   189
    YouWon = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   190
    YouLost = false
13160
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   191
    takeASeat = false
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   192
    recordBroken = false
10632
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
   193
    currTeam = GetHogTeamName(CurrentHedgehog)
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   194
    if CurrentHedgehog ~= nil then
12658
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   195
        if CurrentHedgehog ~= dummyHog or multiplayerWinningHogs[CurrentHedgehog] == true then
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   196
            SetGearPosition(CurrentHedgehog, 1951,32640)
12659
26b0d3b76dea ClimbHome: Make sure hog faces left on turn start
Wuzzy <almikes@aol.com>
parents: 12658
diff changeset
   197
            HogTurnLeft(CurrentHedgehog, true)
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   198
            if not HogsAreInvulnerable then SetEffect(CurrentHedgehog,heInvulnerable,0) end
10598
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   199
            AddVisualGear(1951,32640,vgtExplosion,0,false)
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   200
            SetState(CurrentHedgehog,band(GetState(CurrentHedgehog),bnot(gstInvisible)))
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   201
            SetWeapon(amRope)
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   202
        else
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   203
            dummySkip = GameTime+1
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   204
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   205
    end
12658
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   206
    for hog, _ in pairs(multiplayerWinningHogs) do
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   207
        SetEffect(hog, heInvulnerable, 1)
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   208
    end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   209
    for f,i in pairs(Fire) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   210
        DeleteGear(f)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   211
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   212
    for s,i in pairs(Stars) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   213
        DeleteVisualGear(s)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   214
        Stars[s] = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   215
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   216
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   217
    if CurrentHedgehog ~= dummyHog then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   218
        for i = 0,12 do
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   219
            flame = AddGear(2000+i*2,308, gtFlame, gsttmpFlag,  0, 0, 0)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   220
            SetTag(flame, 999999+i)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   221
            Fire[flame]=1
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   222
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   223
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   224
    if Cake ~= nil then DeleteGear(Cake) end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   225
    CakeTries = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   226
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   227
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   228
--function onGearDelete(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   229
--    if gear == WaterRise and MaxHeight > 500 and CurrentHedgehog ~= nil and band(GetState(CurrentHedgehog),gstHHDriven) ~= 0 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   230
--        WaterRise = AddGear(0,0,gtWaterUp, 0, 0, 0, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   231
--    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   232
--end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   233
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   234
function FireBoom(x,y,d) -- going to add for rockets too
13160
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   235
    PlaySound(sndExplosion)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   236
    AddVisualGear(x,y,vgtExplosion,0,false)
10580
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   237
    -- should approximate circle by removing corners
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   238
    --if BoomFire == nil then BoomFire = {} end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   239
    for i = 0,50 do
10580
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   240
	fx = GetRandom(d)-div(d,2)
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   241
	fy = GetRandom(d)-div(d,2)
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   242
	if fx<0 then
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   243
	   fdx = -5000-GetRandom(3000)
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   244
	else
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   245
	   fdx = 5000+GetRandom(3000)
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   246
	end
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   247
	if fy<0 then
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   248
	   fdy = -5000-GetRandom(3000)
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   249
	else
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   250
	   fdy = 5000+GetRandom(3000)
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   251
	end
17560eb73b4c Reset max team health after script may have screwed with it on start. Maybe a script max health reset function could be useful too. Set climbhome hogs to invulnerable while not their turn if needed to avoid accidental mine/dead hog damage. Tweak cake fire boom a bit.
nemo
parents: 10413
diff changeset
   252
        flame = AddGear(x+fx, y+fy, gtFlame, gsttmpFlag,  fdx, fdy, 0)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   253
        SetTag(flame, 999999+i)
10589
98ea597e5cd9 expose FlightTime to lua, disable in-air flame harming moving hogs ☹ aaaand override that in ClimbHome ☺
nemo
parents: 10587
diff changeset
   254
        SetFlightTime(flame, 0)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   255
        Fire[flame]=1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   256
--        BoomFire[flame]=1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   257
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   258
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   259
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   260
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   261
function onGameTick20()
10824
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   262
    local x,y
12758
327f71313e04 this should probably sidestep that thing unc0rr keeps bringing up. untested. but then, I've never had it happen. I think what happens is onGameTick20 is called in same tick as onNewTurn and before it...
nemo
parents: 12660
diff changeset
   263
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   264
    if math.random(20) == 1 then AddVisualGear(2012,56,vgtSmoke,0,false) end
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   265
    if CurrentHedgehog == dummyHog and dummySkip ~= 0 and dummySkip < GameTime then
13175
98a0edb4bb5a Lua API: Add SkipTurn() to replace ParseCommand("skip")
Wuzzy <Wuzzy2@mail.ru>
parents: 13160
diff changeset
   266
        SkipTurn()
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   267
        dummySkip = 0
10585
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   268
    end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   269
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   270
    --if BoomFire ~= nil then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   271
    --    for f,i in pairs(BoomFire) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   272
    --        if band(GetState(f),gstCollision~=0) then DeleteGear(f) end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   273
    --    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   274
    --    BoomFire = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   275
    --end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   276
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   277
    for s,i in pairs(Stars) do
13691
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   278
        local _, Y = GetVisualGearValues(s)
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   279
        if Y ~= nil and Y > WaterLine + 500 then
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   280
            DeleteVisualGear(s)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   281
            Stars[s] = nil
13691
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   282
        elseif Y == nil then
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   283
            Stars[s] = nil
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   284
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   285
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   286
12658
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   287
    -- This will be executed if a player reached home in multiplayer
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   288
    if multiplayerVictoryDelay > 0 then
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   289
        multiplayerVictoryDelay = multiplayerVictoryDelay - 20
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   290
        if multiplayerVictoryDelay <= 0 then
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   291
            -- If delay's over, the game will continue with the next hog
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   292
            if CurrentHedgehog then
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   293
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   294
                multiplayerWinningHogs[CurrentHedgehog] = true
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   295
                multiplayerWins = multiplayerWins + 1
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   296
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   297
                local victoryX, victoryY
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   298
                if multiplayerWins <= #victoryPosses then
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   299
                    victoryX, victoryY = victoryPosses[multiplayerWins].x, victoryPosses[multiplayerWins].y
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   300
                else
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   301
                    victoryX, victoryY = victoryPosses[#victoryPosses].x, victoryPosses[#victoryPosses].y
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   302
                end
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   303
                SetGearPosition(CurrentHedgehog, victoryX, victoryY)
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   304
                SetEffect(CurrentHedgehog, heInvulnerable, 1)
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   305
                SetHealth(CurrentHedgehog, 1)
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   306
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   307
                if (deadHedgehogs + multiplayerWins) >= totalHedgehogs then
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   308
                    makeFinalMultiPlayerStats()
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   309
                    EndGame()
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   310
                    onAchievementsDeclaration()
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   311
                else
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   312
                    EndTurn(true)
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   313
                    SetInputMask(0xFFFFFFFF)
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   314
                end
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   315
                return
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   316
            end
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   317
        end
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   318
    end
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   319
12830
b986a8b8cd56 just merging if statements
nemo
parents: 12765
diff changeset
   320
    if CurrentHedgehog ~= nil then
b986a8b8cd56 just merging if statements
nemo
parents: 12765
diff changeset
   321
        x,y = GetGearPosition(CurrentHedgehog)
b986a8b8cd56 just merging if statements
nemo
parents: 12765
diff changeset
   322
        if Cake ~= nil then
b986a8b8cd56 just merging if statements
nemo
parents: 12765
diff changeset
   323
            local cx,cy = GetGearPosition(Cake)
12831
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   324
            if y < cy-1500 then DeleteGear(Cake) end
12830
b986a8b8cd56 just merging if statements
nemo
parents: 12765
diff changeset
   325
13160
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   326
            if Cake ~= nil and GetHealth(Cake) < 999980 then
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   327
                if not CakeWarning and gearIsInCircle(CurrentHedgehog,cx,cy,1350) then
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   328
                    AddCaption(loc("Warning: Fire cake detected"))
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   329
                    CakeWarning = true
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   330
                end
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   331
                if gearIsInCircle(CurrentHedgehog,cx,cy,450) then
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   332
                    if not CakeFireWarning then
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   333
                        AddCaption(loc("Don't touch the flames!"))
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   334
                        CakeFireWarning = true
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   335
                    end
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   336
                    FireBoom(cx,cy,200) -- todo animate
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   337
                    DeleteGear(Cake)
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   338
                end
12831
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   339
            end
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   340
        end
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   341
        if band(GetState(CurrentHedgehog),gstHHDriven) == 0 then
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   342
            for f,i in pairs(Fire) do -- takes too long to fall otherwise
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   343
                DeleteGear(f)
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   344
            end
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   345
            if Cake ~= nil then
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   346
                DeleteGear(Cake)
12830
b986a8b8cd56 just merging if statements
nemo
parents: 12765
diff changeset
   347
            end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   348
        end
12830
b986a8b8cd56 just merging if statements
nemo
parents: 12765
diff changeset
   349
     end
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   350
    
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   351
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   352
    if CurrentHedgehog ~= nil and TurnTimeLeft > 0 and band(GetState(CurrentHedgehog),gstHHDriven) ~= 0 then
10810
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
   353
        if MaxHeight < delayHeight and
13755
110d6c1e817f Lua: Rename globals: NoPointX→NO_CURSOR, cMaxTurnTime→MAX_TURN_TIME, cMaxHogHealth→MAX_HOG_HEALTH
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
   354
           TurnTimeLeft<(MAX_TURN_TIME-delayTime) and
10810
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
   355
            MaxHeight > 286 and WaterLine > 286 then
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
   356
            if waterAccel ~= 0 then
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
   357
                SetWaterLine(WaterLine-(baseWaterSpeed+div(getActualHeight(MaxHeight)*100,waterAccel)))
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
   358
            else
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
   359
                SetWaterLine(WaterLine-baseWaterSpeed)
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
   360
            end
931dd8f42763 add some config params - speed,accel,delaytime,delayheight,nocake. water rise speed, water rise acceleration, time delay from start of turn for water rise, height delay for same, and disable cake. also set start boulder to indestructible
nemo
parents: 10697
diff changeset
   361
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   362
        if y > 0 and y < 30000 and MaxHeight > 286 and math.random(y) < 500 then
13691
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   363
            local s = AddVisualGear(0, 0, vgtStraightShot, 0, false)
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   364
            if s then
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   365
                local c = div(250000,y)
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   366
                if c > 255 then c = 255 end
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   367
                c = c * 0x10000 + 0xFF0000FF
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   368
                SetVisualGearValues(s,
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   369
                    math.random(2048), -5000, 0, -1-(1/y*1000),
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   370
                    math.random(360),
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   371
                    0,
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   372
                    999999999, -- frameticks
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   373
                    sprStar, -- star
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   374
                    0, c)
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   375
                    --,  0xFFCC00FF) -- could be fun to make colour shift as you rise...
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   376
                Stars[s] = 1
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   377
            end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   378
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   379
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   380
        local vx, vy = GetGearVelocity(CurrentHedgehog)
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   381
        local distanceFromWater = WaterLine - y
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   382
	
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   383
        --[[ check joke awards ]]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   384
        -- navy award: when distance from main map is over 1000
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   385
        local navyDistance = 1250
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   386
        if x < -navyDistance or x > LAND_WIDTH+navyDistance then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   387
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   388
            local dist = 0
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   389
            if jokeAwardNavy == nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   390
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   391
            else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   392
                if x < 0 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   393
                    dist = math.abs(x)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   394
                else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   395
                    dist = x - LAND_WIDTH
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   396
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   397
                if dist > jokeAwardNavy.distance then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   398
                    awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   399
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   400
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   401
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   402
                jokeAwardNavy = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   403
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   404
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   405
                    distance = dist
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   406
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   407
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   408
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   409
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   410
        -- Speed award for largest distance from water
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   411
        if distanceFromWater > 3000 and WaterLine < 32000 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   412
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   413
            if jokeAwardSpeed == nil or distanceFromWater > jokeAwardSpeed.distance then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   414
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   415
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   416
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   417
                jokeAwardSpeed = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   418
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   419
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   420
                    distance = distanceFromWater
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   421
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   422
            end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   423
        end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   424
14480
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   425
        local rawFinishTime = GameTime-startTime
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   426
        local finishTime = rawFinishTime/1000
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   427
        local roundedFinishTime = math.ceil(math.floor(finishTime+0.5))
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   428
        if isSinglePlayer then
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   429
            if distanceFromWater < 0 and not YouLost and not YouWon then
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   430
                makeSinglePlayerLoserStats()
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   431
                YouLost = true
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   432
            end
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   433
            -- FIXME: Hog is also in winning box if it just walks into the chair from the left, touching it. Intentional?
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   434
            if not YouWon and not YouLost and gearIsInBox(CurrentHedgehog, 1920, 252, 50, 50) then
14469
ead8928a59f8 Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents: 13755
diff changeset
   435
                SaveMissionVar("Won", "true")
13648
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13175
diff changeset
   436
                AddCaption(loc("Victory!"), capcolDefault, capgrpGameState)
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   437
                ShowMission(loc("Climb Home"),
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   438
                            loc("Made it!"),
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   439
                            string.format(loc("Ahhh, home, sweet home. Made it in %d seconds."), roundedFinishTime),
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   440
                            -amRope, 0)
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   441
                PlaySound(sndVictory,CurrentHedgehog)
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   442
                SendStat(siGameResult, loc("You have beaten the challenge!"))
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   443
                SendStat(siGraphTitle, loc("Your height over time"))
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   444
                SendStat(siCustomAchievement, string.format(loc("%s reached home in %.3f seconds. Congratulations!"), GetHogName(CurrentHedgehog), finishTime))
14480
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   445
                updateChallengeRecord("TimeRecord", rawFinishTime, false)
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   446
                SendStat(siCustomAchievement, string.format(loc("%s bravely climbed up to a dizzy height of %d to reach home."), GetHogName(CurrentHedgehog), getActualHeight(RecordHeight)))
14480
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   447
                updateChallengeRecord("Highscore", getActualHeight(RecordHeight))
14583
50f511588635 Outsource commonly used words in siPointType to QTfrontend
Wuzzy <Wuzzy2@mail.ru>
parents: 14480
diff changeset
   448
                SendStat(siPointType, "!TIME")
50f511588635 Outsource commonly used words in siPointType to QTfrontend
Wuzzy <Wuzzy2@mail.ru>
parents: 14480
diff changeset
   449
                SendStat(siPlayerKills, tostring(rawFinishTime), GetHogTeamName(CurrentHedgehog))
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   450
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   451
                EndGame()
14933
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14595
diff changeset
   452
                SetState(CurrentHedgehog, gstWinner)
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   453
                onAchievementsDeclaration()
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   454
                YouWon = true
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   455
            end
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   456
        else
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   457
            if distanceFromWater < 0 and not YouLost and not YouWon then
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   458
                makeMultiPlayerLoserStat(CurrentHedgehog)
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   459
                deadHedgehogs = deadHedgehogs + 1
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   460
                YouLost = true
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   461
                if deadHedgehogs >= totalHedgehogs then
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   462
                    makeFinalMultiPlayerStats()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   463
                    EndGame()
11628
515d2d38ab8b Declare achievements alongwith EndGame call, since it would skip SendStats
unc0rr
parents: 11620
diff changeset
   464
                    onAchievementsDeclaration()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   465
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   466
            end
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   467
            -- Check victory
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   468
            if not YouWon and not YouLost and gearIsInBox(CurrentHedgehog, 1920, 252, 50, 50) and
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   469
                    -- Delay victory if MrMine is triggered
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   470
                    (not MrMine or (MrMine and band(GetState(MrMine), gstAttacking) == 0)) then
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   471
                -- Player managed to reach home in multiplayer.
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   472
                -- Stop hog, disable controls, celebrate victory and continue the game after 4 seconds.
13648
690cc84e9fd6 Use capcolDefault in Lua scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13175
diff changeset
   473
                AddCaption(string.format(loc("%s climbed home in %d seconds!"), GetHogName(CurrentHedgehog), roundedFinishTime), capcolDefault, capgrpGameState)
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   474
                SendStat(siCustomAchievement, string.format(loc("%s (%s) reached home in %.3f seconds."), GetHogName(CurrentHedgehog), GetHogTeamName(CurrentHedgehog), finishTime))
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   475
                makeMultiPlayerWinnerStat(CurrentHedgehog)
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   476
                PlaySound(sndVictory, CurrentHedgehog)
12918
20e627c1ac20 ClimbHome, Sniper Rifle training: Unselect weapon after victory
Wuzzy <Wuzzy2@mail.ru>
parents: 12832
diff changeset
   477
		SetWeapon(amNothing)
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   478
                SetGearMessage(CurrentHedgehog, band(GetGearMessage(CurrentHedgehog), bnot(gmLeft+gmRight+gmUp+gmDown+gmHJump+gmLJump+gmPrecise)))
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   479
                SetInputMask(0x00)
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   480
                -- TODO: Add stupid winner grin.
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   481
                multiplayerVictoryDelay = 4000
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   482
                YouWon = true
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   483
            end
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   484
        end
10598
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   485
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   486
        if GameTime % 500 == 0 then
11894
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   487
            if not isSinglePlayer then
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   488
	        for t,i in pairs(teams) do
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   489
                    if currTeam == t then
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   490
                        SendStat(siClanHealth, tostring(getActualHeight(y)), t)
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   491
                    else
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   492
                        SendStat(siClanHealth, '0', t)
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   493
                    end
10632
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
   494
                end
12765
5acf6b91df76 you know what... I think everything would have been fine if we'd simply required all this hog stuff to be in the same block...
nemo
parents: 12759
diff changeset
   495
            else
11894
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   496
                SendStat(siClanHealth, tostring(getActualHeight(y)), GetHogTeamName(CurrentHedgehog))
10632
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
   497
            end
13160
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   498
            -- If player is inside home, tell player to take a seat.
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   499
            if not takeASeat and gearIsInBox(CurrentHedgehog, 1765, 131, 244, 189) then
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   500
                AddCaption(loc("Welcome home! Please take a seat"))
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   501
                takeASeat = true
25de976a7b9a ClimeHome: Show messages when cake is nearby and when reaching home
Wuzzy <Wuzzy2@mail.ru>
parents: 13028
diff changeset
   502
            end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   503
    
12831
42003e235a46 remove some more test redundancy and restore a missing and important nil check
nemo
parents: 12830
diff changeset
   504
            if addCake and CakeTries < 10 and y < 32600 and y > 3000 and Cake == nil then 
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   505
                -- doing this just after the start the first time to take advantage of randomness sources
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   506
                -- Pick a clear y to start with
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   507
                if y > 31000 then cy = 24585 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   508
                   y > 28000 then cy = 21500 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   509
                   y > 24000 then cy = 19000 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   510
                   y > 21500 then cy = 16000 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   511
                   y > 19000 then cy = 12265 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   512
                   y > 16000 then cy =  8800 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   513
                   y > 12000 then cy =  5700 else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   514
                   cy = 400 end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   515
                Cake = AddGear(GetRandom(2048), cy, gtCake, 0, 0, 0, 0)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   516
                SetHealth(Cake,999999)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   517
                CakeTries = CakeTries + 1 
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   518
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   519
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   520
            if (y > 286) or (y < 286 and MaxHeight > 286) then
11640
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   521
                if MaxHeight > 286 and y <= 286 then
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   522
                    -- wow, reached top
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   523
                    local teamName = GetHogTeamName(CurrentHedgehog)
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   524
                    if teamTimes[teamName] == nil or teamTimes[teamName] > GameTime - startTime then 
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   525
                        teamTimes[teamName] = GameTime - startTime 
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   526
                    end
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   527
                    MaxHeight = 286
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   528
                end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   529
                if y < MaxHeight and y > 286 then MaxHeight = y end
13028
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   530
                -- New maximum height of this turn?
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   531
                if MaxHeight < hTagHeight then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   532
                    hTagHeight = MaxHeight
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   533
                    if hTag ~= nil then DeleteVisualGear(hTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   534
                    hTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
13028
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   535
                    local score = 32640-hTagHeight
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   536
                    -- snagged from space invasion
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   537
                    SetVisualGearValues (
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   538
                            hTag,        --id
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   539
                            -(ScreenWidth/2) + 40, --xoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   540
                            ScreenHeight - 60, --yoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   541
                            0,          --dx
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   542
                            0,          --dy
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   543
                            1.1,        --zoom
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   544
                            1,          --~= 0 means align to screen
13691
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   545
                            nil,        --frameticks
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   546
            -- 116px off bottom for lowest rock, 286 or so off top for position of chair
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   547
            -- 32650 is "0"
13028
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   548
                            score,    --value
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   549
                            99999999999,--timer
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   550
                            GetClanColor(GetHogClan(CurrentHedgehog))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   551
                            )
13028
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   552
                    local team = GetHogTeamName(CurrentHedgehog)
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   553
                    SetTeamLabel(team, math.max(score, teamBests[team] or 0))
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   554
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   555
13028
acba432d34b1 ClimbHome: Show best team heights next to team name
Wuzzy <Wuzzy2@mail.ru>
parents: 12918
diff changeset
   556
                -- New record height?
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   557
                if MaxHeight < RecordHeight then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   558
                    RecordHeight = MaxHeight
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   559
                    local oldName = RecordHeightHogName
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   560
                    RecordHeightHogName = GetHogName(CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   561
                    if oldName == nil then recordBroken = true end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   562
                    if not isSinglePlayer and RecordHeight > 1500 and not recordBroken then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   563
                        recordBroken = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   564
                        AddCaption(string.format(loc("%s has passed the best height of %s!"), RecordHeightHogName, oldName))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   565
                    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   566
                    if not isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   567
                        if rTag ~= nil then DeleteVisualGear(rTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   568
                        rTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   569
                        -- snagged from space invasion
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   570
                        SetVisualGearValues (
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   571
                            rTag,        --id
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   572
                            -(ScreenWidth/2) + 100, --xoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   573
                            ScreenHeight - 60, --yoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   574
                            0,          --dx
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   575
                            0,          --dy
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   576
                            1.1,        --zoom
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   577
                            1,          --~= 0 means align to screen
13691
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   578
                            nil,        --frameticks
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   579
            -- 116px off bottom for lowest rock, 286 or so off top for position of chair
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   580
            -- 32650 is "0"
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   581
                            getActualHeight(RecordHeight),    --value
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   582
                            99999999999,--timer
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   583
                            GetClanColor(GetHogClan(CurrentHedgehog))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   584
                            )
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   585
                    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   586
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   587
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   588
            if MaxHeight > 286 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   589
                if tTag ~= nil then DeleteVisualGear(tTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   590
                tTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   591
                -- snagged from space invasion
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   592
                SetVisualGearValues (
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   593
                    tTag,        --id
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   594
                    -(ScreenWidth/2) + 40, --xoffset
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   595
                    ScreenHeight - 100, --yoffset
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   596
                    0,          --dx
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   597
                    0,          --dy
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   598
                    1.1,        --zoom
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   599
                    1,          --~= 0 means align to screen
13691
3651c63f3c84 Clean up legacy visual gear stuff in ClimbHome, fix star despawn, make stars non-critical
Wuzzy <Wuzzy2@mail.ru>
parents: 13669
diff changeset
   600
                    nil,        --frameticks
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   601
                    (GameTime-startTime)/1000,    --value
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   602
                    99999999999,--timer
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   603
                    0xffffffff
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   604
                    )
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   605
            end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   606
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   607
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   608
end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   609
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   610
function onGearDamage(gear, damage)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   611
    if GetGearType(gear) == gtHedgehog and not YouLost and not YouWon then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   612
        -- Joke award for largest damage to hog
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   613
        local qualifyDamage = 50
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   614
        if (damage >= qualifyDamage) then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   615
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   616
            if jokeAwardDamage == nil or damage > jokeAwardDamage.damage then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   617
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   618
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   619
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   620
                jokeAwardDamage = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   621
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   622
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   623
                    damage = damage
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   624
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   625
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   626
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   627
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   628
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   629
            makeSinglePlayerLoserStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   630
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   631
            deadHedgehogs = deadHedgehogs + 1
12660
913d25669131 ClimbHome: Fix final team scoring 0 if hog took damage
Wuzzy <almikes@aol.com>
parents: 12659
diff changeset
   632
            makeMultiPlayerLoserStat(gear)
12658
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   633
            if (deadHedgehogs + multiplayerWins) >= totalHedgehogs then
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   634
                makeFinalMultiPlayerStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   635
                EndGame()
11628
515d2d38ab8b Declare achievements alongwith EndGame call, since it would skip SendStats
unc0rr
parents: 11620
diff changeset
   636
                onAchievementsDeclaration()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   637
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   638
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   639
        YouLost = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   640
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   641
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   642
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   643
function makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   644
    local m
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   645
    if isSinglePlayer then m = 10 else m = 6 end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   646
    local r = math.random(1,m)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   647
    if r == 1 then text = loc("%s never got the ninja diploma.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   648
    elseif r == 2 then text = loc("You have to move upwards, not downwards, %s!")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   649
    elseif r == 3 then text = loc("%s never wanted to reach for the sky in the first place.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   650
    elseif r == 4 then text = loc("%s should try the rope training mission first.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   651
    elseif r == 5 then text = loc("%s skipped ninja classes.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   652
    elseif r == 6 then text = loc("%s doesn’t really know how to handle a rope properly.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   653
    elseif r == 7 then text = loc("Better luck next time!")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   654
    elseif r == 8 then text = loc("It was all just bad luck!")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   655
    elseif r == 9 then text = loc("Well, that escalated quickly!")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   656
    elseif r == 10 then text = loc("What? Is it over already?") end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   657
    return text
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   658
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   659
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   660
function makeSinglePlayerLoserStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   661
    local actualHeight = getActualHeight(RecordHeight)
14595
c5f18710a184 Remove "loser" messages in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14583
diff changeset
   662
    SendStat(siGameResult, loc("Challenge over!"))
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   663
    SendStat(siGraphTitle, loc("Your height over time"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   664
    local text
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   665
    if actualHeight > 30000 then text = loc("%s was damn close to home.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   666
    elseif actualHeight > 28000 then text = loc("%s was close to home.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   667
    elseif actualHeight > 24265 then text = loc("%s was good, but not good enough.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   668
    elseif actualHeight > 16177 then text = loc("%s managed to pass half of the distance towards home.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   669
    elseif actualHeight > 8088 then text = loc("%s went over a quarter of the way towards home.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   670
    elseif actualHeight > 5100 then text = loc("%s still had a long way to go.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   671
    elseif actualHeight > 2000 then text = loc("%s made it past the hogosphere.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   672
    elseif actualHeight > 1500  then text = loc("%s barely made it past the hogosphere.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   673
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   674
        text = makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   675
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   676
    if actualHeight > 1500 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   677
        SendStat(siCustomAchievement, string.format(text, RecordHeightHogName, actualHeight))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   678
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   679
        SendStat(siCustomAchievement, string.format(text, RecordHeightHogName))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   680
    end
14480
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   681
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14469
diff changeset
   682
    updateChallengeRecord("Highscore", actualHeight)
14583
50f511588635 Outsource commonly used words in siPointType to QTfrontend
Wuzzy <Wuzzy2@mail.ru>
parents: 14480
diff changeset
   683
    SendStat(siPointType, "!POINTS")
12429
b9cc405541c1 Fix various loc() syntax errors in scripts
Wuzzy <almikes@aol.com>
parents: 12397
diff changeset
   684
    SendStat(siPlayerKills, actualHeight, GetHogTeamName(CurrentHedgehog))
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   685
    EndGame()
11628
515d2d38ab8b Declare achievements alongwith EndGame call, since it would skip SendStats
unc0rr
parents: 11620
diff changeset
   686
    onAchievementsDeclaration()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   687
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   688
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   689
function makeMultiPlayerLoserStat(gear)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   690
    local teamName = GetHogTeamName(gear)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   691
    local actualHeight = getActualHeight(MaxHeight)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   692
    if teamBests[teamName] == nil then teamBests[teamName] = actualHeight end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   693
    if teamBests[teamName] < actualHeight then teamBests[teamName] = actualHeight end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   694
    if teamScoreStats[teamName] == nil then teamScoreStats[teamName] = {} end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   695
    table.insert(teamScoreStats[teamName], actualHeight)
10598
9dd0f41d3244 This should probably fix multiplayer desync, but is the result of fiddling while pretty sick/feverish so, needs testing, and the water/scaling stuff is disabled.
nemo
parents: 10593
diff changeset
   696
    --SendStat(siClanHealth, tostring(teamBests[teamName]), teamName)
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   697
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   698
12658
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   699
function makeMultiPlayerWinnerStat(gear)
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   700
    return makeMultiPlayerLoserStat(gear)
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   701
end
1215fd246e08 Climb Home: Fix game getting stuck when player reaches home
Wuzzy <almikes@aol.com>
parents: 12429
diff changeset
   702
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   703
function makeFinalMultiPlayerStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   704
    local ranking = {}
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   705
    for k,v in pairs(teamBests) do
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   706
        table.insert(ranking, {name=k, score=v})
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   707
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   708
    local comp = function(table1, table2)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   709
        if table1.score < table2.score then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   710
            return true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   711
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   712
            return false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   713
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   714
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   715
    table.sort(ranking, comp)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   716
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   717
    local winner = ranking[#ranking]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   718
    local loser = ranking[1]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   719
    SendStat(siGameResult, string.format(loc("%s wins!"), winner.name))
11894
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11640
diff changeset
   720
    SendStat(siGraphTitle, string.format(loc("Height over time")))
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   721
    
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   722
    if winner.score < 1500 then
11067
c632b47b8ff0 Trying to get these scripts to behave properly, still WIP though.
nemo
parents: 10824
diff changeset
   723
        SendStat(siCustomAchievement, string.format(loc("This round’s award for ultimate disappointment goes to: Everyone!")))
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   724
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   725
        if winner.score > 30000 then text = loc("%s (%s) reached for the sky and beyond with a height of %d!")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   726
        elseif winner.score > 24750 then text = loc("%s (%s) was certainly not afraid of heights: Peak height of %d!")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   727
        elseif winner.score > 16500 then text = loc("%s (%s) does not have to feel ashamed for their best height of %d.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   728
        elseif winner.score > 8250 then text = loc("%s (%s) reached a decent peak height of %d.")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   729
        else text = loc("%s (%s) reached a peak height of %d.") end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   730
        SendStat(siCustomAchievement, string.format(text, RecordHeightHogName, winner.name, winner.score))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   731
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   732
        if loser.score < 1500 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   733
            text = makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   734
            SendStat(siCustomAchievement, string.format(text, loser.name))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   735
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   736
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   737
    checkAwards()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   738
    for i = #ranking, 1, -1 do
14583
50f511588635 Outsource commonly used words in siPointType to QTfrontend
Wuzzy <Wuzzy2@mail.ru>
parents: 14480
diff changeset
   739
	SendStat(siPointType, "!POINTS")
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   740
        SendStat(siPlayerKills, tostring(ranking[i].score), ranking[i].name)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   741
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   742
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   743
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   744
function checkAwards()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   745
    if jokeAwardNavy ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   746
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   747
            SendStat(siCustomAchievement, string.format(loc("The Navy greets %s for managing to get in a distance of %d away from the mainland!"), jokeAwardNavy.hogName, jokeAwardNavy.distance))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   748
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   749
            SendStat(siCustomAchievement, string.format(loc("Greetings from the Navy, %s (%s), for being a distance of %d away from the mainland!"), jokeAwardNavy.hogName, jokeAwardNavy.teamName, jokeAwardNavy.distance))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   750
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   751
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   752
    if jokeAwardSpeed ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   753
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   754
            SendStat(siCustomAchievement, string.format(loc("Your hedgehog was panicly afraid of the water and decided to go in a safe distance of %d from it."), jokeAwardSpeed.distance))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   755
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   756
            SendStat(siCustomAchievement, string.format(loc("%s (%s) was panicly afraid of the water and decided to get in a safe distance of %d from it."), jokeAwardSpeed.hogName, jokeAwardSpeed.teamName, jokeAwardSpeed.distance))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   757
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   758
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   759
    if jokeAwardDamage ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   760
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   761
            SendStat(siCustomAchievement, string.format(loc("Ouch! That must have hurt. You mutilated your poor hedgehog hog with %d damage."), jokeAwardDamage.damage))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   762
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   763
            SendStat(siCustomAchievement, string.format(loc("Ouch! That must have hurt. %s (%s) hit the ground with %d damage points."), jokeAwardDamage.hogName, jokeAwardDamage.teamName, jokeAwardDamage.damage))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   764
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   765
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   766
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   767
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   768
function getActualHeight(height)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   769
    return 32640-height
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   770
end
11620
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11618
diff changeset
   771
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11618
diff changeset
   772
function onAchievementsDeclaration()
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11618
diff changeset
   773
    for teamname, score in pairs(teamBests) do
11632
221691bede23 Trick on storage format to simplify sql queries
unC0Rr
parents: 11628
diff changeset
   774
        DeclareAchievement("height reached", teamname, "ClimbHome", -score)
11620
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11618
diff changeset
   775
    end
11640
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   776
    for teamname, score in pairs(teamTimes) do
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   777
        DeclareAchievement("rope race", teamname, "ClimbHome", score)
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11632
diff changeset
   778
    end
11620
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11618
diff changeset
   779
end