share/hedgewars/Data/Missions/Scenario/Big_Armory.lua
changeset 12235 f9565e2e0424
child 12236 b4878d6cd96e
equal deleted inserted replaced
12234:04535e6dc15a 12235:f9565e2e0424
       
     1 HedgewarsScriptLoad("/Scripts/Locale.lua")
       
     2 
       
     3 local playerHog
       
     4 local playerTeamName = loc("Pro Killers")
       
     5 local enemyTeamName = loc("Galaxy Guardians")
       
     6 local enemyTeam1 = {
       
     7 	{name=loc("Rocket"), x=796, y=1184},
       
     8 	{name=loc("Star"), x=733, y=1525},
       
     9 	{name=loc("Asteroid"), x=738, y=1855},
       
    10 	{name=loc("Comet"), x=937, y=1318},
       
    11 	{name=loc("Sunflame"), x=3424, y=1536},
       
    12 	{name=loc("Eclipse"), x=3417, y=1081},
       
    13 	{name=loc("Jetpack"), x=2256, y=1246},
       
    14 	{name=loc("Void"), x=1587, y=1231},
       
    15 }
       
    16 local gameStarted = false
       
    17 local turnNo = 0
       
    18 local toleranceTimer = nil
       
    19 local enemyHogsLeft = #enemyTeam1
       
    20 local pendingDeaths = {}
       
    21 local enemyHogs = {}
       
    22 local gameEnded = false
       
    23 local waitGears = 0
       
    24 local hasAttacked = false
       
    25 local minePlaced = false
       
    26 local delayGear = nil
       
    27 
       
    28 function onGameInit()
       
    29 	Seed = "{7e34a56b-ee7b-4fe1-8f30-352a998f3f6a}"
       
    30 	GameFlags = gfDisableWind + gfDisableLandObjects
       
    31 	TurnTime= 45000
       
    32 	CaseFreq = 0 
       
    33 	MinesNum = 0 
       
    34 	Explosives = 0 
       
    35 	Theme = "EarthRise" 
       
    36 	MapGen = mgRandom
       
    37 	MapFeatureSize = 12
       
    38 	-- Disable Sudden Death
       
    39 	WaterRise = 0
       
    40 	HealthDecrease = 0
       
    41 	
       
    42 	AddTeam(playerTeamName, 0xFF0000, "Bone", "Island", "Classic", "cm_scout")
       
    43 	playerHog = AddHog(loc("Ultrasoldier"), 0, 100, "Terminator_Glasses")
       
    44 	SetGearPosition(playerHog, 543, 1167)
       
    45 
       
    46 	AddTeam(enemyTeamName, 0xF5F808, "Earth", "Island", "Classic", "cm_galaxy")
       
    47 	for i=1,8 do
       
    48 		local hogID = AddHog(enemyTeam1[i].name, 0, 100, "NoHat")
       
    49 		table.insert(enemyHogs, hogID)
       
    50 		SetGearPosition(hogID, enemyTeam1[i].x, enemyTeam1[i].y)
       
    51 	end
       
    52 end
       
    53 
       
    54 function onAmmoStoreInit()
       
    55 
       
    56 	SetAmmo(amGrenade, 9, 0, 0, 1)
       
    57 	SetAmmo(amClusterBomb, 9, 0, 0, 1)
       
    58 	SetAmmo(amBazooka, 9, 0, 0, 1)
       
    59 	SetAmmo(amBee, 9, 0, 0, 1)
       
    60 	SetAmmo(amShotgun, 9, 0, 0, 1)
       
    61 	SetAmmo(amPickHammer, 9, 0, 0, 1)
       
    62 	SetAmmo(amSkip, 9, 0, 0, 1)
       
    63 	SetAmmo(amRope, 9, 0, 0, 1)
       
    64 	SetAmmo(amMine, 9, 0, 0, 1)
       
    65 	SetAmmo(amDEagle, 9, 0, 0, 1)
       
    66 	SetAmmo(amDynamite, 9, 0, 0, 1)
       
    67 	SetAmmo(amFirePunch, 9, 0, 0, 1)
       
    68 	SetAmmo(amWhip, 9, 0, 0, 1)
       
    69 	SetAmmo(amBaseballBat, 9, 0, 0, 1)
       
    70 	SetAmmo(amParachute, 9, 0, 0, 1)
       
    71 	SetAmmo(amAirAttack, 9, 0, 0, 1)
       
    72 	SetAmmo(amMineStrike, 9, 0, 0, 1)
       
    73 	SetAmmo(amBlowTorch, 9, 0, 0, 1)
       
    74 	SetAmmo(amGirder, 9, 0, 0, 1)
       
    75 	SetAmmo(amTeleport, 9, 0, 0, 1)
       
    76 	SetAmmo(amSwitch, 9, 0, 0, 1)
       
    77 	SetAmmo(amMortar, 9, 0, 0, 1)
       
    78 	SetAmmo(amKamikaze, 9, 0, 0, 1)
       
    79 	SetAmmo(amCake, 9, 0, 0, 1)
       
    80 	SetAmmo(amSeduction, 9, 0, 0, 1)
       
    81 	SetAmmo(amWatermelon, 9, 0, 0, 1)
       
    82 	SetAmmo(amHellishBomb, 9, 0, 0, 1)
       
    83 	SetAmmo(amNapalm, 9, 0, 0, 1)
       
    84 	SetAmmo(amDrill, 9, 0, 0, 1)
       
    85 	SetAmmo(amBallgun, 9, 0, 0, 1)
       
    86 	SetAmmo(amRCPlane, 9, 0, 0, 1)
       
    87 	SetAmmo(amLowGravity, 9, 0, 0, 1)
       
    88 	SetAmmo(amExtraDamage, 9, 0, 0, 1)
       
    89 	SetAmmo(amInvulnerable, 9, 0, 0, 1)
       
    90 	SetAmmo(amLaserSight, 9, 0, 0, 1)
       
    91 	SetAmmo(amVampiric, 9, 0, 0, 1)
       
    92 	SetAmmo(amSniperRifle, 9, 0, 0, 1)
       
    93 	SetAmmo(amJetpack, 9, 0, 0, 1)
       
    94 	SetAmmo(amMolotov, 9, 0, 0, 1)
       
    95 	SetAmmo(amBirdy, 9, 0, 0, 1)
       
    96 	SetAmmo(amPortalGun, 9, 0, 0, 1)
       
    97 	SetAmmo(amPiano, 9, 0, 0, 1)
       
    98 	SetAmmo(amGasBomb, 9, 0, 0, 1)
       
    99 	SetAmmo(amSineGun, 9, 0, 0, 1)
       
   100 	SetAmmo(amFlamethrower, 9, 0, 0, 1)
       
   101 	SetAmmo(amSMine, 9, 0, 0, 1)
       
   102 	SetAmmo(amHammer, 9, 0, 0, 1)
       
   103 	SetAmmo(amResurrector, 9, 0, 0, 1)
       
   104 	SetAmmo(amDrillStrike, 9, 0, 0, 1)
       
   105 	SetAmmo(amSnowball, 9, 0, 0, 1)
       
   106 	SetAmmo(amTardis, 9, 0, 0, 1)
       
   107 	SetAmmo(amLandGun, 9, 0, 0, 1)
       
   108 	SetAmmo(amIceGun, 9, 0, 0, 1)
       
   109 	SetAmmo(amKnife, 9, 0, 0, 1)
       
   110 	SetAmmo(amRubber, 9, 0, 0, 1)
       
   111 	SetAmmo(amAirMine, 9, 0, 0, 1)
       
   112 	SetAmmo(amDuck, 9, 0, 0, 1)
       
   113 
       
   114 	SetAmmo(amExtraTime, 2, 0, 0, 0)
       
   115 
       
   116 end
       
   117 
       
   118 function onGameStart()
       
   119 	SendHealthStatsOff()
       
   120 	ShowMission(loc("Big Armory"), loc("Scenario"), loc("Kill all enemy hedgehogs in a single turn."), -amBazooka, 0) 
       
   121 	SetWind(15)
       
   122 end
       
   123 
       
   124 function onGameTick20()
       
   125 	if not gameStarted and turnNo == 1 and TurnTimeLeft < TurnTime then
       
   126 		gameStarted = true
       
   127 	elseif gameStarted and not gameEnded then
       
   128 		if isPlayerAlive() then
       
   129 			if enemyHogsLeft - countPending() <= 0 then
       
   130 				TurnTimeLeft = 0
       
   131 				if delayGear then
       
   132 					DeleteGear(delayGear)
       
   133 				end
       
   134 				return
       
   135 			elseif (enemyHogsLeft > 0) and TurnTimeLeft < 40 then
       
   136 				if not toleranceTimer and waitGears <= 0 then
       
   137 					SetInputMask(0)
       
   138 					SetGearMessage(playerHog, 0)
       
   139 					if not minePlaced then
       
   140 						TurnTimeLeft = 10000000
       
   141 					end
       
   142 					if hasAttacked then
       
   143 						if minePlaced then
       
   144 							toleranceTimer = 12000
       
   145 						else
       
   146 							toleranceTimer = 7500
       
   147 						end
       
   148 					else
       
   149 						PlaySound(sndBoring, playerHog)
       
   150 						toleranceTimer = 5020
       
   151 					end
       
   152 					return
       
   153 				end
       
   154 			end
       
   155 			if toleranceTimer ~= nil then
       
   156 				if toleranceTimer % 1000 == 0 and toleranceTimer > 0 and toleranceTimer <= 5000 then
       
   157 					AddCaption(string.format(loc("Mission failure in %d s"), div(toleranceTimer, 1000)), 0xFFFFFFFF, capgrpGameState)
       
   158 				end
       
   159 				if toleranceTimer == 4000 then
       
   160 					PlaySound(sndCountdown4)
       
   161 				elseif toleranceTimer == 3000 then
       
   162 					PlaySound(sndCountdown3)
       
   163 				elseif toleranceTimer == 2000 then
       
   164 					PlaySound(sndCountdown2)
       
   165 				elseif toleranceTimer == 1000 then
       
   166 					PlaySound(sndCountdown1)
       
   167 				end
       
   168 				if waitGears <= 0 then
       
   169 					if toleranceTimer <= 0 then
       
   170 						lose()
       
   171 						return
       
   172 					end
       
   173 					toleranceTimer = toleranceTimer - 20
       
   174 				end
       
   175 				return
       
   176 			end
       
   177 		end
       
   178 	end
       
   179 end
       
   180 
       
   181 function onGearAdd(gear)
       
   182 	local gt = GetGearType(gear)
       
   183 	if gt == gtIceGun or gt == gtPickHammer or gt == gtSineGunShot or gt == gtCake
       
   184 	or gt == gtTeleport or gt == gtFlamethrower or gt == gtBallGun or gt == gtSeduction
       
   185 	or gt == gtAirAttack or gt == gtMine or gt == gtSMine or gt == gtAirMine
       
   186 	or (isWaitGear(gear) and gt ~= gtFlame) then
       
   187 		--[[ This is a hack to prevent the turn from instantly ending
       
   188 		after using a weapon with a retreat time of 0. For some reason, there would be
       
   189 		are also problems with the hellish-hand grenade without this hack.
       
   190 		It spawns an invisible grenade with disabled gravity at (0,0) with a
       
   191 		high timer, which will delay the end of the turn. ]]
       
   192 		if delayGear == nil then
       
   193 			delayGear = AddGear(0, 0, gtGrenade, gstNoGravity + gstInvisible, 0, 0, 2147483647)
       
   194 		end
       
   195 	end
       
   196 	if gt == gtMine or gt == gtSMine or gt == gtAirMine then
       
   197 		minePlaced = true
       
   198 	end
       
   199 	if isWaitGear(gear) then
       
   200 		waitGears = waitGears + 1
       
   201 	end
       
   202 	if gt == gtAirAttack then
       
   203 		hasAttacked = true
       
   204 	end
       
   205 end
       
   206 
       
   207 function onGearDelete(gear)
       
   208 	if isWaitGear(gear) then
       
   209 		waitGears = waitGears - 1
       
   210 	end
       
   211 	if GetGearType(gear) == gtHedgehog then
       
   212 		if GetHogTeamName(gear) == enemyTeamName then
       
   213 			enemyHogsLeft = enemyHogsLeft - 1
       
   214 			pendingDeaths[gear] = nil
       
   215 			if enemyHogsLeft <= 0 then
       
   216 				win()
       
   217 			end
       
   218 		end
       
   219 	end
       
   220 end
       
   221 
       
   222 function countPending()
       
   223 	local p = 0
       
   224 	for h, v in pairs(pendingDeaths) do
       
   225 		if v then
       
   226 			p = p + 1
       
   227 		end
       
   228 	end
       
   229 	return p
       
   230 end
       
   231 
       
   232 function isPlayerAlive()
       
   233 	if GetGearType(playerHog) == gtHedgehog then
       
   234 		if GetHealth(playerHog) == 0 then
       
   235 			return false
       
   236 		else
       
   237 			local _, gearDamage
       
   238 			_, _, _, _, _, _, _, _, _, _, _, gearDamage = GetGearValues(playerHog)
       
   239 			return (GetHealth(playerHog) - gearDamage) > 0
       
   240 		end
       
   241 	else
       
   242 		return false
       
   243 	end
       
   244 end
       
   245 
       
   246 function onGearDamage(gear, damage)
       
   247 	if GetGearType(gear) == gtHedgehog then
       
   248 		if GetHogTeamName(gear) == enemyTeamName then
       
   249 			local _, gearDamage
       
   250 			_, _, _, _, _, _, _, _, _, _, _, gearDamage = GetGearValues(gear)
       
   251 			if (GetHealth(gear) - gearDamage) <= 0 then
       
   252 				pendingDeaths[gear] = true
       
   253 			end
       
   254 		end
       
   255 	end
       
   256 end
       
   257 
       
   258 function isWaitGear(gear)
       
   259 	local gt = GetGearType(gear)
       
   260 	return gt == gtBall or gt == gtHellishBomb or gt == gtWatermelon or gt == gtMelonPiece
       
   261 		or (gt == gtFlame and band(GetState(gear), gsttmpFlag) == 0)
       
   262 		or gt == gtDrill or gt == gtAirAttack or gt == gtAirBomb or gt == gtCluster
       
   263 		or gt == gtEgg or gt == gtHammerHit or gt == gtNapalmBomb or gt == gtPoisonCloud
       
   264 		or gt == gtGasBomb
       
   265 end
       
   266 
       
   267 function onNewTurn()
       
   268 	turnNo = turnNo + 1
       
   269 	if turnNo > 1 then
       
   270 		PlaySound(sndBoring, playerHog)
       
   271 		lose()
       
   272 	end
       
   273 end
       
   274 
       
   275 function onHogAttack(ammoType)
       
   276 	-- Set hasAttacked if hog attacked NOT with a non-turn ending weapon
       
   277 	if ammoType ~= amNothing and ammoType ~= amSkip and ammoType ~= amJetpack and ammoType ~= amGirder and ammoType ~= amRubber
       
   278 		and ammoType ~= amLandGun and ammoType ~= amParachute and ammoType ~= amResurrector and ammoType ~= amRope and ammoType ~= amSwitcher
       
   279 		and ammoType ~= amExtraDamage and ammoType ~= amExtraTime and ammoType ~= amLowGravity and ammoType ~= amInvulnerable
       
   280 		and ammoType ~= amLaserSight and ammoType ~= amVampiric and ammoType ~= amPortalGun and ammoType ~= amSnowball then
       
   281 		hasAttacked = true
       
   282 	end
       
   283 	if ammoType == amSkip and enemyHogsLeft > 0 then
       
   284 		PlaySound(sndCoward, playerHog)
       
   285 		lose()
       
   286 		return
       
   287 	end
       
   288 end
       
   289 
       
   290 function lose()
       
   291 	if not gameEnded then
       
   292 		PlaySound(sndStupid, playerHog)
       
   293 		local mission, achievement
       
   294 		mission = loc("You failed to kill all enemies in this turn.")
       
   295 		achievement = loc("You failed to kill all enemies in a single turn.")
       
   296 		AddCaption(loc("Mission failed!"), 0xFFFFFFFF, capgrpGameState)
       
   297 		ShowMission(loc("Big Armory"), loc("Scenario"), mission, -amBazooka, 5000) 
       
   298 		SendStat(siGameResult, loc("You lose!"))
       
   299 		SendStat(siCustomAchievement, achievement)
       
   300 		SendStat(siPlayerKills, tostring(0), enemyTeamName)
       
   301 		SendStat(siPlayerKills, tostring(8-enemyHogsLeft), playerTeamName)
       
   302 		gameEnded = true
       
   303 		EndGame()
       
   304 	end
       
   305 end
       
   306 
       
   307 function win()
       
   308 	if not gameEnded then
       
   309 		AddCaption(loc("Victory!"), 0xFFFFFFFF, capgrpGameState)
       
   310 		ShowMission(loc("Big Armory"), loc("Scenario"), loc("Congratulations! You win."), 4, 5000) 
       
   311 		PlaySound(sndVictory, playerHog)
       
   312 		SendStat(siGameResult, loc("You win!"))
       
   313 		SendStat(siCustomAchievement, loc("You have killed all enemies."))
       
   314 		SendStat(siPlayerKills, tostring(8-enemyHogsLeft), playerTeamName)
       
   315 		SendStat(siPlayerKills, tostring(0), enemyTeamName)
       
   316 		gameEnded = true
       
   317 		EndGame()
       
   318 	end
       
   319 end