share/hedgewars/Data/Maps/ClimbHome/map.lua
author Wuzzy <almikes@aol.com>
Fri, 25 Nov 2016 02:53:42 +0100
changeset 12077 ce3860c82c8b
parent 11889 c8979eeb73fa
child 12079 8f222872d432
permissions -rw-r--r--
Rewrite 2nd line of mission panel of most missions for consistency
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 = {}
11635
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
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
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    29
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
    30
local addCake = true
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    31
local Stars = {}
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    32
local tauntNoo = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    33
local jokeAwardNavy = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    34
local jokeAwardSpeed = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    35
local jokeAwardDamage = nil
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    36
local recordBroken = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    37
local ready = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    38
local dummyHog = nil
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
    39
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
    40
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
    41
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
    42
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
    43
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
    44
local delayTime = 0
10824
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    45
local airMineX = {}
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    46
local airMineY = {}
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    47
local airMine = {}
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    48
local init = true
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
    49
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
    50
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
    51
    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
    52
10811
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    53
    if params["speed"] ~= nil then
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    54
        baseWaterSpeed = params["speed"]
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    55
    end
10812
38dc8445d7a7 fix typo
nemo
parents: 10811
diff changeset
    56
    if params["accel"] ~= nil then
10811
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    57
        waterAccel = params["accel"]
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    58
        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
    59
    end
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    60
    if params["delaytime"] ~= nil then
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    61
        delayTime = params["delaytime"]
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    62
    end
11613
66880a42c2d7 Fix typo
unC0Rr
parents: 11067
diff changeset
    63
    if params["delayheight"] ~= nil then
10811
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
diff changeset
    64
        delayHeight = 32768-params["delayheight"]
0d9c49e88142 I guess the params shouldn't be all or nothing.
nemo
parents: 10810
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
    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
    67
