share/hedgewars/Data/Maps/Control/map.lua
changeset 4662 63aafc9c2a81
child 4698 6f14ef3e40ae
equal deleted inserted replaced
4661:f5d858e4b634 4662:63aafc9c2a81
       
     1 --------------------------------
       
     2 -- CONTROL 0.3
       
     3 --------------------------------
       
     4 
       
     5 -- in this version
       
     6 
       
     7 ---------
       
     8 -- 0.2
       
     9 ---------
       
    10 -- fixed score display errrors
       
    11 -- added missing resurrection effects
       
    12 -- moved hogs off control points if thats where they started
       
    13 -- added sanity limit for the above
       
    14 -- added tint tags to display clan score on each point as it scors
       
    15 -- added gameflags filter
       
    16 -- changed scoring rate
       
    17 -- hogs now only score point DURING THEIR TURN
       
    18 -- map now accepts custom weaponsets and themes 
       
    19 -- changed win limit
       
    20 
       
    21 ---------
       
    22 -- 0.3
       
    23 ---------
       
    24 
       
    25 -- added translation support
       
    26 
       
    27 -----------------
       
    28 --script begins
       
    29 -----------------
       
    30 
       
    31 loadfile(GetDataPath() .. "Scripts/Locale.lua")()
       
    32 
       
    33 ---------------------------------------------------------------
       
    34 ----------lots of bad variables and things
       
    35 ----------because someone is too lazy
       
    36 ----------to read about tables properly
       
    37 ------------------ "Oh well, they probably have the memory"
       
    38 
       
    39 local gameWon = false
       
    40 
       
    41 local vCirc = {}
       
    42 local vCircCount = 0
       
    43 
       
    44 local hGCount = 0
       
    45 
       
    46 local vCircX = {}
       
    47 local vCircY = {}
       
    48 local vCircMinA = {}
       
    49 local vCircMaxA = {}
       
    50 local vCircType = {}
       
    51 local vCircPulse = {}
       
    52 local vCircFuckAll = {}
       
    53 local vCircRadius = {}
       
    54 local vCircWidth = {}
       
    55 local vCircCol = {}
       
    56 
       
    57 --------------------------
       
    58 -- hog and team tracking variales
       
    59 --------------------------
       
    60 
       
    61 local numhhs = 0 -- store number of hedgehogs
       
    62 local hhs = {} -- store hedgehog gears
       
    63 
       
    64 local numTeams --  store the number of teams in the game
       
    65 local teamNameArr = {}	-- store the list of teams
       
    66 local teamClan = {}
       
    67 local teamSize = {}	-- store how many hogs per team
       
    68 local teamIndex = {} -- at what point in the hhs{} does each team begin
       
    69 
       
    70 local teamComment = {}
       
    71 local teamScore = {}
       
    72 
       
    73 --------------------------------
       
    74 --zone and teleporter variables
       
    75 --------------------------------
       
    76 
       
    77 --local redTel
       
    78 --local orangeTel
       
    79 --local areaArr = {} -- no longer used
       
    80 
       
    81 local cPoint = {}
       
    82 local cOwnerClan = {}
       
    83 
       
    84 local zXMin = {}
       
    85 local zWidth = {}
       
    86 local zYMin = {}
       
    87 local zHeight = {}
       
    88 local zOccupied = {}
       
    89 local zCount = 0
       
    90 
       
    91 ------------------------
       
    92 -- zone methods
       
    93 ------------------------
       
    94 -- see on gameTick also
       
    95 
       
    96 function CreateZone(xMin, yMin, width, height)
       
    97 
       
    98 
       
    99 	zXMin[zCount] = xMin
       
   100 	zYMin[zCount] = yMin
       
   101 	zWidth[zCount] = width
       
   102 	zHeight[zCount] = height
       
   103 	zOccupied[zCount] = false
       
   104 	zCount = zCount + 1
       
   105 
       
   106 	return (zCount-1)
       
   107 
       
   108 end
       
   109 
       
   110 function GearIsInZone(gear, zI)
       
   111 
       
   112 	if (GetX(gear) > zXMin[zI]) and (GetX(gear) < (zXMin[zI]+zWidth[zI])) and (GetY(gear) > zYMin[zI]) and (GetY(gear) < (zYMin[zI]+zHeight[zI])) then
       
   113 		zOccupied[zI] = true
       
   114 	else
       
   115 		zOccupied[zI] = false
       
   116 	end
       
   117 
       
   118 	return zOccupied[zI]
       
   119 
       
   120 end
       
   121 
       
   122 function ZonesAreEmpty()
       
   123 
       
   124 	okay = true
       
   125 
       
   126 	for i = 0,(zCount-1) do
       
   127 				
       
   128 		for k = 0, (numhhs-1) do
       
   129 			if (hhs[k] ~= nil) then
       
   130 			if (GearIsInZone(hhs[k],i)) == true then
       
   131 				FindPlace(hhs[k], false, 0, LAND_WIDTH, true)
       
   132 				okay = false
       
   133 			end
       
   134 			end
       
   135 		end
       
   136 	end
       
   137 
       
   138 	return(okay)
       
   139 
       
   140 end
       
   141 
       
   142 function CheckZones()
       
   143 
       
   144 	for i = 0,(zCount-1) do
       
   145 		SetVisualGearValues(vCirc[i], vCircX[i], vCircY[i], vCircMinA[i], vCircMaxA[i], vCircType[i], vCircPulse[i], vCircFuckAll[i], vCircRadius[i], vCircWidth[i], 0xffffffff)
       
   146 		cOwnerClan[i] = nil
       
   147 		for k = 0, (numhhs-1) do
       
   148 			if (hhs[k] ~= nil) then
       
   149 			if (GearIsInZone(hhs[k],i)) == true then
       
   150 
       
   151 				if cOwnerClan[i] ~= nil then
       
   152 					if cOwnerClan[i] ~= GetHogClan(hhs[k]) then 
       
   153 						--if the hog now being compared is different to one that is also here and was previously compared
       
   154 						
       
   155 						SetVisualGearValues(vCirc[i], vCircX[i], vCircY[i], vCircMinA[i], vCircMaxA[i], vCircType[i], vCircPulse[i], vCircFuckAll[i], vCircRadius[i], vCircWidth[i], 0xffffffff)						
       
   156 						--SetVisualGearValues(vCirc[i], 2739, 1378, 20, 255, 1, 10, 0, 300, 5, 0xffffffff)
       
   157 	
       
   158 						cOwnerClan[i] = 10 -- this means conflicted
       
   159 					end
       
   160 				elseif cOwnerClan[i] == nil then
       
   161 					cOwnerClan[i] = GetHogClan(hhs[k])
       
   162 					--SetVisualGearValues(vCirc[i], 2739, 1378, 20, 255, 1, 10, 0, 300, 5, GetClanColor( GetHogClan(hhs[k])) )
       
   163 					SetVisualGearValues(vCirc[i], vCircX[i], vCircY[i], vCircMinA[i], vCircMaxA[i], vCircType[i], vCircPulse[i], vCircFuckAll[i], vCircRadius[i], vCircWidth[i], GetClanColor( GetHogClan(hhs[k])))
       
   164 	
       
   165 				end
       
   166 
       
   167 			end
       
   168 			end
       
   169 		end
       
   170 
       
   171 	end
       
   172 
       
   173 end
       
   174 
       
   175 function AwardPoints()
       
   176 		
       
   177 	for i = 0,(zCount-1) do
       
   178 		-- give score to all players controlling points		
       
   179 		--if (cOwnerClan[i] ~= nil) and (cOwnerClan[i] ~= 10) then
       
   180 		--	teamScore[cOwnerClan[i]] = teamScore[cOwnerClan[i]] + 1
       
   181 		--end
       
   182 		
       
   183 		-- only give score to the player currently in control		
       
   184 		if CurrentHedgehog ~= nil then		
       
   185 			if cOwnerClan[i] == GetHogClan(CurrentHedgehog) then
       
   186 				teamScore[cOwnerClan[i]] = teamScore[cOwnerClan[i]] + 1
       
   187 			end
       
   188 		end
       
   189 	end
       
   190 
       
   191 	-- i want to show all the tags at once as having the SAME score not 1,2,3,4 so alas, repeating the loop seems needed	
       
   192 	for i = 0,(zCount-1) do			
       
   193 		if CurrentHedgehog ~= nil then		
       
   194 			if cOwnerClan[i] == GetHogClan(CurrentHedgehog) then
       
   195 				g = AddVisualGear(vCircX[i], vCircY[i], vgtHealthTag, 100, False)
       
   196 				SetVisualGearValues(g, vCircX[i], vCircY[i], 0, 0, 0, 0, 0, teamScore[cOwnerClan[i]], 1500, GetClanColor(cOwnerClan[i]))
       
   197 			end
       
   198 		end
       
   199 	end
       
   200 
       
   201 end
       
   202 
       
   203 -----------------
       
   204 -- general methods
       
   205 ------------------
       
   206 
       
   207 function RebuildTeamInfo()
       
   208 
       
   209 
       
   210 	-- make a list of individual team names
       
   211 	for i = 0, 5 do
       
   212 		teamNameArr[i] = " " -- = i
       
   213 		teamSize[i] = 0
       
   214 		teamIndex[i] = 0
       
   215 		teamScore[i] = 0
       
   216 	end
       
   217 	numTeams = 0
       
   218 
       
   219 	for i = 0, (numhhs-1) do
       
   220 
       
   221 		z = 0
       
   222 		unfinished = true
       
   223 		while(unfinished == true) do
       
   224 
       
   225 			newTeam = true
       
   226 			tempHogTeamName = GetHogTeamName(hhs[i]) -- this is the new name
       
   227 
       
   228 			if tempHogTeamName == teamNameArr[z] then
       
   229 				newTeam = false
       
   230 				unfinished = false
       
   231 			end
       
   232 
       
   233 			z = z + 1
       
   234 
       
   235 			if z == TeamsCount then
       
   236 				unfinished = false
       
   237 				if newTeam == true then
       
   238 					teamNameArr[numTeams] = tempHogTeamName
       
   239 					numTeams = numTeams + 1
       
   240 				end
       
   241 			end
       
   242 
       
   243 		end
       
   244 
       
   245 	end
       
   246 
       
   247 	-- find out how many hogs per team, and the index of the first hog in hhs
       
   248 	for i = 0, (numTeams-1) do
       
   249 		for z = 0, (numhhs-1) do
       
   250 			if GetHogTeamName(hhs[z]) == teamNameArr[i] then
       
   251 				teamClan[i] = GetHogClan(hhs[z])				
       
   252 				if teamSize[i] == 0 then
       
   253 					teamIndex[i] = z -- should give starting index
       
   254 				end
       
   255 				teamSize[i] = teamSize[i] + 1
       
   256 				--add a pointer so this hog appears at i in hhs
       
   257 			end
       
   258 		end
       
   259 
       
   260 	end
       
   261 
       
   262 end
       
   263 
       
   264 ------------------------
       
   265 -- game methods
       
   266 ------------------------
       
   267 
       
   268 function onGameInit()
       
   269 
       
   270 	-- Things we don't modify here will use their default values.
       
   271 	--GameFlags = gfInfAttack + gfSolidLand -- Game settings and rules
       
   272 	
       
   273 	GameFlags = band(bor(GameFlags, gfInfAttack + gfSolidLand), bnot(gfKing + gfForts))
       
   274 		
       
   275 	SuddenDeathTurns = 99 -- suddendeath is off, effectively
       
   276 
       
   277 end
       
   278 
       
   279 
       
   280 function onGameStart()
       
   281 
       
   282 	ShowMission(loc("CONTROL v0.3"), loc("by mikade"), loc("Control pillars to score points."), 0, 0)
       
   283 
       
   284 
       
   285 	-- build zones
       
   286 	cPoint[0] = CreateZone(571,47,120,80)
       
   287 	cPoint[1] = CreateZone(1029,643,120,80)
       
   288 	cPoint[2] = CreateZone(322,1524,120,80)
       
   289 	cPoint[3] = CreateZone(1883,38,120,80)
       
   290 	cPoint[4] = CreateZone(3821,46,120,80)
       
   291 	cPoint[5] = CreateZone(2679,1338,120,80)
       
   292 
       
   293 	vCircX[0], vCircY[0] = 631, 82
       
   294 	vCircX[1], vCircY[1] = 1088, 684
       
   295 	vCircX[2], vCircY[2] = 381, 1569
       
   296 	vCircX[3], vCircY[3] = 1942, 77
       
   297 	vCircX[4], vCircY[4] = 3883, 89
       
   298 	vCircX[5], vCircY[5] = 2739, 1378
       
   299 	
       
   300 	for i = 0, 5 do	
       
   301 		vCirc[i] = AddVisualGear(0,0,vgtCircle,0,true)
       
   302 		vCircMinA[i] = 20
       
   303 		vCircMaxA[i] = 255
       
   304 		vCircType[i] = 1
       
   305 		vCircPulse[i] = 10
       
   306 		vCircFuckAll[i] = 0
       
   307 		vCircRadius[i] = 300
       
   308 		vCircWidth[i] = 5
       
   309 		vCircCol[i] = 0xffffffff
       
   310 
       
   311 		SetVisualGearValues(vCirc[i], vCircX[i], vCircY[i], vCircMinA[i], vCircMaxA[i], vCircType[i], vCircPulse[i], vCircFuckAll[i], vCircRadius[i], vCircWidth[i], vCircCol[i])
       
   312 	end
       
   313 
       
   314 	--zxc = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
       
   315 	--SetVisualGearValues(zxc, 1000,1000, 20, 255, 1,    10,                     0,         100,        1,      GetClanColor(0))
       
   316 					--minO,max0 -glowyornot	--pulsate timer	 -- fuckall      -- radius -- width  -- colour
       
   317 
       
   318 	--new improved placement schematics aw yeah
       
   319 	RebuildTeamInfo()
       
   320 
       
   321 
       
   322 	--SetGearPosition(hhs[0], 631, 82)
       
   323 	--SetGearPosition(hhs[1], 1088, 684)
       
   324 	--SetGearPosition(hhs[2], 381, 1569)
       
   325 
       
   326 	-- reposition hogs if they are on control points until they are not or sanity limit kicks in
       
   327 	reN = 0
       
   328 	--zz = 0
       
   329 	while (reN < 10) do
       
   330 		if ZonesAreEmpty() == false then
       
   331 			reN = reN + 1	
       
   332 			--zz = zz + 1	
       
   333 			--SetGearPosition(hhs[0], 631, 82) -- put this in here to thwart attempts at repositioning and test sanity limit	
       
   334 		else
       
   335 			reN = 15		
       
   336 		end
       
   337 		--AddCaption(zz) -- number of times it took to work
       
   338 	end
       
   339 
       
   340 end
       
   341 
       
   342 
       
   343 function onNewTurn()
       
   344 
       
   345 		
       
   346 	if lastTeam ~= GetHogTeamName(CurrentHedgehog) then
       
   347 		lastTeam = GetHogTeamName(CurrentHedgehog)
       
   348 	end
       
   349 
       
   350 	if gameWon == false then
       
   351 	
       
   352 		for i = 0, (numTeams-1) do
       
   353 			if teamScore[i] >= 150 then
       
   354 				gameWon = true
       
   355 				winnerClan = i			
       
   356 			end
       
   357 		end
       
   358 
       
   359 		if gameWon == true then
       
   360 			for i = 0, (numhhs-1) do
       
   361 				if hhs[i] ~= nil then				
       
   362 					if GetHogClan(hhs[i]) ~= winnerClan then
       
   363 						SetEffect(hhs[i], heResurrectable, false)
       
   364 						SetHealth(hhs[i],0)
       
   365 					end
       
   366 				end			
       
   367 			end
       
   368 			TurnTimeLeft = 1
       
   369 		end
       
   370 
       
   371 		for i = 0,5 do
       
   372 				if teamNameArr[i] ~= " " then				-- i
       
   373 					teamComment[i] = teamNameArr[i] .. ": " .. teamScore[teamClan[i]] .. loc (" points|")
       
   374 				elseif teamNameArr[i] == " " then
       
   375 					teamComment[i] = "|"
       
   376 				end
       
   377 			end
       
   378 			ShowMission(loc("CONTROL"), loc("Team Scores:"), teamComment[0] .. teamComment[1] .. teamComment[2] .. teamComment[3] .. teamComment[4] .. teamComment[5], 0, 1600)
       
   379 	
       
   380 	end
       
   381 
       
   382 end
       
   383 
       
   384 function onGameTick()
       
   385 
       
   386 	vCircCount = vCircCount + 1
       
   387 	if (vCircCount >= 500) and (gameWon == false) then
       
   388 		vCircCount = 0
       
   389 		CheckZones()
       
   390 		--AwardPoints()
       
   391 
       
   392 
       
   393 		--[[for i = 0,5 do
       
   394 
       
   395 			if teamNameArr[i] ~= " " then				-- i
       
   396 				teamComment[i] = teamNameArr[i] .. ": " .. teamScore[teamClan[i] ] .. " points|"
       
   397 			elseif teamNameArr[i] == " " then
       
   398 				teamComment[i] = "|"
       
   399 			end
       
   400 		end
       
   401 		
       
   402 		ShowMission("CONTROL", "Team Scores:", teamComment[0] .. teamComment[1] .. teamComment[2] .. teamComment[3] .. teamComment[4] .. teamComment[5], 0, 1600)]]
       
   403 
       
   404 	end	
       
   405 
       
   406 	-- things we wanna check often
       
   407 	if (CurrentHedgehog ~= nil) then
       
   408 	--	AddCaption(GetX(CurrentHedgehog) .. "; " .. GetY(CurrentHedgehog))
       
   409 		--AddCaption(teamNameArr[0] .. " : " .. teamScore[0])
       
   410 		--AddCaption(GetHogTeamName(CurrentHedgehog) .. " : " .. teamScore[GetHogClan(CurrentHedgehog)]) -- this end up 1?
       
   411 		
       
   412 		-- huh? the first clan added seems to be clan 1, not 0 ??
       
   413 
       
   414 	end
       
   415 
       
   416 	hGCount = hGCount + 1
       
   417 	if (hGCount >= 2000) and (gameWon == false) then
       
   418 		hGCount = 0
       
   419 		AwardPoints()
       
   420 	end
       
   421 
       
   422 end
       
   423 
       
   424 function onGearResurrect(gear)
       
   425 	AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false)
       
   426 end
       
   427 
       
   428 
       
   429 function onGearAdd(gear)
       
   430 
       
   431 	if GetGearType(gear) == gtHedgehog then
       
   432 
       
   433 		hhs[numhhs] = gear
       
   434 		numhhs = numhhs + 1
       
   435 		SetEffect(gear, heResurrectable, true)
       
   436 
       
   437 	end
       
   438 
       
   439 end
       
   440 
       
   441 function onGearDelete(gear)
       
   442 
       
   443 	if GetGearType(gear) == gtHedgehog then
       
   444 	--AddCaption("gear deleted!")
       
   445 		for i = 0, (numhhs-1) do
       
   446 			if gear == hhs[i] then
       
   447 				hhs[i] = nil
       
   448 				--AddCaption("for real")	
       
   449 			end		
       
   450 		end
       
   451 	end
       
   452 
       
   453 end