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