share/hedgewars/Data/Maps/ClimbHome/map.lua
author nemo
Sun, 30 Nov 2014 14:41:40 -0500
changeset 10585 eaccc445c473
parent 10581 f0b4c14a3c62
child 10587 1dac23b5fe3b
permissions -rw-r--r--
Should prevent desync hopefully. Thanks unc0rr
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")
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     3
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     4
local hTag = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     5
local hTagHeight = 33000
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     6
local tTag = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     7
local rTag = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     8
local startTime = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
     9
local MaxHeight = 32640
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    10
local RecordHeight = 33000
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    11
local RecordHeightHogName = nil
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    12
local Fire = {}
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    13
--local BoomFire = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    14
local HH = {}
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    15
local totalHedgehogs = 0
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    16
local deadHedgehogs = 0
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    17
local teamScoreStats = {}
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    18
local teamBests = {}
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    19
local MrMine -- in honour of sparkle's first arrival in the cabin
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    20
local YouWon = false
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    21
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
    22
local HogsAreInvulnerable = false
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    23
local WaterRise = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    24
local Cake = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    25
local CakeTries = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    26
local Stars = {}
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    27
local tauntNoo = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    28
local jokeAwardNavy = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    29
local jokeAwardSpeed = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    30
local jokeAwardDamage = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    31
local recordBroken = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    32
local ready = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    33
local showWaterStats = false -- uses the AI team to draw water height.
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    34
local dummyHog = nil
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    35
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    36
function onGameInit()
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    37
    -- Ensure people get same map for same theme
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    38
    TurnTime = 999999999
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    39
    CaseFreq = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    40
    Explosives = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    41
    MineDudPercent = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    42
    DisableGameFlags(gfBottomBorder+gfBorder)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    43
    --This reduced startup time by only about 15% and looked ugly
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    44
    --EnableGameFlags(gfDisableLandObjects) 
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    45
    -- 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
    46
    Seed = ClimbHome
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    47
    AddTeam(loc("Water Gods"), 0x0000AC, "Simple", "Island", "Default")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    48
    dummyHog = AddHog("Poseidon", 0, 1, "NoHat")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    49
    SendStat(siClanHealth, tostring(32640), loc("Water Gods"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    50
    SendStat(siClanHealth, tostring(32640), loc("Water Gods"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    51
    --HideHog(dummyHog)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    52
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    53
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    54
function onGearAdd(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    55
    if GetGearType(gear) == gtHedgehog then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    56
        HH[gear] = 1
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    57
        totalHedgehogs = totalHedgehogs + 1
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    58
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    59
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    60
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    61
function onGearDelete(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    62
    if gear == MrMine then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    63
        AddCaption("Once you set off the proximity trigger, Mr. Mine is not your friend",0xffffff,0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    64
        MrMine = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    65
    elseif gear == Cake then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    66
        Cake = nil
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    67
    elseif GetGearType(gear) == gtHedgehog then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    68
        HH[gear] = nil
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    69
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    70
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    71
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    72
function onGameStart()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    73
    --SetClanColor(ClansCount-1, 0x0000ffff) appears to be broken
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    74
    SendHealthStatsOff()
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    75
    ShowMission(loc("Climb Home"),
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    76
                loc("Rope to safety"),
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    77
                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."),
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    78
                -amRope, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    79
    local x = 1818
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    80
    for h,i in pairs(HH) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    81
       -- SetGearPosition(h,x,32549)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    82
        SetGearPosition(h,x,108)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    83
        SetHealth(h,1)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    84
        if x < 1978 then x = x+32 else x = 1818 end
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
    85
	if GetEffect(h,heInvulnerable) == 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
    86
	    SetEffect(h,heInvulnerable,1)
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
    87
	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
    88
	    HogsAreInvulnerable = true
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
    89
	end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    90
        SetState(h,bor(GetState(h),gstInvisible))
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    91
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    92
-- 1925,263 - Mr. Mine position
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    93
    MrMine = AddGear(1925,263,gtMine,0,0,0,0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    94
end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    95
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    96
function onAmmoStoreInit()
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    97
    SetAmmo(amRope, 9, 0, 0, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    98
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    99
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   100
function onNewTurn()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   101
    ready = false
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   102
    startTime = GameTime
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   103
    --disable to preserve highest over multiple turns
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   104
    --will need to change water check too ofc
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   105
    MaxHeight = 32640
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   106
    hTagHeight = 33000
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   107
    SetWaterLine(32768)
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   108
    YouWon = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   109
    YouLost = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   110
    tauntNoo = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   111
    recordBroken = false
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   112
    if CurrentHedgehog ~= nil then
10585
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   113
        SetGearPosition(CurrentHedgehog, 1951,32640)
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   114
        if not HogsAreInvulnerable then SetEffect(CurrentHedgehog,heInvulnerable,0) end
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   115
        AddVisualGear(19531,32640,vgtExplosion,0,false)
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   116
        SetState(CurrentHedgehog,band(GetState(CurrentHedgehog),bnot(gstInvisible)))
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   117
        SetWeapon(amRope)
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   118
        ready = true
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   119
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   120
    for f,i in pairs(Fire) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   121
        DeleteGear(f)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   122
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   123
    for s,i in pairs(Stars) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   124
        DeleteVisualGear(s)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   125
        Stars[s] = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   126
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   127
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   128
    if CurrentHedgehog ~= dummyHog then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   129
        for i = 0,12 do
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   130
            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
   131
            SetTag(flame, 999999+i)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   132
            Fire[flame]=1
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   133
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   134
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   135
    if Cake ~= nil then DeleteGear(Cake) end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   136
    CakeTries = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   137
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   138
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   139
--function onGearDelete(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   140
--    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
   141
--        WaterRise = AddGear(0,0,gtWaterUp, 0, 0, 0, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   142
--    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   143
--end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   144
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   145
function FireBoom(x,y,d) -- going to add for rockets too
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   146
    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
   147
    -- should approximate circle by removing corners
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   148
    --if BoomFire == nil then BoomFire = {} end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   149
    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
   150
	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
   151
	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
   152
	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
   153
	   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
   154
	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
   155
	   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
   156
	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
   157
	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
   158
	   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
   159
	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
   160
	   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
   161
	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
   162
        flame = AddGear(x+fx, y+fy, gtFlame, gsttmpFlag,  fdx, fdy, 0)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   163
        SetTag(flame, 999999+i)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   164
        Fire[flame]=1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   165
--        BoomFire[flame]=1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   166
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   167
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   168
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   169
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   170
function onGameTick20()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   171
    local x,y;
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   172
    if math.random(20) == 1 then AddVisualGear(2012,56,vgtSmoke,0,false) end
10585
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   173
    if CurrentHedgehog == dummyHog then
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   174
        ParseCommand("/skip")
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   175
    end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   176
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   177
    --if BoomFire ~= nil then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   178
    --    for f,i in pairs(BoomFire) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   179
    --        if band(GetState(f),gstCollision~=0) then DeleteGear(f) end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   180
    --    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   181
    --    BoomFire = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   182
    --end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   183
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   184
    for s,i in pairs(Stars) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   185
        g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(s)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   186
        if g1 > WaterLine + 500 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   187
            DeleteVisualGear(s)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   188
            Stars[s] = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   189
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   190
        --else  wasn't really visible, pointless.
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   191
        --    g5 = g5+1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   192
        --    if g5 > 360 then g5 = 0 end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   193
        --    SetVisualGearValues(s, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   194
        --end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   195
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   196
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   197
    if CurrentHedgehog ~= nil then x,y = GetGearPosition(CurrentHedgehog) end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   198
    if Cake ~= nil and CurrentHedgehog ~= nil then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   199
        local cx,cy = GetGearPosition(Cake)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   200
        if y < cy-1500 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   201
            DeleteGear(Cake)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   202
            Cake = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   203
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   204
        if gearIsInCircle(CurrentHedgehog,cx,cy,450) then
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
   205
            FireBoom(cx,cy,200) -- todo animate
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   206
            DeleteGear(Cake)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   207
            Cake = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   208
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   209
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   210
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   211
    if CurrentHedgehog ~= nil and TurnTimeLeft > 0 and band(GetState(CurrentHedgehog),gstHHDriven) ~= 0 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   212
        if MaxHeight < 32000 and MaxHeight > 286 and WaterLine > 286  then SetWaterLine(WaterLine-2) end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   213
        if y > 0 and y < 30000 and MaxHeight > 286 and math.random(y) < 500 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   214
            local s = AddVisualGear(0, 0, vgtStraightShot, 0, true)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   215
            local c = div(250000,y)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   216
            if c > 255 then c = 255 end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   217
            c = c * 0x10000 + 0xFF0000FF
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   218
            SetVisualGearValues(s,
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   219
                math.random(2048), -5000, 0, -1-(1/y*1000), 
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   220
                math.random(360),
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   221
                0,
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   222
                999999999, -- frameticks
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   223
                171, -- star
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   224
                0, c)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   225
                --,  0xFFCC00FF) -- could be fun to make colour shift as you rise...
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   226
            Stars[s] = 1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   227
        end    
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   228
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   229
    
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   230
    if CurrentHedgehog ~= nil and band(GetState(CurrentHedgehog),gstHHDriven) == 0 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   231
        for f,i in pairs(Fire) do -- takes too long to fall otherwise
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   232
            DeleteGear(f)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   233
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   234
        if Cake ~= nil then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   235
            DeleteGear(Cake)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   236
            Cake = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   237
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   238
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   239
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   240
    if CurrentHedgehog ~= nil and TurnTimeLeft > 0 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   241
        local vx, vy = GetGearVelocity(CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   242
	local distanceFromWater = WaterLine - y
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   243
	
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   244
        --[[ check joke awards ]]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   245
        -- 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
   246
        local navyDistance = 1250
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   247
        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
   248
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   249
            local dist = 0
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   250
            if jokeAwardNavy == nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   251
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   252
            else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   253
                if x < 0 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   254
                    dist = math.abs(x)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   255
                else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   256
                    dist = x - LAND_WIDTH
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   257
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   258
                if dist > jokeAwardNavy.distance then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   259
                    awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   260
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   261
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   262
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   263
                jokeAwardNavy = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   264
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   265
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   266
                    distance = dist
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   267
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   268
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   269
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   270
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   271
        -- Speed award for largest distance from water
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   272
        if distanceFromWater > 3000 and WaterLine < 32000 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   273
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   274
            if jokeAwardSpeed == nil or distanceFromWater > jokeAwardSpeed.distance then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   275
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   276
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   277
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   278
                jokeAwardSpeed = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   279
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   280
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   281
                    distance = distanceFromWater
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   282
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   283
            end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   284
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   285
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   286
        if GameTime % 500 == 0 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   287
            --if isSinglePlayer and MaxHeight < 32000 and WaterRise == nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   288
            --    WaterRise = AddGear(0,0,gtWaterUp, 0, 0, 0, 0)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   289
            --end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   290
            if showWaterStats == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   291
	        SendStat(siClanHealth, tostring(getActualHeight(WaterLine)), loc("Water Gods"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   292
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   293
            SendStat(siClanHealth, tostring(getActualHeight(y)), loc(GetHogTeamName(CurrentHedgehog)))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   294
            if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   295
                if distanceFromWater < 0 and not YouLost and not YouWon then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   296
                    makeSinglePlayerLoserStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   297
                    YouLost = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   298
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   299
                if not YouWon and not YouLost and gearIsInBox(CurrentHedgehog, 1920, 252, 50, 50) then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   300
                    local finishTime = (GameTime-startTime)/1000
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   301
                    local roundedFinishTime = math.ceil(math.floor(finishTime+0.5))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   302
                    AddCaption(loc("Victory!"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   303
                    ShowMission(loc("Climb Home"),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   304
                                loc("Made it!"),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   305
                                string.format(loc("Ahhh, home, sweet home. Made it in %d seconds."), roundedFinishTime),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   306
                                -amRope, 0)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   307
                    PlaySound(sndVictory,CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   308
                    SetState(CurrentHedgehog, gstWinner)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   309
                    SendStat(siGameResult, loc("You have beaten the challenge!"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   310
                    SendStat(siGraphTitle, loc("Your height over time"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   311
                    SendStat(siCustomAchievement, string.format(loc("%s reached home in %.3f seconds. Congratulations!"), loc(GetHogName(CurrentHedgehog)), finishTime))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   312
                    SendStat(siCustomAchievement, string.format(loc("%s bravely climbed up to a dizzy height of %d to reach home."),loc(GetHogName(CurrentHedgehog)), getActualHeight(RecordHeight)))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   313
                    SendStat(siPointType, loc("seconds"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   314
                    SendStat(siPlayerKills, tostring(roundedFinishTime), loc(GetHogTeamName(CurrentHedgehog)))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   315
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   316
		    if not showWaterStats == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   317
			SendStat(siClanHealth, tostring(32640), loc("Water Gods"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   318
		    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   319
                    EndGame()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   320
                    YouWon = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   321
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   322
            elseif distanceFromWater < 0 and not YouLost then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   323
                makeMultiPlayerLoserStat(CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   324
                deadHedgehogs = deadHedgehogs + 1
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   325
                YouLost = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   326
                if deadHedgehogs >= totalHedgehogs-1 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   327
                    makeFinalMultiPlayerStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   328
                    EndGame()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   329
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   330
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   331
    
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   332
            -- play taunts
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   333
            if not YouWon and not YouLost then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   334
                local nooDistance = 500
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   335
                if ((x < -nooDistance and vx < 0) or (x > LAND_WIDTH+nooDistance and vx > 0)) then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   336
                    if (tauntNoo == false and distanceFromWater > 80) then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   337
                        PlaySound(sndNooo, CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   338
                        tauntNoo = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   339
                    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   340
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   341
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   342
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   343
            if CakeTries < 10 and y < 32600 and y > 3000 and Cake == nil and band(GetState(CurrentHedgehog),gstHHDriven) ~= 0 then 
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   344
                -- 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
   345
                -- Pick a clear y to start with
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   346
                if y > 31000 then cy = 24585 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   347
                   y > 28000 then cy = 21500 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   348
                   y > 24000 then cy = 19000 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   349
                   y > 21500 then cy = 16000 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   350
                   y > 19000 then cy = 12265 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   351
                   y > 16000 then cy =  8800 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   352
                   y > 12000 then cy =  5700 else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   353
                   cy = 400 end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   354
                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
   355
                SetHealth(Cake,999999)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   356
                CakeTries = CakeTries + 1 
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   357
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   358
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   359
            if (y > 286) or (y < 286 and MaxHeight > 286) then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   360
                if y < MaxHeight and y > 286 then MaxHeight = y end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   361
                if y < 286 then MaxHeight = 286 end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   362
                if MaxHeight < hTagHeight then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   363
                    hTagHeight = MaxHeight
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   364
                    if hTag ~= nil then DeleteVisualGear(hTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   365
                    hTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   366
                    local g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(hTag)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   367
                    -- snagged from space invasion
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   368
                    SetVisualGearValues (
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   369
                            hTag,        --id
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   370
                            -(ScreenWidth/2) + 40, --xoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   371
                            ScreenHeight - 60, --yoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   372
                            0,          --dx
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   373
                            0,          --dy
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   374
                            1.1,        --zoom
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   375
                            1,          --~= 0 means align to screen
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   376
                            g7,         --frameticks
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   377
            -- 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
   378
            -- 32650 is "0"
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   379
                            32640-hTagHeight,    --value
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   380
                            99999999999,--timer
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   381
                            GetClanColor(GetHogClan(CurrentHedgehog))
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
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   384
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   385
                if MaxHeight < RecordHeight then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   386
                    RecordHeight = MaxHeight
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   387
                    local oldName = RecordHeightHogName
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   388
                    RecordHeightHogName = GetHogName(CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   389
                    if oldName == nil then recordBroken = true end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   390
                    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
   391
                        recordBroken = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   392
                        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
   393
                    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   394
                    if not isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   395
                        if rTag ~= nil then DeleteVisualGear(rTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   396
                        rTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   397
                        local g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(hTag)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   398
                        -- snagged from space invasion
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   399
                        SetVisualGearValues (
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   400
                            rTag,        --id
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   401
                            -(ScreenWidth/2) + 100, --xoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   402
                            ScreenHeight - 60, --yoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   403
                            0,          --dx
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   404
                            0,          --dy
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   405
                            1.1,        --zoom
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   406
                            1,          --~= 0 means align to screen
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   407
                            g7,         --frameticks
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   408
            -- 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
   409
            -- 32650 is "0"
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   410
                            getActualHeight(RecordHeight),    --value
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   411
                            99999999999,--timer
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   412
                            GetClanColor(GetHogClan(CurrentHedgehog))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   413
                            )
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   414
                    end
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
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   417
            if MaxHeight > 286 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   418
                if tTag ~= nil then DeleteVisualGear(tTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   419
                tTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   420
                local g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(tTag)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   421
                -- snagged from space invasion
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   422
                SetVisualGearValues (
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   423
                    tTag,        --id
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   424
                    -(ScreenWidth/2) + 40, --xoffset
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   425
                    ScreenHeight - 100, --yoffset
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   426
                    0,          --dx
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   427
                    0,          --dy
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   428
                    1.1,        --zoom
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   429
                    1,          --~= 0 means align to screen
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   430
                    g7,         --frameticks
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   431
                    (GameTime-startTime)/1000,    --value
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   432
                    99999999999,--timer
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   433
                    0xffffffff
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   434
                    )
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   435
            end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   436
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   437
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   438
end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   439
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   440
function onGearDamage(gear, damage)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   441
    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
   442
        -- Joke award for largest damage to hog
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   443
        local qualifyDamage = 50
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   444
        if (damage >= qualifyDamage) then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   445
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   446
            if jokeAwardDamage == nil or damage > jokeAwardDamage.damage then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   447
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   448
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   449
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   450
                jokeAwardDamage = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   451
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   452
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   453
                    damage = damage
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   454
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   455
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   456
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   457
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   458
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   459
            makeSinglePlayerLoserStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   460
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   461
            deadHedgehogs = deadHedgehogs + 1
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   462
            if deadHedgehogs >= totalHedgehogs-1 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   463
                makeFinalMultiPlayerStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   464
                EndGame()
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
            makeMultiPlayerLoserStat(gear)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   467
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   468
        YouLost = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   469
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   470
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   471
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   472
function makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   473
    local m
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   474
    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
   475
    local r = math.random(1,m)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   476
    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
   477
    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
   478
    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
   479
    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
   480
    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
   481
    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
   482
    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
   483
    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
   484
    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
   485
    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
   486
    return text
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   487
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   488
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   489
function makeSinglePlayerLoserStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   490
    local actualHeight = getActualHeight(RecordHeight)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   491
    SendStat(siGameResult, loc("You lose!"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   492
    SendStat(siGraphTitle, loc("Your height over time"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   493
    local text
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   494
    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
   495
    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
   496
    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
   497
    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
   498
    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
   499
    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
   500
    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
   501
    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
   502
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   503
        text = makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   504
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   505
    if actualHeight > 1500 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   506
        SendStat(siCustomAchievement, string.format(text, RecordHeightHogName, actualHeight))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   507
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   508
        SendStat(siCustomAchievement, string.format(text, RecordHeightHogName))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   509
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   510
    SendStat(siPointType, "points")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   511
    SendStat(siPlayerKills, actualHeight, loc(GetHogTeamName(CurrentHedgehog)))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   512
    EndGame()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   513
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   514
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   515
function makeMultiPlayerLoserStat(gear)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   516
    local teamName = GetHogTeamName(gear)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   517
    local actualHeight = getActualHeight(MaxHeight)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   518
    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
   519
    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
   520
    if teamScoreStats[teamName] == nil then teamScoreStats[teamName] = {} end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   521
    table.insert(teamScoreStats[teamName], actualHeight)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   522
    SendStat(siClanHealth, tostring(teamBests[teamName]), teamName)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   523
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   524
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   525
function makeFinalMultiPlayerStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   526
    local ranking = {}
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   527
    for k,v in pairs(teamBests) do
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   528
        table.insert(ranking, {name=k, score=v})
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   529
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   530
    local comp = function(table1, table2)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   531
        if table1.score < table2.score then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   532
            return true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   533
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   534
            return false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   535
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   536
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   537
    table.sort(ranking, comp)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   538
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   539
    local winner = ranking[#ranking]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   540
    local loser = ranking[1]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   541
    SendStat(siGameResult, string.format(loc("%s wins!"), winner.name))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   542
    SendStat(siGraphTitle, string.format(loc("Team’s best heights per round")))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   543
    
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   544
    if winner.score < 1500 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   545
        SendStat(siCustomAchievement, string.format(loc("This round’s award for ulitmate disappointment goes to: Everyone!")))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   546
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   547
        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
   548
        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
   549
        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
   550
        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
   551
        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
   552
        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
   553
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   554
        if loser.score < 1500 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   555
            text = makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   556
            SendStat(siCustomAchievement, string.format(text, loser.name))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   557
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   558
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   559
    checkAwards()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   560
    for i = #ranking, 1, -1 do
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   561
        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
   562
        SendStat(siPointType, "points")
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   563
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   564
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   565
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   566
function checkAwards()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   567
    if jokeAwardNavy ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   568
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   569
            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
   570
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   571
            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
   572
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   573
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   574
    if jokeAwardSpeed ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   575
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   576
            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
   577
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   578
            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
   579
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   580
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   581
    if jokeAwardDamage ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   582
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   583
            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
   584
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   585
            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
   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
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   589
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   590
function getActualHeight(height)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   591
    return 32640-height
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   592
end