end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    68
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    69
function onGameInit()
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    70
    -- Ensure people get same map for same theme
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    71
    TurnTime = 999999999
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    72
    CaseFreq = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    73
    Explosives = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    74
    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
    75
    EnableGameFlags(gfOneClanMode)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    76
    DisableGameFlags(gfBottomBorder+gfBorder)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    77
    --This reduced startup time by only about 15% and looked ugly
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    78
    --EnableGameFlags(gfDisableLandObjects) 
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    79
    -- 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
    80
    Seed = ClimbHome
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    81
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    82
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    83
function onGearAdd(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    84
    if GetGearType(gear) == gtHedgehog then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    85
        HH[gear] = 1
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    86
        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
    87
        teams[GetHogTeamName(gear)] = 1
10824
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    88
    elseif init and GetGearType(gear) == gtAirMine then
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
    89
        airMine[gear] = 1
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    90
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    91
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    92
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    93
function onGearDelete(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    94
    if gear == MrMine then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    95
        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
    96
        MrMine = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    97
    elseif gear == Cake then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
    98
        Cake = nil
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
    99
    elseif GetGearType(gear) == gtHedgehog then
11067
c632b47b8ff0 Trying to get these scripts to behave properly, still WIP though.
nemo
parents: 10824
diff changeset
   100
	onGameTick20()
c632b47b8ff0 Trying to get these scripts to behave properly, still WIP though.
nemo
parents: 10824
diff changeset
   101
	onGearDamage(gear, 0)
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   102
        HH[gear] = nil
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   103
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   104
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   105
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   106
function onGameStart()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   107
    --SetClanColor(ClansCount-1, 0x0000ffff) appears to be broken
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   108
    SendHealthStatsOff()
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   109
    ShowMission(loc("Climb Home"),
12077
ce3860c82c8b Rewrite 2nd line of mission panel of most missions for consistency
Wuzzy <almikes@aol.com>
parents: 11889
diff changeset
   110
                loc("Challenge"),
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   111
                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
   112
                -amRope, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   113
    local x = 1818
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   114
    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
   115
        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
   116
            -- 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
   117
            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
   118
            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
   119
            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
   120
            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
   121
                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
   122
            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
   123
                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
   124
            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
   125
            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
   126
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   127
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   128
-- 1925,263 - Mr. Mine position
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   129
    MrMine = AddGear(1925,263,gtMine,0,0,0,0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   130
end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   131
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   132
function onAmmoStoreInit()
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   133
    SetAmmo(amRope, 9, 0, 0, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   134
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   135
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   136
function onNewTurn()
10824
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   137
    if init then
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   138
        init = false
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   139
        for a,i in pairs(airMine) do
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   140
            x,y = GetGearPosition(a)
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   141
            airMineX[a] = x
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   142
            airMineY[a] = y
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   143
        end
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   144
    else
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   145
        for a,i in pairs(airMine) do
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   146
            local x,y = GetGearPosition(a)
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   147
            if not x or airMineX[a] ~= x or airMineY[a] ~= y then
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   148
                DeleteGear(a)
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   149
                AddGear(airMineX[a],airMineY[a], gtAirMine, gsttmpFlag, 0, 0, 0)
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   150
            end
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   151
        end
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   152
    end
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   153
        
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   154
    ready = false
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   155
    startTime = GameTime
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   156
    --disable to preserve highest over multiple turns
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   157
    --will need to change water check too ofc
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   158
    MaxHeight = 32640
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   159
    hTagHeight = 33000
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   160
    SetWaterLine(32768)
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   161
    YouWon = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   162
    YouLost = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   163
    tauntNoo = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   164
    recordBroken = false
10632
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
   165
    currTeam = GetHogTeamName(CurrentHedgehog)
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   166
    if CurrentHedgehog ~= nil then
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   167
        if CurrentHedgehog ~= dummyHog then
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   168
            SetGearPosition(CurrentHedgehog, 1951,32640)
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   169
            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
   170
            AddVisualGear(1951,32640,vgtExplosion,0,false)
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   171
            SetState(CurrentHedgehog,band(GetState(CurrentHedgehog),bnot(gstInvisible)))
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   172
            SetWeapon(amRope)
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   173
            ready = true
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   174
        else
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   175
            dummySkip = GameTime+1
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   176
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   177
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   178
    for f,i in pairs(Fire) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   179
        DeleteGear(f)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   180
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   181
    for s,i in pairs(Stars) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   182
        DeleteVisualGear(s)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   183
        Stars[s] = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   184
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   185
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   186
    if CurrentHedgehog ~= dummyHog then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   187
        for i = 0,12 do
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   188
            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
   189
            SetTag(flame, 999999+i)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   190
            Fire[flame]=1
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   191
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   192
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   193
    if Cake ~= nil then DeleteGear(Cake) end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   194
    CakeTries = 0
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   195
end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   196
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   197
--function onGearDelete(gear)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   198
--    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
   199
--        WaterRise = AddGear(0,0,gtWaterUp, 0, 0, 0, 0)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   200
--    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   201
--end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   202
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   203
function FireBoom(x,y,d) -- going to add for rockets too
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   204
    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
   205
    -- should approximate circle by removing corners
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   206
    --if BoomFire == nil then BoomFire = {} end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   207
    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
   208
	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
   209
	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
   210
	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
   211
	   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
   212
	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
   213
	   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
   214
	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
   215
	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
   216
	   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
   217
	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
   218
	   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
   219
	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
   220
        flame = AddGear(x+fx, y+fy, gtFlame, gsttmpFlag,  fdx, fdy, 0)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   221
        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
   222
        SetFlightTime(flame, 0)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   223
        Fire[flame]=1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   224
--        BoomFire[flame]=1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   225
    end
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
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   229
function onGameTick20()
10824
acbbd49f8274 make air mines respawn on climbhome
nemo
parents: 10812
diff changeset
   230
    local x,y
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   231
    if math.random(20) == 1 then AddVisualGear(2012,56,vgtSmoke,0,false) end
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   232
    if CurrentHedgehog == dummyHog and dummySkip ~= 0 and dummySkip < GameTime then
10585
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   233
        ParseCommand("/skip")
10592
2da35f88db23 stricter skip
nemo
parents: 10589
diff changeset
   234
        dummySkip = 0
10585
eaccc445c473 Should prevent desync hopefully. Thanks unc0rr
nemo
parents: 10581
diff changeset
   235
    end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   236
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   237
    --if BoomFire ~= nil then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   238
    --    for f,i in pairs(BoomFire) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   239
    --        if band(GetState(f),gstCollision~=0) then DeleteGear(f) end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   240
    --    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   241
    --    BoomFire = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   242
    --end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   243
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   244
    for s,i in pairs(Stars) do
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   245
        g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(s)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   246
        if g1 > WaterLine + 500 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   247
            DeleteVisualGear(s)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   248
            Stars[s] = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   249
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   250
        --else  wasn't really visible, pointless.
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   251
        --    g5 = g5+1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   252
        --    if g5 > 360 then g5 = 0 end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   253
        --    SetVisualGearValues(s, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   254
        --end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   255
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   256
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   257
    if CurrentHedgehog ~= nil then x,y = GetGearPosition(CurrentHedgehog) end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   258
    if Cake ~= nil and CurrentHedgehog ~= nil then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   259
        local cx,cy = GetGearPosition(Cake)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   260
        if y < cy-1500 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   261
            DeleteGear(Cake)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   262
            Cake = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   263
        end
10587
1dac23b5fe3b delay cake boom until it has walked a little bit. also fix accidental drowning of watergods in last commit
nemo
parents: 10585
diff changeset
   264
10645
b8c73bacb31e Fix in-flight colouring of land spray, make it use tint when added to land too (lua might find that handy), tweak climbhome cake delay slightly
nemo
parents: 10632
diff changeset
   265
        if Cake ~= nil and GetHealth(Cake) < 999980 and 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
   266
            FireBoom(cx,cy,200) -- todo animate
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   267
            DeleteGear(Cake)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   268
            Cake = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   269
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   270
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   271
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   272
    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
   273
        if MaxHeight < delayHeight and
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
   274
           TurnTimeLeft<(999999999-delayTime) and 
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
   275
            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
   276
            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
   277
                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
   278
            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
   279
                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
   280
            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
   281
        end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   282
        if y > 0 and y < 30000 and MaxHeight > 286 and math.random(y) < 500 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   283
            local s = AddVisualGear(0, 0, vgtStraightShot, 0, true)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   284
            local c = div(250000,y)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   285
            if c > 255 then c = 255 end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   286
            c = c * 0x10000 + 0xFF0000FF
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   287
            SetVisualGearValues(s,
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   288
                math.random(2048), -5000, 0, -1-(1/y*1000), 
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   289
                math.random(360),
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   290
                0,
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   291
                999999999, -- frameticks
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   292
                171, -- star
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   293
                0, c)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   294
                --,  0xFFCC00FF) -- could be fun to make colour shift as you rise...
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   295
            Stars[s] = 1
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   296
        end    
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   297
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   298
    
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   299
    if CurrentHedgehog ~= nil and band(GetState(CurrentHedgehog),gstHHDriven) == 0 then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   300
        for f,i in pairs(Fire) do -- takes too long to fall otherwise
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   301
            DeleteGear(f)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   302
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   303
        if Cake ~= nil then
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   304
            DeleteGear(Cake)
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   305
            Cake = nil
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   306
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   307
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   308
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   309
    if CurrentHedgehog ~= nil and TurnTimeLeft > 0 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   310
        local vx, vy = GetGearVelocity(CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   311
	local distanceFromWater = WaterLine - y
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   312
	
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   313
        --[[ check joke awards ]]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   314
        -- 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
   315
        local navyDistance = 1250
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   316
        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
   317
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   318
            local dist = 0
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   319
            if jokeAwardNavy == nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   320
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   321
            else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   322
                if x < 0 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   323
                    dist = math.abs(x)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   324
                else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   325
                    dist = x - LAND_WIDTH
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   326
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   327
                if dist > jokeAwardNavy.distance then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   328
                    awarded = true
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
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   332
                jokeAwardNavy = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   333
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   334
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   335
                    distance = dist
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   336
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   337
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   338
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   339
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   340
        -- Speed award for largest distance from water
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   341
        if distanceFromWater > 3000 and WaterLine < 32000 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   342
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   343
            if jokeAwardSpeed == nil or distanceFromWater > jokeAwardSpeed.distance then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   344
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   345
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   346
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   347
                jokeAwardSpeed = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   348
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   349
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   350
                    distance = distanceFromWater
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   351
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   352
            end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   353
        end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   354
            if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   355
                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
   356
                    makeSinglePlayerLoserStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   357
                    YouLost = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   358
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   359
                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
   360
                    local finishTime = (GameTime-startTime)/1000
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   361
                    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
   362
                    AddCaption(loc("Victory!"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   363
                    ShowMission(loc("Climb Home"),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   364
                                loc("Made it!"),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   365
                                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
   366
                                -amRope, 0)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   367
                    PlaySound(sndVictory,CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   368
                    SetState(CurrentHedgehog, gstWinner)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   369
                    SendStat(siGameResult, loc("You have beaten the challenge!"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   370
                    SendStat(siGraphTitle, loc("Your height over time"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   371
                    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
   372
                    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
   373
                    SendStat(siPointType, loc("seconds"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   374
                    SendStat(siPlayerKills, tostring(roundedFinishTime), loc(GetHogTeamName(CurrentHedgehog)))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   375
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   376
                    EndGame()
11623
515d2d38ab8b Declare achievements alongwith EndGame call, since it would skip SendStats
unc0rr
parents: 11615
diff changeset
   377
                    onAchievementsDeclaration()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   378
                    YouWon = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   379
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   380
            elseif distanceFromWater < 0 and not YouLost then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   381
                makeMultiPlayerLoserStat(CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   382
                deadHedgehogs = deadHedgehogs + 1
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   383
                YouLost = true
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
   384
                if deadHedgehogs >= totalHedgehogs then
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   385
                    makeFinalMultiPlayerStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   386
                    EndGame()
11623
515d2d38ab8b Declare achievements alongwith EndGame call, since it would skip SendStats
unc0rr
parents: 11615
diff changeset
   387
                    onAchievementsDeclaration()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   388
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   389
            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
   390
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
   391
        if GameTime % 500 == 0 then
11889
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   392
            if not isSinglePlayer then
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   393
	        for t,i in pairs(teams) do
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   394
                    if currTeam == t then
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   395
                        SendStat(siClanHealth, tostring(getActualHeight(y)), t)
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   396
                    else
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   397
                        SendStat(siClanHealth, '0', t)
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   398
                    end
10632
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
   399
                end
11889
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   400
            elseif CurrentHedgehog ~= nil then
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   401
                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
   402
            end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   403
    
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   404
            -- play taunts
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   405
            if not YouWon and not YouLost then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   406
                local nooDistance = 500
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   407
                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
   408
                    if (tauntNoo == false and distanceFromWater > 80) then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   409
                        PlaySound(sndNooo, CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   410
                        tauntNoo = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   411
                    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   412
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   413
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   414
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
   415
            if addCake and CakeTries < 10 and y < 32600 and y > 3000 and Cake == nil and band(GetState(CurrentHedgehog),gstHHDriven) ~= 0 then 
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   416
                -- 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
   417
                -- Pick a clear y to start with
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   418
                if y > 31000 then cy = 24585 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   419
                   y > 28000 then cy = 21500 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   420
                   y > 24000 then cy = 19000 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   421
                   y > 21500 then cy = 16000 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   422
                   y > 19000 then cy = 12265 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   423
                   y > 16000 then cy =  8800 elseif
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   424
                   y > 12000 then cy =  5700 else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   425
                   cy = 400 end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   426
                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
   427
                SetHealth(Cake,999999)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   428
                CakeTries = CakeTries + 1 
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   429
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   430
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   431
            if (y > 286) or (y < 286 and MaxHeight > 286) then
11635
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   432
                if MaxHeight > 286 and y <= 286 then
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   433
                    -- wow, reached top
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   434
                    local teamName = GetHogTeamName(CurrentHedgehog)
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   435
                    if teamTimes[teamName] == nil or teamTimes[teamName] > GameTime - startTime then 
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   436
                        teamTimes[teamName] = GameTime - startTime 
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   437
                    end
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   438
                    MaxHeight = 286
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   439
                end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   440
                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
   441
                if MaxHeight < hTagHeight then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   442
                    hTagHeight = MaxHeight
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   443
                    if hTag ~= nil then DeleteVisualGear(hTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   444
                    hTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   445
                    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
   446
                    -- snagged from space invasion
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   447
                    SetVisualGearValues (
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   448
                            hTag,        --id
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   449
                            -(ScreenWidth/2) + 40, --xoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   450
                            ScreenHeight - 60, --yoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   451
                            0,          --dx
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   452
                            0,          --dy
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   453
                            1.1,        --zoom
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   454
                            1,          --~= 0 means align to screen
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   455
                            g7,         --frameticks
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   456
            -- 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
   457
            -- 32650 is "0"
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   458
                            32640-hTagHeight,    --value
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   459
                            99999999999,--timer
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   460
                            GetClanColor(GetHogClan(CurrentHedgehog))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   461
                            )
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   462
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   463
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   464
                if MaxHeight < RecordHeight then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   465
                    RecordHeight = MaxHeight
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   466
                    local oldName = RecordHeightHogName
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   467
                    RecordHeightHogName = GetHogName(CurrentHedgehog)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   468
                    if oldName == nil then recordBroken = true end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   469
                    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
   470
                        recordBroken = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   471
                        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
   472
                    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   473
                    if not isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   474
                        if rTag ~= nil then DeleteVisualGear(rTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   475
                        rTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   476
                        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
   477
                        -- snagged from space invasion
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   478
                        SetVisualGearValues (
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   479
                            rTag,        --id
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   480
                            -(ScreenWidth/2) + 100, --xoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   481
                            ScreenHeight - 60, --yoffset
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   482
                            0,          --dx
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   483
                            0,          --dy
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   484
                            1.1,        --zoom
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   485
                            1,          --~= 0 means align to screen
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   486
                            g7,         --frameticks
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   487
            -- 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
   488
            -- 32650 is "0"
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   489
                            getActualHeight(RecordHeight),    --value
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   490
                            99999999999,--timer
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   491
                            GetClanColor(GetHogClan(CurrentHedgehog))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   492
                            )
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   493
                    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   494
                end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   495
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   496
            if MaxHeight > 286 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   497
                if tTag ~= nil then DeleteVisualGear(tTag) end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   498
                tTag = AddVisualGear(0, 0, vgtHealthTag, 0, true)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   499
                local g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(tTag)
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   500
                -- snagged from space invasion
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   501
                SetVisualGearValues (
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   502
                    tTag,        --id
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   503
                    -(ScreenWidth/2) + 40, --xoffset
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   504
                    ScreenHeight - 100, --yoffset
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   505
                    0,          --dx
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   506
                    0,          --dy
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   507
                    1.1,        --zoom
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   508
                    1,          --~= 0 means align to screen
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   509
                    g7,         --frameticks
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   510
                    (GameTime-startTime)/1000,    --value
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   511
                    99999999999,--timer
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   512
                    0xffffffff
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   513
                    )
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   514
            end
10413
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   515
        end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   516
    end
afd746a538ef climb home training/multiplayer
nemo
parents:
diff changeset
   517
end
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   518
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   519
function onGearDamage(gear, damage)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   520
    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
   521
        -- Joke award for largest damage to hog
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   522
        local qualifyDamage = 50
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   523
        if (damage >= qualifyDamage) then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   524
            local awarded = false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   525
            if jokeAwardDamage == nil or damage > jokeAwardDamage.damage then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   526
                awarded = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   527
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   528
            if awarded == true then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   529
                jokeAwardDamage = {
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   530
                    hogName = GetHogName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   531
                    teamName = GetHogTeamName(CurrentHedgehog),
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   532
                    damage = damage
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   533
                }
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   534
            end
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
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   537
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   538
            makeSinglePlayerLoserStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   539
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   540
            deadHedgehogs = deadHedgehogs + 1
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
   541
            if deadHedgehogs >= totalHedgehogs then
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   542
                makeFinalMultiPlayerStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   543
                EndGame()
11623
515d2d38ab8b Declare achievements alongwith EndGame call, since it would skip SendStats
unc0rr
parents: 11615
diff changeset
   544
                onAchievementsDeclaration()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   545
            end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   546
            makeMultiPlayerLoserStat(gear)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   547
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   548
        YouLost = true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   549
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   550
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   551
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   552
function makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   553
    local m
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   554
    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
   555
    local r = math.random(1,m)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   556
    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
   557
    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
   558
    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
   559
    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
   560
    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
   561
    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
   562
    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
   563
    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
   564
    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
   565
    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
   566
    return text
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   567
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   568
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   569
function makeSinglePlayerLoserStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   570
    local actualHeight = getActualHeight(RecordHeight)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   571
    SendStat(siGameResult, loc("You lose!"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   572
    SendStat(siGraphTitle, loc("Your height over time"))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   573
    local text
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   574
    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
   575
    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
   576
    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
   577
    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
   578
    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
   579
    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
   580
    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
   581
    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
   582
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   583
        text = makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   584
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   585
    if actualHeight > 1500 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   586
        SendStat(siCustomAchievement, string.format(text, RecordHeightHogName, actualHeight))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   587
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   588
        SendStat(siCustomAchievement, string.format(text, RecordHeightHogName))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   589
    end
11067
c632b47b8ff0 Trying to get these scripts to behave properly, still WIP though.
nemo
parents: 10824
diff changeset
   590
    SendStat(siPointType, loc("points"))
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   591
    SendStat(siPlayerKills, actualHeight, loc(GetHogTeamName(CurrentHedgehog)))
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   592
    EndGame()
11623
515d2d38ab8b Declare achievements alongwith EndGame call, since it would skip SendStats
unc0rr
parents: 11615
diff changeset
   593
    onAchievementsDeclaration()
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   594
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   595
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   596
function makeMultiPlayerLoserStat(gear)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   597
    local teamName = GetHogTeamName(gear)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   598
    local actualHeight = getActualHeight(MaxHeight)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   599
    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
   600
    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
   601
    if teamScoreStats[teamName] == nil then teamScoreStats[teamName] = {} end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   602
    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
   603
    --SendStat(siClanHealth, tostring(teamBests[teamName]), teamName)
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   604
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   605
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   606
function makeFinalMultiPlayerStats()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   607
    local ranking = {}
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   608
    for k,v in pairs(teamBests) do
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   609
        table.insert(ranking, {name=k, score=v})
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   610
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   611
    local comp = function(table1, table2)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   612
        if table1.score < table2.score then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   613
            return true
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   614
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   615
            return false
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   616
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   617
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   618
    table.sort(ranking, comp)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   619
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   620
    local winner = ranking[#ranking]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   621
    local loser = ranking[1]
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   622
    SendStat(siGameResult, string.format(loc("%s wins!"), winner.name))
11889
c8979eeb73fa Fix ClimbHome mission bugs (broken teams, broken graph)
Wuzzy <almikes@aol.com>
parents: 11635
diff changeset
   623
    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
   624
    
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   625
    if winner.score < 1500 then
11067
c632b47b8ff0 Trying to get these scripts to behave properly, still WIP though.
nemo
parents: 10824
diff changeset
   626
        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
   627
    else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   628
        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
   629
        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
   630
        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
   631
        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
   632
        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
   633
        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
   634
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   635
        if loser.score < 1500 then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   636
            text = makeLoserComment()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   637
            SendStat(siCustomAchievement, string.format(text, loser.name))
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
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   640
    checkAwards()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   641
    for i = #ranking, 1, -1 do
10632
5ae7ba0b2849 pretty sure the other teams need stats at 0 for the graph to look right
nemo
parents: 10598
diff changeset
   642
	SendStat(siPointType, loc("points"))
10581
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   643
        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
   644
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   645
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   646
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   647
function checkAwards()
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   648
    if jokeAwardNavy ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   649
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   650
            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
   651
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   652
            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
   653
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   654
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   655
    if jokeAwardSpeed ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   656
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   657
            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
   658
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   659
            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
   660
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   661
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   662
    if jokeAwardDamage ~= nil then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   663
        if isSinglePlayer then
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   664
            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
   665
        else
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   666
            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
   667
        end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   668
    end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   669
end
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   670
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   671
function getActualHeight(height)
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   672
    return 32640-height
f0b4c14a3c62 Wuzzy's changes to climbhome w/ some tweaks by me
nemo
parents: 10580
diff changeset
   673
end
11615
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11613
diff changeset
   674
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11613
diff changeset
   675
function onAchievementsDeclaration()
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11613
diff changeset
   676
    for teamname, score in pairs(teamBests) do
11627
221691bede23 Trick on storage format to simplify sql queries
unC0Rr
parents: 11623
diff changeset
   677
        DeclareAchievement("height reached", teamname, "ClimbHome", -score)
11615
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11613
diff changeset
   678
    end
11635
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   679
    for teamname, score in pairs(teamTimes) do
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   680
        DeclareAchievement("rope race", teamname, "ClimbHome", score)
2a53e219bc1a Time achievement for ClimbHome
unC0Rr
parents: 11627
diff changeset
   681
    end
11615
d5b205f00ac7 Achievement for ClimbHome
unC0Rr
parents: 11613
diff changeset
   682
end