share/hedgewars/Data/Missions/Scenario/Big_Armory.lua
changeset 13056 b1a230d21a48
parent 12231 b4878d6cd96e
child 13057 8b44518d1002
equal deleted inserted replaced
13055:5ceb8b0632c4 13056:b1a230d21a48
       
     1 HedgewarsScriptLoad("/Scripts/SimpleMission.lua")
     1 HedgewarsScriptLoad("/Scripts/Locale.lua")
     2 HedgewarsScriptLoad("/Scripts/Locale.lua")
     2 
     3 
     3 local playerHog
     4 local heroAmmo = {}
     4 local playerTeamName = loc("Pro Killers")
     5 for a=0, amDuck do
     5 local enemyTeamName = loc("Galaxy Guardians")
     6 	if a == amExtraTime then
     6 local enemyTeam1 = {
     7 		heroAmmo[a] = 2
     7 	{name=loc("Rocket"), x=796, y=1184},
     8 	elseif a ~= amNothing then
     8 	{name=loc("Star"), x=733, y=1525},
     9 		heroAmmo[a] = 100
     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", "Default", "cm_scout")
       
    43 	playerHog = AddHog(loc("Ultrasoldier"), 0, 100, "Terminator_Glasses")
       
    44 	SetGearPosition(playerHog, 543, 1167)
       
    45 
       
    46 	AddTeam(enemyTeamName, 0xF5F808, "Earth", "Island", "Default", "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
    10 	end
    52 end
    11 end
    53 
    12 
    54 function onAmmoStoreInit()
    13 SimpleMission({
       
    14 	missionTitle = loc("Big Armory"),
       
    15 	wind = 15,
       
    16 	initVars = {
       
    17 		TurnTime = 45000,
       
    18 		Seed = "{7e34a56b-ee7b-4fe1-8f30-352a998f3f6a}",
       
    19 		GameFlags = gfDisableWind + gfDisableLandObjects,
       
    20 		Theme = "EarthRise",
       
    21 		MapGen = mgRandom,
       
    22 		MapFeatureSize = 12,
       
    23 	},
       
    24 	teams = {
       
    25 		{ name = loc("Pro Killers"),
       
    26 		clanID = 0,
       
    27 		flag = "cm_scout",
       
    28 		grave = "Bone",
       
    29 		hogs = {
       
    30 			{
       
    31 			name = loc("Ultrasoldier"),
       
    32 			health = 100,
       
    33 			x = 543, y = 1167,
       
    34 			hat = "Terminator_Glasses",
       
    35 			ammo = heroAmmo,
       
    36 			}
       
    37 		}, },
    55 
    38 
    56 	SetAmmo(amGrenade, 9, 0, 0, 1)
    39 		{ name = loc("Galaxy Guardians"),
    57 	SetAmmo(amClusterBomb, 9, 0, 0, 1)
    40 		clanID = 8,
    58 	SetAmmo(amBazooka, 9, 0, 0, 1)
    41 		flag = "cm_galaxy",
    59 	SetAmmo(amBee, 9, 0, 0, 1)
    42 		grave = "Earth",
    60 	SetAmmo(amShotgun, 9, 0, 0, 1)
    43 		hogs = {
    61 	SetAmmo(amPickHammer, 9, 0, 0, 1)
    44 			{name=loc("Rocket"), x=796, y=1184, faceLeft=true},
    62 	SetAmmo(amSkip, 9, 0, 0, 1)
    45 			{name=loc("Star"), x=733, y=1525, faceLeft=true},
    63 	SetAmmo(amRope, 9, 0, 0, 1)
    46 			{name=loc("Asteroid"), x=738, y=1855, faceLeft=true},
    64 	SetAmmo(amMine, 9, 0, 0, 1)
    47 			{name=loc("Comet"), x=937, y=1318, faceLeft=true},
    65 	SetAmmo(amDEagle, 9, 0, 0, 1)
    48 			{name=loc("Sunflame"), x=3424, y=1536},
    66 	SetAmmo(amDynamite, 9, 0, 0, 1)
    49 			{name=loc("Eclipse"), x=3417, y=1081},
    67 	SetAmmo(amFirePunch, 9, 0, 0, 1)
    50 			{name=loc("Jetpack"), x=2256, y=1246},
    68 	SetAmmo(amWhip, 9, 0, 0, 1)
    51 			{name=loc("Void"), x=1587, y=1231, faceLeft=true},
    69 	SetAmmo(amBaseballBat, 9, 0, 0, 1)
    52 		}, },
    70 	SetAmmo(amParachute, 9, 0, 0, 1)
    53 	},
    71 	SetAmmo(amAirAttack, 9, 0, 0, 1)
    54 	customNonGoals = {
    72 	SetAmmo(amMineStrike, 9, 0, 0, 1)
    55 		{ type = "turns", turns = 1, failText = loc("You failed to kill all enemies in a single turn.") }
    73 	SetAmmo(amBlowTorch, 9, 0, 0, 1)
    56 	},
    74 	SetAmmo(amGirder, 9, 0, 0, 1)
    57 	customGoalCheck = "turnEnd",
    75 	SetAmmo(amTeleport, 9, 0, 0, 1)
    58 	goalText = loc("Kill all enemy hedgehogs in a single turn."),
    76 	SetAmmo(amSwitch, 9, 0, 0, 1)
    59 })
    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 waitGears <= 0 then
       
   160 					if toleranceTimer <= 0 then
       
   161 						lose()
       
   162 						return
       
   163 					end
       
   164 					toleranceTimer = toleranceTimer - 20
       
   165 				end
       
   166 				return
       
   167 			end
       
   168 		end
       
   169 	end
       
   170 end
       
   171 
       
   172 function onGearAdd(gear)
       
   173 	local gt = GetGearType(gear)
       
   174 	if gt == gtIceGun or gt == gtPickHammer or gt == gtSineGunShot or gt == gtCake
       
   175 	or gt == gtTeleport or gt == gtFlamethrower or gt == gtBallGun or gt == gtSeduction
       
   176 	or gt == gtAirAttack or gt == gtMine or gt == gtSMine or gt == gtAirMine
       
   177 	or (isWaitGear(gear) and gt ~= gtFlame) then
       
   178 		--[[ This is a hack to prevent the turn from instantly ending
       
   179 		after using a weapon with a retreat time of 0. For some reason, there would be
       
   180 		are also problems with the hellish-hand grenade without this hack.
       
   181 		It spawns an invisible grenade with disabled gravity at (0,0) with a
       
   182 		high timer, which will delay the end of the turn. ]]
       
   183 		if delayGear == nil then
       
   184 			delayGear = AddGear(0, 0, gtGrenade, gstNoGravity + gstInvisible, 0, 0, 2147483647)
       
   185 		end
       
   186 	end
       
   187 	if gt == gtMine or gt == gtSMine or gt == gtAirMine then
       
   188 		minePlaced = true
       
   189 	end
       
   190 	if isWaitGear(gear) then
       
   191 		waitGears = waitGears + 1
       
   192 	end
       
   193 	if gt == gtAirAttack then
       
   194 		hasAttacked = true
       
   195 	end
       
   196 end
       
   197 
       
   198 function onGearDelete(gear)
       
   199 	if isWaitGear(gear) then
       
   200 		waitGears = waitGears - 1
       
   201 	end
       
   202 	if GetGearType(gear) == gtHedgehog then
       
   203 		if GetHogTeamName(gear) == enemyTeamName then
       
   204 			enemyHogsLeft = enemyHogsLeft - 1
       
   205 			pendingDeaths[gear] = nil
       
   206 			if enemyHogsLeft <= 0 then
       
   207 				win()
       
   208 			end
       
   209 		end
       
   210 	end
       
   211 end
       
   212 
       
   213 function countPending()
       
   214 	local p = 0
       
   215 	for h, v in pairs(pendingDeaths) do
       
   216 		if v then
       
   217 			p = p + 1
       
   218 		end
       
   219 	end
       
   220 	return p
       
   221 end
       
   222 
       
   223 function isPlayerAlive()
       
   224 	if GetGearType(playerHog) == gtHedgehog then
       
   225 		if GetHealth(playerHog) == 0 then
       
   226 			return false
       
   227 		else
       
   228 			local _, gearDamage
       
   229 			_, _, _, _, _, _, _, _, _, _, _, gearDamage = GetGearValues(playerHog)
       
   230 			return (GetHealth(playerHog) - gearDamage) > 0
       
   231 		end
       
   232 	else
       
   233 		return false
       
   234 	end
       
   235 end
       
   236 
       
   237 function onGearDamage(gear, damage)
       
   238 	if GetGearType(gear) == gtHedgehog then
       
   239 		if GetHogTeamName(gear) == enemyTeamName then
       
   240 			local _, gearDamage
       
   241 			_, _, _, _, _, _, _, _, _, _, _, gearDamage = GetGearValues(gear)
       
   242 			if (GetHealth(gear) - gearDamage) <= 0 then
       
   243 				pendingDeaths[gear] = true
       
   244 			end
       
   245 		end
       
   246 	end
       
   247 end
       
   248 
       
   249 function isWaitGear(gear)
       
   250 	local gt = GetGearType(gear)
       
   251 	return gt == gtBall or gt == gtHellishBomb or gt == gtWatermelon or gt == gtMelonPiece
       
   252 		or (gt == gtFlame and band(GetState(gear), gsttmpFlag) == 0)
       
   253 		or gt == gtDrill or gt == gtAirAttack or gt == gtAirBomb or gt == gtCluster
       
   254 		or gt == gtEgg or gt == gtHammerHit or gt == gtNapalmBomb or gt == gtPoisonCloud
       
   255 		or gt == gtGasBomb
       
   256 end
       
   257 
       
   258 function onNewTurn()
       
   259 	turnNo = turnNo + 1
       
   260 	if turnNo > 1 then
       
   261 		PlaySound(sndBoring, playerHog)
       
   262 		lose()
       
   263 	end
       
   264 end
       
   265 
       
   266 function onHogAttack(ammoType)
       
   267 	-- Set hasAttacked if hog attacked NOT with a non-turn ending weapon
       
   268 	if ammoType ~= amNothing and ammoType ~= amSkip and ammoType ~= amJetpack and ammoType ~= amGirder and ammoType ~= amRubber
       
   269 		and ammoType ~= amLandGun and ammoType ~= amParachute and ammoType ~= amResurrector and ammoType ~= amRope and ammoType ~= amSwitcher
       
   270 		and ammoType ~= amExtraDamage and ammoType ~= amExtraTime and ammoType ~= amLowGravity and ammoType ~= amInvulnerable
       
   271 		and ammoType ~= amLaserSight and ammoType ~= amVampiric and ammoType ~= amPortalGun and ammoType ~= amSnowball then
       
   272 		hasAttacked = true
       
   273 	end
       
   274 	if ammoType == amSkip and enemyHogsLeft > 0 then
       
   275 		PlaySound(sndCoward, playerHog)
       
   276 		lose()
       
   277 		return
       
   278 	end
       
   279 end
       
   280 
       
   281 function lose()
       
   282 	if not gameEnded then
       
   283 		PlaySound(sndStupid, playerHog)
       
   284 		local mission, achievement
       
   285 		mission = loc("You failed to kill all enemies in this turn.")
       
   286 		achievement = loc("You failed to kill all enemies in a single turn.")
       
   287 		AddCaption(loc("Mission failed!"), 0xFFFFFFFF, capgrpGameState)
       
   288 		ShowMission(loc("Big Armory"), loc("Scenario"), mission, -amBazooka, 5000) 
       
   289 		SendStat(siGameResult, loc("You lose!"))
       
   290 		SendStat(siCustomAchievement, achievement)
       
   291 		SendStat(siPlayerKills, tostring(0), enemyTeamName)
       
   292 		SendStat(siPlayerKills, tostring(8-enemyHogsLeft), playerTeamName)
       
   293 		gameEnded = true
       
   294 		EndGame()
       
   295 	end
       
   296 end
       
   297 
       
   298 function win()
       
   299 	if not gameEnded then
       
   300 		AddCaption(loc("Victory!"), 0xFFFFFFFF, capgrpGameState)
       
   301 		ShowMission(loc("Big Armory"), loc("Scenario"), loc("Congratulations! You win."), 4, 5000) 
       
   302 		PlaySound(sndVictory, playerHog)
       
   303 		SendStat(siGameResult, loc("You win!"))
       
   304 		SendStat(siCustomAchievement, loc("You have killed all enemies."))
       
   305 		SendStat(siPlayerKills, tostring(8-enemyHogsLeft), playerTeamName)
       
   306 		SendStat(siPlayerKills, tostring(0), enemyTeamName)
       
   307 		gameEnded = true
       
   308 		EndGame()
       
   309 	end
       
   310 end