share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
changeset 12972 d82e4e583805
parent 12969 2fee2ee717eb
child 12973 9e4fc0b8ed1c
equal deleted inserted replaced
12971:f306a0c2899c 12972:d82e4e583805
   106 local fortMode = false -- is using a fort map?
   106 local fortMode = false -- is using a fort map?
   107 local tempID_CheckProximity = nil -- temporary structure variable for CheckProximity
   107 local tempID_CheckProximity = nil -- temporary structure variable for CheckProximity
   108 local cGear = nil -- detects placement of girders and objects (using airattack)
   108 local cGear = nil -- detects placement of girders and objects (using airattack)
   109 local uniqueStructureID = 0 -- Counter and ID for structures. Is incremented each time a structure spawns
   109 local uniqueStructureID = 0 -- Counter and ID for structures. Is incremented each time a structure spawns
   110 
   110 
   111 --[[ Hacky workaround for object placer: Since this thing is
       
   112 based on the drill strike, it allows the 5 timer keys to be
       
   113 pressed, causing the announcer to show up.
       
   114 This variable counts the number of ticks to count down until
       
   115 to overwrite this anouncer message.
       
   116 -1 means “do nothing”. ]]
       
   117 local checkForSpecialWeaponsIn = -1
       
   118 local lastWep = amNothing -- helper variable to track the previous hack
       
   119 
       
   120 -- Colors
   111 -- Colors
   121 local colorClanTag = 0x00ff00ff
   112 local colorClanTag = 0x00ff00ff
   122 
   113 
   123 local colorSupportStation = 0xFFFF00FF
   114 local colorSupportStation = 0xFFFF00FF
   124 local colorConstructionStation = 0xFFFFFFFF
   115 local colorConstructionStation = 0xFFFFFFFF
   133 
   124 
   134 local colorMessageError = 0xFFFFFFFF
   125 local colorMessageError = 0xFFFFFFFF
   135 
   126 
   136 -- Fake ammo types, for the overwritten weapons in Construction Mode
   127 -- Fake ammo types, for the overwritten weapons in Construction Mode
   137 local amCMStructurePlacer = amAirAttack
   128 local amCMStructurePlacer = amAirAttack
   138 local amCMCratePlacer = amNapalm
   129 local amCMCratePlacer = amMineStrike
   139 local amCMObjectPlacer = amDrillStrike
   130 local amCMObjectPlacer = amNapalm
   140 
   131 
   141 -- Config variables (script parameter)
   132 -- Config variables (script parameter)
   142 local conf_initialEnergy = 550
   133 local conf_initialEnergy = 550
   143 local conf_energyPerRound = 50
   134 local conf_energyPerRound = 50
   144 local conf_maxEnergy = 1000
   135 local conf_maxEnergy = 1000
   192 	{amCake,	25*costFactor},
   183 	{amCake,	25*costFactor},
   193 	{amBallgun,	40*costFactor},
   184 	{amBallgun,	40*costFactor},
   194 	--{amRCPlane,	25*costFactor},
   185 	--{amRCPlane,	25*costFactor},
   195 	{amSMine,	 5*costFactor},
   186 	{amSMine,	 5*costFactor},
   196 
   187 
   197 	--{amMineStrike,15*costFactor},
       
   198 	--{amPiano,	40*costFactor},
   188 	--{amPiano,	40*costFactor},
   199 
   189 
   200 	{amPickHammer,	 2*costFactor},
   190 	{amPickHammer,	 2*costFactor},
   201 	{amBlowTorch,	 4*costFactor},
   191 	{amBlowTorch,	 4*costFactor},
   202 	{amKnife,	 2*costFactor},
   192 	{amKnife,	 2*costFactor},
   981 		end
   971 		end
   982 	end
   972 	end
   983 
   973 
   984 end
   974 end
   985 
   975 
   986 function checkForSpecialWeapons()
       
   987 
       
   988 	if (GetCurAmmoType() == amCMObjectPlacer) then
       
   989 		AddCaption(loc("Object Placer"),GetClanColor(GetHogClan(CurrentHedgehog)),capgrpAmmoinfo)
       
   990 	end
       
   991 
       
   992 	lastWep = GetCurAmmoType()
       
   993 
       
   994 end
       
   995 
       
   996 ------------------------
   976 ------------------------
   997 -- SOME GENERAL METHODS
   977 -- SOME GENERAL METHODS
   998 ------------------------
   978 ------------------------
   999 
   979 
  1000 function GetDistFromGearToXY(gear, g2X, g2Y)
   980 function GetDistFromGearToXY(gear, g2X, g2Y)
  1229 
  1209 
  1230 		if wallsVisible == true then
  1210 		if wallsVisible == true then
  1231 			HandleBorderEffects()
  1211 			HandleBorderEffects()
  1232 		end
  1212 		end
  1233 
  1213 
  1234 		if (TurnTimeLeft ~= TurnTime) then
       
  1235 			if (lastWep ~= GetCurAmmoType()) then
       
  1236 				checkForSpecialWeapons()
       
  1237 			elseif checkForSpecialWeaponsIn == 0 then
       
  1238 				checkForSpecialWeapons()
       
  1239 				checkForSpecialWeaponsIn = -1
       
  1240 			else
       
  1241 				checkForSpecialWeaponsIn = checkForSpecialWeaponsIn - 1
       
  1242 			end
       
  1243 		end
       
  1244 
       
  1245 		if GameTime % 100 == 0 then
  1214 		if GameTime % 100 == 0 then
  1246 
  1215 
  1247 			-- Force-update the construction mode tools every 100ms.
  1216 			-- Force-update the construction mode tools every 100ms.
  1248 			-- This makes sure the announcer messages don't disappear
  1217 			-- This makes sure the announcer messages don't disappear
  1249 			-- while the tool is selected.
  1218 			-- while the tool is selected.
  1439 				updateIndex()
  1408 				updateIndex()
  1440 			end
  1409 			end
  1441 		end
  1410 		end
  1442 	end
  1411 	end
  1443 
  1412 
  1444 	checkForSpecialWeaponsIn = 1
       
  1445 
       
  1446 end
  1413 end
  1447 
  1414 
  1448 -- [Switch]: Set mine time to 0 (only in mine placement mode)
  1415 -- [Switch]: Set mine time to 0 (only in mine placement mode)
  1449 function onSwitch()
  1416 function onSwitch()
  1450 	curWep = GetCurAmmoType()
  1417 	curWep = GetCurAmmoType()
  1567 	AddAmmo(gear, amCMCratePlacer, 0)
  1534 	AddAmmo(gear, amCMCratePlacer, 0)
  1568 	AddAmmo(gear, amGirder, 0)
  1535 	AddAmmo(gear, amGirder, 0)
  1569 	AddAmmo(gear, amRubber, 0)
  1536 	AddAmmo(gear, amRubber, 0)
  1570 	AddAmmo(gear, amTeleport, 0)
  1537 	AddAmmo(gear, amTeleport, 0)
  1571 
  1538 
  1572 	-- Mine strike is broken, so we force-remove it
  1539 	-- Drill strike is broken, so we force-remove it
  1573 	AddAmmo(gear, amMineStrike, 0)
  1540 	AddAmmo(gear, amDrillStrike, 0)
  1574 
  1541 
  1575 	-- Everything else is set by the weapon scheme.
  1542 	-- Everything else is set by the weapon scheme.
  1576 	-- Infinite switch is recommended.
  1543 	-- Infinite switch is recommended.
  1577 end
  1544 end
  1578 
  1545 
  1584 				loc("CONSTRUCTION MODE"),
  1551 				loc("CONSTRUCTION MODE"),
  1585 				loc("a Hedgewars mini-game"),
  1552 				loc("a Hedgewars mini-game"),
  1586 				loc("Build a fortress and destroy your enemy.") .. "|" ..
  1553 				loc("Build a fortress and destroy your enemy.") .. "|" ..
  1587 				loc("There are a variety of structures available to aid you.") .. "|" ..
  1554 				loc("There are a variety of structures available to aid you.") .. "|" ..
  1588 				loc("Use the structure placer to place structures.")
  1555 				loc("Use the structure placer to place structures.")
  1589 				, 4, 5000
  1556 				, -amCMStructurePlacer, 5000
  1590 				)
  1557 				)
  1591 
  1558 
  1592 	SetAmmoTexts(amCMStructurePlacer, loc("Structure Placer"), loc("Construction Mode tool"), loc("Build one of multiple different structures|to aid you in victory, at the cost of energy.") .. "| |" ..
  1559 	SetAmmoTexts(amCMStructurePlacer, loc("Structure Placer"), loc("Construction Mode tool"), loc("Build one of multiple different structures|to aid you in victory, at the cost of energy.") .. "| |" ..
  1593 	loc("Support Station: Allows placement of crates.") .. "|"..
  1560 	loc("Support Station: Allows placement of crates.") .. "|"..
  1594 	loc("Construction Station: Allows placement of|    girders, rubber, mines, sticky mines|    and barrels.")  .. "|" ..
  1561 	loc("Construction Station: Allows placement of|    girders, rubber, mines, sticky mines|    and barrels.")  .. "|" ..
  1730 function onGearAdd(gear)
  1697 function onGearAdd(gear)
  1731 
  1698 
  1732 	local gt = GetGearType(gear)
  1699 	local gt = GetGearType(gear)
  1733 	if (gt == gtAirAttack) or (gt == gtTeleport) or (gt == gtGirder) then
  1700 	if (gt == gtAirAttack) or (gt == gtTeleport) or (gt == gtGirder) then
  1734 		cGear = gear
  1701 		cGear = gear
  1735 	elseif (gt == gtMine) or (gt == gtExplosives) or (gt == gtSMine) then
       
  1736 		curWep = GetCurAmmoType()
       
  1737 		if curWep == amCMObjectPlacer then
       
  1738 			checkForSpecialWeaponsIn = 1
       
  1739 		end
       
  1740 	end
  1702 	end
  1741 
  1703 
  1742 	if isATrackedGear(gear) then
  1704 	if isATrackedGear(gear) then
  1743 		trackGear(gear)
  1705 		trackGear(gear)
  1744 	elseif gearCanBeDeflected(gear) then
  1706 	elseif gearCanBeDeflected(gear) then