share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
changeset 12952 eafaada79157
parent 12951 37b81c20358b
child 12953 7ea62261c481
equal deleted inserted replaced
12951:37b81c20358b 12952:eafaada79157
    64 local strucHealth = {}
    64 local strucHealth = {}
    65 
    65 
    66 local strucCirc = {}
    66 local strucCirc = {}
    67 local strucCircCol = {}
    67 local strucCircCol = {}
    68 local strucCircRadius = {}
    68 local strucCircRadius = {}
    69 local strucCircType = {}
       
    70 local strucAltDisplay = {}
    69 local strucAltDisplay = {}
    71 
    70 
    72 -- Clan stuff
    71 -- Clan stuff
    73 local clanPower = {} -- current power for each clan. Used to build stuff
    72 local clanPower = {} -- current power for each clan. Used to build stuff
    74 local clanPowerTag = nil -- visual gear ID of displayed clan power
    73 local clanPowerTag = nil -- visual gear ID of displayed clan power
   117 -1 means “do nothing”. ]]
   116 -1 means “do nothing”. ]]
   118 local checkForSpecialWeaponsIn = -1
   117 local checkForSpecialWeaponsIn = -1
   119 local lastWep = amNothing -- helper variable to track the previous hack
   118 local lastWep = amNothing -- helper variable to track the previous hack
   120 
   119 
   121 -- Colors
   120 -- Colors
   122 local colorRed = 0xff0000ff
   121 local colorClanTag = 0x00ff00ff
   123 local colorGreen = 0x00ff00ff
   122 
       
   123 local colorSupportStation = 0xFFFF00FF
       
   124 local colorConstructionStation = 0xFFFFFFFF
       
   125 local colorTeleportationNode = 0x0000FFFF
       
   126 local colorHealingStation = 0xFF808040 -- Just a slight glow
       
   127 local colorBioFilter = 0xFF0000FF
       
   128 local colorReflectorShield = 0xFFAE00FF
       
   129 local colorWeaponFilter =  0xA800FFFF
       
   130 
       
   131 local colorHealingStationParticle = 0x00FF00FF
       
   132 
       
   133 local colorMessage = 0xFFBA00FF
   124 
   134 
   125 -- Fake ammo types, for the overwritten weapons in Construction Mode
   135 -- Fake ammo types, for the overwritten weapons in Construction Mode
   126 local amCMStructurePlacer = amAirAttack
   136 local amCMStructurePlacer = amAirAttack
   127 local amCMCratePlacer = amNapalm
   137 local amCMCratePlacer = amNapalm
   128 local amCMObjectPlacer = amDrillStrike
   138 local amCMObjectPlacer = amDrillStrike
   264 
   274 
   265 	local zoomL = 1.1
   275 	local zoomL = 1.1
   266 	local xOffset = 45
   276 	local xOffset = 45
   267 	local yOffset = 70
   277 	local yOffset = 70
   268 	local tValue = clanPower[GetHogClan(CurrentHedgehog)]
   278 	local tValue = clanPower[GetHogClan(CurrentHedgehog)]
   269 	local tCol = 0x00ff00ff
   279 	local tCol = colorClanTag
       
   280 	-- alternatively:  tCol = GetClanColor(GetHogClan(CurrentHedgehog))
   270 
   281 
   271 	DeleteVisualGear(clanPowerTag)
   282 	DeleteVisualGear(clanPowerTag)
   272 	clanPowerTag = AddVisualGear(-div(ScreenWidth, 2) + xOffset, ScreenHeight - yOffset, vgtHealthTag, tValue, false)
   283 	clanPowerTag = AddVisualGear(-div(ScreenWidth, 2) + xOffset, ScreenHeight - yOffset, vgtHealthTag, tValue, false)
   273 
   284 
   274 	SetVisualGearValues(
   285 	SetVisualGearValues(
   280 		zoomL, 		-- zoom
   291 		zoomL, 		-- zoom
   281 		1, 		-- ~= 0 means align to screen
   292 		1, 		-- ~= 0 means align to screen
   282 		nil, 		-- frameticks
   293 		nil, 		-- frameticks
   283 		nil, 		-- value (set above)
   294 		nil, 		-- value (set above)
   284 		240000, 	-- timer
   295 		240000, 	-- timer
   285 		tCol		-- color.   -- GetClanColor( GetHogClan(CurrentHedgehog) )
   296 		tCol		-- color
   286 	)
   297 	)
   287 
   298 
   288 end
   299 end
   289 
   300 
   290 function XYisInRect(px, py, psx, psy, pex, pey)
   301 function XYisInRect(px, py, psx, psy, pex, pey)
   441 	SetGearPosition(tempG, pX, pY)
   452 	SetGearPosition(tempG, pX, pY)
   442 	setGearValue(tempG, "uniqueStructureID", uniqueStructureID)
   453 	setGearValue(tempG, "uniqueStructureID", uniqueStructureID)
   443 
   454 
   444 	local tempCirc = AddVisualGear(0,0,vgtCircle,0,true)
   455 	local tempCirc = AddVisualGear(0,0,vgtCircle,0,true)
   445 
   456 
   446 	SetVisualGearValues(tempCirc, 0, 0, 100, 255, 1, 100, 0, 500, 1, 0xFFFFFF00)
   457 	if pType ~= "Respawner" and pType ~= "Generator" then
       
   458 		SetVisualGearValues(tempCirc, 0, 0, 100, 255, 1, 100, 0, 500, 1, 0xFFFFFF00)
       
   459 		table.insert(strucCirc, tempCirc)
       
   460 	else
       
   461 		table.insert(strucCirc, false)
       
   462 	end
   447 
   463 
   448 	table.insert(strucID, uniqueStructureID)
   464 	table.insert(strucID, uniqueStructureID)
   449 	table.insert(strucType, pType)
   465 	table.insert(strucType, pType)
   450 	table.insert(strucGear,tempG)
   466 	table.insert(strucGear,tempG)
   451 	table.insert(strucClan,pClan)
   467 	table.insert(strucClan,pClan)
   460 
   476 
   461 	else
   477 	else
   462 		table.insert(strucHealth,1)
   478 		table.insert(strucHealth,1)
   463 	end
   479 	end
   464 
   480 
   465 	table.insert(strucCirc,tempCirc)
       
   466 
       
   467 	table.insert(strucCircType, 1)
       
   468 	if pType == "Bio-Filter" then
   481 	if pType == "Bio-Filter" then
   469 		table.insert(strucCircCol,colorRed)
   482 		table.insert(strucCircCol, colorBioFilter)
   470 		table.insert(strucCircRadius,1000)
   483 		table.insert(strucCircRadius,1000)
   471 		frameID = 7
   484 		frameID = 7
   472 	elseif pType == "Healing Station" then
   485 	elseif pType == "Healing Station" then
   473 		table.insert(strucCircCol,0xFF00FF00)
   486 		table.insert(strucCircCol, colorHealingStation)
   474 		table.insert(strucCircRadius,500)
   487 		table.insert(strucCircRadius,500)
   475 		frameID = 3
   488 		frameID = 3
   476 	elseif pType == "Respawner" then
   489 	elseif pType == "Respawner" then
   477 		table.insert(strucCircCol,0xFF00FF00)
   490 		table.insert(strucCircCol, 0)
   478 		table.insert(strucCircRadius,75)
   491 		table.insert(strucCircRadius,0)
   479 		runOnHogs(EnableHogResurrectionForThisClan)
   492 		runOnHogs(EnableHogResurrectionForThisClan)
   480 		frameID = 1
   493 		frameID = 1
   481 	elseif pType == "Teleportation Node" then
   494 	elseif pType == "Teleportation Node" then
   482 		table.insert(strucCircCol,0x0000FFFF)
   495 		table.insert(strucCircCol, colorTeleportationNode)
   483 		table.insert(strucCircRadius,350)
   496 		table.insert(strucCircRadius,350)
   484 		frameID = 6
   497 		frameID = 6
   485 	elseif pType == "Generator" then
   498 	elseif pType == "Generator" then
   486 		table.insert(strucCircCol,0xFFFF00FF)
   499 		table.insert(strucCircCol, 0)
   487 		table.insert(strucCircRadius,75)
   500 		table.insert(strucCircRadius,0)
   488 		setGearValue(tempG, "power", 0)
   501 		setGearValue(tempG, "power", 0)
   489 		frameID = 2
   502 		frameID = 2
   490 	elseif pType == "Support Station" then
   503 	elseif pType == "Support Station" then
   491 		table.insert(strucCircCol,0xFFFF00FF)
   504 		table.insert(strucCircCol, colorSupportStation)
   492 		table.insert(strucCircRadius,500)
   505 		table.insert(strucCircRadius,500)
   493 		frameID = 4
   506 		frameID = 4
   494 	elseif pType == "Construction Station" then
   507 	elseif pType == "Construction Station" then
   495 		table.insert(strucCircCol,0xFFFFFFFF)
   508 		table.insert(strucCircCol, colorConstructionStation)
   496 		table.insert(strucCircRadius,500)
   509 		table.insert(strucCircRadius,500)
   497 		frameID = 8
   510 		frameID = 8
   498 	elseif pType == "Reflector Shield" then
   511 	elseif pType == "Reflector Shield" then
   499 		table.insert(strucCircCol,0xffae00ff)
   512 		table.insert(strucCircCol, colorReflectorShield)
   500 		table.insert(strucCircRadius,750)
   513 		table.insert(strucCircRadius,750)
   501 		frameID = 9
   514 		frameID = 9
   502 	elseif pType == "Weapon Filter" then
   515 	elseif pType == "Weapon Filter" then
   503 		table.insert(strucCircCol,0xa800ffff)
   516 		table.insert(strucCircCol, colorWeaponFilter)
   504 		table.insert(strucCircRadius,750)
   517 		table.insert(strucCircRadius,750)
   505 		frameID = 5
   518 		frameID = 5
   506 	end
   519 	end
   507 
   520 
   508 
   521 
   535 			DeleteVisualGear(strucCirc[i])
   548 			DeleteVisualGear(strucCirc[i])
   536 			table.remove(strucCirc,i)
   549 			table.remove(strucCirc,i)
   537 
   550 
   538 			table.remove(strucCircCol,i)
   551 			table.remove(strucCircCol,i)
   539 			table.remove(strucCircRadius,i)
   552 			table.remove(strucCircRadius,i)
   540 			table.remove(strucCircType,i)
       
   541 
   553 
   542 			if strucAltDisplay[i] ~= 1 then
   554 			if strucAltDisplay[i] ~= 1 then
   543 				DeleteVisualGear(strucAltDisplay[i])
   555 				DeleteVisualGear(strucAltDisplay[i])
   544 			end
   556 			end
   545 			table.remove(strucAltDisplay,i)
   557 			table.remove(strucAltDisplay,i)
   608 
   620 
   609 		if (strucType[i] == "Teleportation Node") and (strucClan[i] == GetHogClan(CurrentHedgehog)) then
   621 		if (strucType[i] == "Teleportation Node") and (strucClan[i] == GetHogClan(CurrentHedgehog)) then
   610 
   622 
   611 			local dist = GetDistFromGearToXY(CurrentHedgehog,GetX(strucGear[i]), GetY(strucGear[i]))
   623 			local dist = GetDistFromGearToXY(CurrentHedgehog,GetX(strucGear[i]), GetY(strucGear[i]))
   612 			local NR
   624 			local NR
   613 			if strucCircType[i] == 0 then
   625 			NR = (48/100*strucCircRadius[i])/2
   614 				NR = strucCircRadius[i]
       
   615 			else
       
   616 				NR = (48/100*strucCircRadius[i])/2
       
   617 			end
       
   618 			if dist <= NR*NR then
   626 			if dist <= NR*NR then
   619 				teleportOriginSuccessful = true
   627 				teleportOriginSuccessful = true
   620 			end
   628 			end
   621 
   629 
   622 			dist = GetDistFromXYtoXY(tX,tY,GetX(strucGear[i]), GetY(strucGear[i]))
   630 			dist = GetDistFromXYtoXY(tX,tY,GetX(strucGear[i]), GetY(strucGear[i]))
   623 			if strucCircType[i] == 0 then
   631 			NR = (48/100*strucCircRadius[i])/2
   624 				NR = strucCircRadius[i]
       
   625 			else
       
   626 				NR = (48/100*strucCircRadius[i])/2
       
   627 			end
       
   628 			if dist <= NR*NR then
   632 			if dist <= NR*NR then
   629 				teleportDestinationSuccessful = true
   633 				teleportDestinationSuccessful = true
   630 			end
   634 			end
   631 
   635 
   632 		end
   636 		end
   651 		return
   655 		return
   652 	end
   656 	end
   653 
   657 
   654 	-- calculate my real radius if I am an aura
   658 	-- calculate my real radius if I am an aura
   655 	local NR
   659 	local NR
   656 	if strucCircType[sID] == 0 then
   660 	NR = (48/100*strucCircRadius[sID])/2
   657 		NR = strucCircRadius[sID]
       
   658 	else
       
   659 		NR = (48/100*strucCircRadius[sID])/2
       
   660 	end
       
   661 
   661 
   662 	-- we're in business
   662 	-- we're in business
   663 	if dist <= NR*NR then
   663 	if dist <= NR*NR then
   664 
   664 
   665 		-- heal clan hogs
   665 		-- heal clan hogs
   679 						end
   679 						end
   680 					end
   680 					end
   681 
   681 
   682 					-- change this to the med kit sprite health ++++s later
   682 					-- change this to the med kit sprite health ++++s later
   683 					local tempE = AddVisualGear(GetX(strucGear[sID]), GetY(strucGear[sID]), vgtSmoke, 0, true)
   683 					local tempE = AddVisualGear(GetX(strucGear[sID]), GetY(strucGear[sID]), vgtSmoke, 0, true)
   684 					SetVisualGearValues(tempE, nil, nil, nil, nil, nil, nil, nil, nil, nil, colorGreen)
   684 					SetVisualGearValues(tempE, nil, nil, nil, nil, nil, nil, nil, nil, nil, colorHealingStationParticle)
   685 
   685 
   686 				end
   686 				end
   687 			end
   687 			end
   688 
   688 
   689 		-- explode enemy clan hogs
   689 		-- explode enemy clan hogs
   749 
   749 
   750 							AddVisualGear(GetX(gear), GetY(gear), vgtExplosion, 0, false)
   750 							AddVisualGear(GetX(gear), GetY(gear), vgtExplosion, 0, false)
   751 							PlaySound(sndExplosion)
   751 							PlaySound(sndExplosion)
   752 
   752 
   753 							strucHealth[sID] = strucHealth[sID] - gDmg
   753 							strucHealth[sID] = strucHealth[sID] - gDmg
   754 							strucCircCol[sID] = strucCircCol[sID] - gDmg
   754 							if strucCirc[sID] then
       
   755 								strucCircCol[sID] = strucCircCol[sID] - gDmg
       
   756 							end
   755 
   757 
   756 							if strucHealth[sID] <= 0 then
   758 							if strucHealth[sID] <= 0 then
   757 								AddVisualGear(GetX(strucGear[sID]), GetY(strucGear[sID]), vgtExplosion, 0, false)
   759 								AddVisualGear(GetX(strucGear[sID]), GetY(strucGear[sID]), vgtExplosion, 0, false)
   758 								DeleteGear(strucGear[sID])
   760 								DeleteGear(strucGear[sID])
   759 								PlaySound(sndExplosion)
   761 								PlaySound(sndExplosion)
   842 		end
   844 		end
   843 	end
   845 	end
   844 
   846 
   845 	for i = 1, #strucID do
   847 	for i = 1, #strucID do
   846 
   848 
   847 		SetVisualGearValues(strucCirc[i], GetX(strucGear[i]), GetY(strucGear[i]), nil, nil, nil, nil, nil, strucCircRadius[i], nil, strucCircCol[i])
   849 		if strucCirc[i] then
       
   850 			SetVisualGearValues(strucCirc[i], GetX(strucGear[i]), GetY(strucGear[i]), nil, nil, nil, nil, nil, strucCircRadius[i], nil, strucCircCol[i])
       
   851 		end
   848 
   852 
   849 		tempID_CheckProximity = i
   853 		tempID_CheckProximity = i
   850 
   854 
   851 		SetVisualGearValues(strucAltDisplay[i], GetX(strucGear[i]), GetY(strucGear[i]), 0, 0, nil, nil, 800000, sprTarget)
   855 		SetVisualGearValues(strucAltDisplay[i], GetX(strucGear[i]), GetY(strucGear[i]), 0, 0, nil, nil, 800000, sprTarget)
   852 
   856 
   948 -- essentially called when user clicks the mouse
   952 -- essentially called when user clicks the mouse
   949 -- with girders or an airattack
   953 -- with girders or an airattack
   950 function PlaceObject(x,y)
   954 function PlaceObject(x,y)
   951 
   955 
   952 	if (clanUsedExtraTime[GetHogClan(CurrentHedgehog)] == true) and (cat[cIndex] == "Utility Crate Placement Mode") and (utilArray[pIndex][1] == amExtraTime) then
   956 	if (clanUsedExtraTime[GetHogClan(CurrentHedgehog)] == true) and (cat[cIndex] == "Utility Crate Placement Mode") and (utilArray[pIndex][1] == amExtraTime) then
   953 		AddCaption(loc("You may only place 1 Extra Time crate per turn."),0xffba00ff,capgrpVolume)
   957 		AddCaption(loc("You may only place 1 Extra Time crate per turn."),colorMessage,capgrpVolume)
   954 		PlaySound(sndDenied)
   958 		PlaySound(sndDenied)
   955 	elseif (conf_cratesPerRound ~= "inf" and clanCratesSpawned[GetHogClan(CurrentHedgehog)] >= conf_cratesPerRound) and ( (cat[cIndex] == "Health Crate Placement Mode") or (cat[cIndex] == "Utility Crate Placement Mode") or (cat[cIndex] == "Weapon Crate Placement Mode")  )  then
   959 	elseif (conf_cratesPerRound ~= "inf" and clanCratesSpawned[GetHogClan(CurrentHedgehog)] >= conf_cratesPerRound) and ( (cat[cIndex] == "Health Crate Placement Mode") or (cat[cIndex] == "Utility Crate Placement Mode") or (cat[cIndex] == "Weapon Crate Placement Mode")  )  then
   956 		AddCaption(string.format(loc("You may only place %d crates per round."), conf_cratesPerRound),0xffba00ff,capgrpVolume)
   960 		AddCaption(string.format(loc("You may only place %d crates per round."), conf_cratesPerRound),colorMessage,capgrpVolume)
   957 		PlaySound(sndDenied)
   961 		PlaySound(sndDenied)
   958 	elseif (XYisInRect(x,y, clanBoundsSX[GetHogClan(CurrentHedgehog)],clanBoundsSY[GetHogClan(CurrentHedgehog)],clanBoundsEX[GetHogClan(CurrentHedgehog)],clanBoundsEY[GetHogClan(CurrentHedgehog)]) == true)
   962 	elseif (XYisInRect(x,y, clanBoundsSX[GetHogClan(CurrentHedgehog)],clanBoundsSY[GetHogClan(CurrentHedgehog)],clanBoundsEX[GetHogClan(CurrentHedgehog)],clanBoundsEY[GetHogClan(CurrentHedgehog)]) == true)
   959 	and (clanPower[GetHogClan(CurrentHedgehog)] >= placedExpense)
   963 	and (clanPower[GetHogClan(CurrentHedgehog)] >= placedExpense)
   960 	then
   964 	then
   961 		-- For checking if the actual placement succeeded
   965 		-- For checking if the actual placement succeeded
  1008 		end
  1012 		end
  1009 
  1013 
  1010 		if placed then
  1014 		if placed then
  1011 			clanPower[GetHogClan(CurrentHedgehog)] = clanPower[GetHogClan(CurrentHedgehog)] - placedExpense
  1015 			clanPower[GetHogClan(CurrentHedgehog)] = clanPower[GetHogClan(CurrentHedgehog)] - placedExpense
  1012 		else
  1016 		else
  1013 			AddCaption(loc("Invalid Placement"),0xffba00ff,capgrpVolume)
  1017 			AddCaption(loc("Invalid Placement"),colorMessage,capgrpVolume)
  1014 			PlaySound(sndDenied)
  1018 			PlaySound(sndDenied)
  1015 		end
  1019 		end
  1016 
  1020 
  1017 	else
  1021 	else
  1018 		if (clanPower[GetHogClan(CurrentHedgehog)] >= placedExpense) then
  1022 		if (clanPower[GetHogClan(CurrentHedgehog)] >= placedExpense) then
  1019 			AddCaption(loc("Invalid Placement"),0xffba00ff,capgrpVolume)
  1023 			AddCaption(loc("Invalid Placement"),colorMessage,capgrpVolume)
  1020 		else
  1024 		else
  1021 			AddCaption(loc("Insufficient Power"),0xffba00ff,capgrpVolume)
  1025 			AddCaption(loc("Insufficient Power"),colorMessage,capgrpVolume)
  1022 		end
  1026 		end
  1023 		PlaySound(sndDenied)
  1027 		PlaySound(sndDenied)
  1024 	end
  1028 	end
  1025 
  1029 
  1026 end
  1030 end
  1132 			updateCost()
  1136 			updateCost()
  1133 			updated = true
  1137 			updated = true
  1134 		end
  1138 		end
  1135 
  1139 
  1136 		if updated then
  1140 		if updated then
  1137 			AddCaption(loc(cat[cIndex]), 0xffba00ff, capgrpMessage)
  1141 			AddCaption(loc(cat[cIndex]), colorMessage, capgrpMessage)
  1138 			showModeMessage()
  1142 			showModeMessage()
  1139 			wallsVisible = true
  1143 			wallsVisible = true
  1140 		else
  1144 		else
  1141 			wallsVisible = false
  1145 			wallsVisible = false
  1142 		end
  1146 		end
  1244 		placedExpense = atkArray[pIndex][2]
  1248 		placedExpense = atkArray[pIndex][2]
  1245 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1249 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1246 		placedExpense = utilArray[pIndex][2]
  1250 		placedExpense = utilArray[pIndex][2]
  1247 	end
  1251 	end
  1248 
  1252 
  1249 	AddCaption(string.format(loc("Cost: %d"), placedExpense), 0xffba00ff, capgrpAmmostate)
  1253 	AddCaption(string.format(loc("Cost: %d"), placedExpense), colorMessage, capgrpAmmostate)
  1250 
  1254 
  1251 end
  1255 end
  1252 
  1256 
  1253 -- Should be called when the index of the mode was changed by the player.
  1257 -- Should be called when the index of the mode was changed by the player.
  1254 -- E.g. new weapon crate contents or structure type
  1258 -- E.g. new weapon crate contents or structure type
  1291 	or cat[cIndex] == "Sticky Mine Placement Mode" then
  1295 	or cat[cIndex] == "Sticky Mine Placement Mode" then
  1292 		str = GetAmmoName(val)
  1296 		str = GetAmmoName(val)
  1293 	else
  1297 	else
  1294 		str = tostring(val)
  1298 		str = tostring(val)
  1295 	end
  1299 	end
  1296 	AddCaption(str, 0xffba00ff, capgrpMessage2)
  1300 	AddCaption(str, colorMessage, capgrpMessage2)
  1297 end
  1301 end
  1298 
  1302 
  1299 function rotateMode(pDir)
  1303 function rotateMode(pDir)
  1300 	curWep = GetCurAmmoType()
  1304 	curWep = GetCurAmmoType()
  1301 	local foundMatch = false
  1305 	local foundMatch = false