share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
changeset 12973 9e4fc0b8ed1c
parent 12972 d82e4e583805
child 12974 f92e9b1df096
equal deleted inserted replaced
12972:d82e4e583805 12973:9e4fc0b8ed1c
   235 	loc_noop("Barrel Placement Mode"),
   235 	loc_noop("Barrel Placement Mode"),
   236 	loc_noop("Weapon Crate Placement Mode"),
   236 	loc_noop("Weapon Crate Placement Mode"),
   237 	loc_noop("Utility Crate Placement Mode"),
   237 	loc_noop("Utility Crate Placement Mode"),
   238 	loc_noop("Health Crate Placement Mode"),
   238 	loc_noop("Health Crate Placement Mode"),
   239 	loc_noop("Structure Placement Mode"),
   239 	loc_noop("Structure Placement Mode"),
       
   240 }
       
   241 
       
   242 -- Frames in sprTarget for the structure images
       
   243 local catFrames = {
       
   244 	["Respawner"] = 1,
       
   245 	["Generator"] = 2,
       
   246 	["Healing Station"] = 3,
       
   247 	["Support Station"] = 4,
       
   248 	["Weapon Filter"] = 5,
       
   249 	["Teleportation Node"] = 6,
       
   250 	["Bio-Filter"] = 7,
       
   251 	["Construction Station"] = 8,
       
   252 	["Reflector Shield"] = 9,
   240 }
   253 }
   241 
   254 
   242 local catReverse = {}
   255 local catReverse = {}
   243 for c=1, #cat do
   256 for c=1, #cat do
   244 	catReverse[cat[c]] = c
   257 	catReverse[cat[c]] = c
   488 	end
   501 	end
   489 
   502 
   490 	if pType == "Bio-Filter" then
   503 	if pType == "Bio-Filter" then
   491 		table.insert(strucCircCol, colorBioFilter)
   504 		table.insert(strucCircCol, colorBioFilter)
   492 		table.insert(strucCircRadius,1000)
   505 		table.insert(strucCircRadius,1000)
   493 		frameID = 7
       
   494 	elseif pType == "Healing Station" then
   506 	elseif pType == "Healing Station" then
   495 		table.insert(strucCircCol, colorHealingStation)
   507 		table.insert(strucCircCol, colorHealingStation)
   496 		table.insert(strucCircRadius,500)
   508 		table.insert(strucCircRadius,500)
   497 		frameID = 3
       
   498 	elseif pType == "Respawner" then
   509 	elseif pType == "Respawner" then
   499 		table.insert(strucCircCol, 0)
   510 		table.insert(strucCircCol, 0)
   500 		table.insert(strucCircRadius,0)
   511 		table.insert(strucCircRadius,0)
   501 		runOnHogs(EnableHogResurrectionForThisClan)
   512 		runOnHogs(EnableHogResurrectionForThisClan)
   502 		frameID = 1
       
   503 	elseif pType == "Teleportation Node" then
   513 	elseif pType == "Teleportation Node" then
   504 		table.insert(strucCircCol, colorTeleportationNode)
   514 		table.insert(strucCircCol, colorTeleportationNode)
   505 		table.insert(strucCircRadius,350)
   515 		table.insert(strucCircRadius,350)
   506 		frameID = 6
       
   507 	elseif pType == "Generator" then
   516 	elseif pType == "Generator" then
   508 		table.insert(strucCircCol, 0)
   517 		table.insert(strucCircCol, 0)
   509 		table.insert(strucCircRadius,0)
   518 		table.insert(strucCircRadius,0)
   510 		setGearValue(tempG, "power", 0)
   519 		setGearValue(tempG, "power", 0)
   511 		frameID = 2
       
   512 	elseif pType == "Support Station" then
   520 	elseif pType == "Support Station" then
   513 		table.insert(strucCircCol, colorSupportStation)
   521 		table.insert(strucCircCol, colorSupportStation)
   514 		table.insert(strucCircRadius,500)
   522 		table.insert(strucCircRadius,500)
   515 		frameID = 4
       
   516 	elseif pType == "Construction Station" then
   523 	elseif pType == "Construction Station" then
   517 		table.insert(strucCircCol, colorConstructionStation)
   524 		table.insert(strucCircCol, colorConstructionStation)
   518 		table.insert(strucCircRadius,500)
   525 		table.insert(strucCircRadius,500)
   519 		frameID = 8
       
   520 	elseif pType == "Reflector Shield" then
   526 	elseif pType == "Reflector Shield" then
   521 		table.insert(strucCircCol, colorReflectorShield)
   527 		table.insert(strucCircCol, colorReflectorShield)
   522 		table.insert(strucCircRadius,750)
   528 		table.insert(strucCircRadius,750)
   523 		frameID = 9
       
   524 	elseif pType == "Weapon Filter" then
   529 	elseif pType == "Weapon Filter" then
   525 		table.insert(strucCircCol, colorWeaponFilter)
   530 		table.insert(strucCircCol, colorWeaponFilter)
   526 		table.insert(strucCircRadius,750)
   531 		table.insert(strucCircRadius,750)
   527 		frameID = 5
   532 	end
   528 	end
   533 	if catFrames[pType] then
   529 
   534 		frameID = catFrames[pType]
       
   535 	end
   530 
   536 
   531 	SetVisualGearValues(madness, nil, nil, 0, 0, nil, frameID, nil, visualSprite, nil, nil)
   537 	SetVisualGearValues(madness, nil, nil, 0, 0, nil, frameID, nil, visualSprite, nil, nil)
   532 	SetState(tempG, bor(GetState(tempG),gstInvisible) )
   538 	SetState(tempG, bor(GetState(tempG),gstInvisible) )
   533 	table.insert(strucAltDisplay, madness)
   539 	table.insert(strucAltDisplay, madness)
   534 
   540 
  1197 		curWep = amNothing
  1203 		curWep = amNothing
  1198 		wallsVisible = false
  1204 		wallsVisible = false
  1199 	end
  1205 	end
  1200 end
  1206 end
  1201 
  1207 
       
  1208 local cursorIcon = nil
       
  1209 local ammoIcon = nil
       
  1210 local ammoIconBorder = nil
       
  1211 
       
  1212 function HandleCursor()
       
  1213 	if curAmmo == amCMStructurePlacer or curAmmo == amCMObjectPlcer or curAmmo == amCMCratePlacer then
       
  1214 		local dFrame = 0
       
  1215 		local dSprite
       
  1216 		local yOffset = 0
       
  1217 		if (cat[cIndex] == "Structure Placement Mode") then
       
  1218 			dSprite = sprTarget
       
  1219 			dFrame = catFrames[pMode[pIndex]]
       
  1220 		elseif (cat[cIndex] == "Mine Placement Mode") then
       
  1221 			dSprite = sprCustom2 -- sprMineOff
       
  1222 		elseif (cat[cIndex] == "Sticky Mine Placement Mode") then
       
  1223 			dSprite = sprCustom3 -- sprSMineOff
       
  1224 		elseif (cat[cIndex] == "Barrel Placement Mode") then
       
  1225 			dSprite = sprExplosives
       
  1226 		elseif (cat[cIndex] == "Health Crate Placement Mode") then
       
  1227 			dSprite = sprFAid
       
  1228 		elseif (cat[cIndex] == "Weapon Crate Placement Mode") then
       
  1229 			dSprite = sprCase
       
  1230 		elseif (cat[cIndex] == "Utility Crate Placement Mode") then
       
  1231 			dSprite = sprUtility
       
  1232 		else
       
  1233 			dSprite = sprArrow
       
  1234 		end
       
  1235 
       
  1236 		if not cursorIcon then
       
  1237 			cursorIcon = AddVisualGear(CursorX, CursorY, vgtStraightShot, dSprite, false, 3)
       
  1238 		end
       
  1239 		SetVisualGearValues(cursorIcon, CursorX, CursorY, 0, 0, 0, dFrame, 1000, dSprite, 1000)
       
  1240 
       
  1241 		-- Render ammo icon for weapon and utility crate
       
  1242 		local ammoFrame
       
  1243 		if (cat[cIndex] == "Weapon Crate Placement Mode") or (cat[cIndex] == "Utility Crate Placement Mode") then
       
  1244 			local tArr
       
  1245 			if (cat[cIndex] == "Weapon Crate Placement Mode") then
       
  1246 				tArr = atkArray
       
  1247 			else
       
  1248 				tArr = utilArray
       
  1249 			end
       
  1250 
       
  1251 			-- Get ammo icon
       
  1252 			ammoFrame = tArr[pIndex][1] - 1
       
  1253 		end
       
  1254 		if ammoFrame then
       
  1255 			local xDisplacement = 42
       
  1256 			local yDisplacement = 42
       
  1257 			local x = CursorX + yDisplacement
       
  1258 			local y = CursorY + yDisplacement
       
  1259 
       
  1260 			-- Border around ammo icon
       
  1261 			if not ammoIconBorder then
       
  1262 				ammoIconBorder = AddVisualGear(x, y, vgtStraightShot, sprCustom1, false, 3)
       
  1263 			end
       
  1264 			SetVisualGearValues(ammoIconBorder, x, y, 0, 0, 0, 0, 1000, nil, 1000)
       
  1265 
       
  1266 			-- Ammo icon
       
  1267 			if not ammoIcon then
       
  1268 				ammoIcon = AddVisualGear(x, y, vgtStraightShot, sprAMAmmos, false, 3)
       
  1269 			end
       
  1270 			SetVisualGearValues(ammoIcon, x, y, 0, 0, 0, ammoFrame, 1000, nil, 1000)
       
  1271 
       
  1272 		else
       
  1273 			-- Cleanup vgears if not placing ammo crates
       
  1274 			if ammoIcon then
       
  1275 				DeleteVisualGear(ammoIcon)
       
  1276 			end
       
  1277 			if ammoIconBorder then
       
  1278 				DeleteVisualGear(ammoIconBorder)
       
  1279 			end
       
  1280 		end
       
  1281 	end
       
  1282 end
       
  1283 
       
  1284 function onVisualGearDelete(vg)
       
  1285 	if vg ~= nil then
       
  1286 		if vg == cursorIcon then
       
  1287 			cursorIcon = nil
       
  1288 		elseif vg == ammoIcon then
       
  1289 			ammoIcon = nil
       
  1290 		elseif vg == ammoIconBorder then
       
  1291 			ammoIconBorder = nil
       
  1292 		end
       
  1293 	end
       
  1294 end
  1202 
  1295 
  1203 -- called in onGameTick()
  1296 -- called in onGameTick()
  1204 function HandleConstructionMode()
  1297 function HandleConstructionMode()
  1205 
  1298 
  1206 	HandleStructures()
  1299 	HandleStructures()
  1208 	if CurrentHedgehog ~= nil then
  1301 	if CurrentHedgehog ~= nil then
  1209 
  1302 
  1210 		if wallsVisible == true then
  1303 		if wallsVisible == true then
  1211 			HandleBorderEffects()
  1304 			HandleBorderEffects()
  1212 		end
  1305 		end
       
  1306 
       
  1307 		HandleCursor()
  1213 
  1308 
  1214 		if GameTime % 100 == 0 then
  1309 		if GameTime % 100 == 0 then
  1215 
  1310 
  1216 			-- Force-update the construction mode tools every 100ms.
  1311 			-- Force-update the construction mode tools every 100ms.
  1217 			-- This makes sure the announcer messages don't disappear
  1312 			-- This makes sure the announcer messages don't disappear