share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
changeset 12951 37b81c20358b
parent 12950 a260d233cef3
child 12952 eafaada79157
equal deleted inserted replaced
12950:a260d233cef3 12951:37b81c20358b
   135 
   135 
   136 -----------------------
   136 -----------------------
   137 -- CRATE DEFINITIONS --
   137 -- CRATE DEFINITIONS --
   138 -----------------------
   138 -----------------------
   139 -- format:
   139 -- format:
   140 -- { ammoType, ammoTypeString, unused, cost }
   140 -- { ammoType, cost }
   141 
   141 
   142 local costFactor = 20
   142 local costFactor = 20
   143 
   143 
   144 -- WEAPON CRATES 
   144 -- WEAPON CRATES
   145 -- Weapons which shouldn't be aded:
   145 -- Weapons which shouldn't be aded:
   146 -- Air attack, napalm, drillstrike: Overwritten weapons for the Construction Mode tools
   146 -- Air attack, napalm, drillstrike: Overwritten weapons for the Construction Mode tools
   147 local atkArray = {
   147 local atkArray = {
   148 	{amBazooka, 		"amBazooka",		0, 2*costFactor},
   148 	{amBazooka,	 2*costFactor},
   149 	--{amBee, 		"amBee",		0, 4*costFactor},
   149 	--{amBee,	 4*costFactor},
   150 	{amMortar, 		"amMortar",		0, 1*costFactor},
   150 	{amMortar,	 1*costFactor},
   151 	{amDrill, 		"amDrill",		0, 3*costFactor},
   151 	{amDrill,	 3*costFactor},
   152 	{amSnowball, 		"amSnowball",		0, 3*costFactor},
   152 	{amSnowball,	 3*costFactor},
   153 
   153 
   154 	{amGrenade,		"amGrenade",		0, 2*costFactor},
   154 	{amGrenade,	 2*costFactor},
   155 	{amClusterBomb,		"amClusterBomb",	0, 3*costFactor},
   155 	{amClusterBomb,	 3*costFactor},
   156 	{amWatermelon, 		"amWatermelon",		0, 25*costFactor},
   156 	{amWatermelon,	25*costFactor},
   157 	{amHellishBomb,		"amHellishBomb",	0, 25*costFactor},
   157 	{amHellishBomb,	25*costFactor},
   158 	{amMolotov, 		"amMolotov",		0, 3*costFactor},
   158 	{amMolotov,	 3*costFactor},
   159 	{amGasBomb, 		"amGasBomb",		0, 3*costFactor},
   159 	{amGasBomb,	 3*costFactor},
   160 
   160 
   161 	{amShotgun,		"amShotgun",		0, 2*costFactor},
   161 	{amShotgun,	 2*costFactor},
   162 	{amDEagle,		"amDEagle",		0, 2*costFactor},
   162 	{amDEagle,	 2*costFactor},
   163 	{amSniperRifle,		"amSniperRifle",	0, 3*costFactor},
   163 	{amSniperRifle,	 3*costFactor},
   164 	--{amSineGun, 		"amSineGun",		0, 6*costFactor},
   164 	--{amSineGun,	 6*costFactor},
   165 	{amFlamethrower,	"amFlamethrower",	0, 4*costFactor},
   165 	{amFlamethrower, 4*costFactor},
   166 	{amIceGun, 		"amIceGun",		0, 15*costFactor},
   166 	{amIceGun,	15*costFactor},
   167 
   167 
   168 	{amFirePunch, 		"amFirePunch",		0, 3*costFactor},
   168 	{amFirePunch,	 3*costFactor},
   169 	{amWhip,		"amWhip",		0, 1*costFactor},
   169 	{amWhip,	 1*costFactor},
   170 	{amBaseballBat, 	"amBaseballBat",	0, 7*costFactor},
   170 	{amBaseballBat,	 7*costFactor},
   171 	--{amKamikaze, 		"amKamikaze",		0, 1*costFactor},
   171 	--{amKamikaze,	 1*costFactor},
   172 	{amSeduction, 		"amSeduction",		0, 1*costFactor},
   172 	{amSeduction,	 1*costFactor},
   173 	{amHammer,		"amHammer",		0, 1*costFactor},
   173 	{amHammer,	 1*costFactor},
   174 
   174 
   175 	{amMine, 		"amMine",		0, 1*costFactor},
   175 	{amMine,	 1*costFactor},
   176 	{amDynamite, 		"amDynamite",		0, 9*costFactor},
   176 	{amDynamite,	 9*costFactor},
   177 	{amCake, 		"amCake",		0, 25*costFactor},
   177 	{amCake,	25*costFactor},
   178 	{amBallgun, 		"amBallgun",		0, 40*costFactor},
   178 	{amBallgun,	40*costFactor},
   179 	--{amRCPlane,		"amRCPlane",		0, 25*costFactor},
   179 	--{amRCPlane,	25*costFactor},
   180 	{amSMine,		"amSMine",		0, 5*costFactor},
   180 	{amSMine,	 5*costFactor},
   181 
   181 
   182 	--{amMineStrike,	"amMineStrike",		0, 15*costFactor},
   182 	--{amMineStrike,15*costFactor},
   183 	--{amPiano,		"amPiano",		0, 40*costFactor},
   183 	--{amPiano,	40*costFactor},
   184 
   184 
   185 	{amPickHammer,		"amPickHammer",		0, 2*costFactor},
   185 	{amPickHammer,	 2*costFactor},
   186 	{amBlowTorch, 		"amBlowTorch",		0, 4*costFactor},
   186 	{amBlowTorch,	 4*costFactor},
   187 	{amKnife,		"amKnife",		0, 2*costFactor},
   187 	{amKnife,	 2*costFactor},
   188 
   188 
   189 	{amBirdy,		"amBirdy",		0, 7*costFactor},
   189 	{amBirdy,	 7*costFactor},
   190 
   190 
   191 	{amDuck,		"amDuck",		0, 2*costFactor}
   191 	{amDuck,	 2*costFactor}
   192 }
   192 }
   193 
   193 
   194 -- UTILITY CRATES --
   194 -- UTILITY CRATES --
   195 
   195 
   196 -- Utilities which shouldn't be added:
   196 -- Utilities which shouldn't be added:
   200 -- * Resurrector: We have the resurrector structure for this
   200 -- * Resurrector: We have the resurrector structure for this
   201 
   201 
   202 -- Utilities which might be weird for this mode:
   202 -- Utilities which might be weird for this mode:
   203 -- * Tardis: Randomly teleports hog, maybe even into enemy clan's area
   203 -- * Tardis: Randomly teleports hog, maybe even into enemy clan's area
   204 local utilArray = {
   204 local utilArray = {
   205 	{amLandGun,		"amLandGun",		0, 5*costFactor},
   205  	{amLandGun,	 5*costFactor},
   206 
   206 
   207 	{amRope, 		"amRope",		0, 7*costFactor},
   207 	{amRope,	 7*costFactor},
   208 	{amParachute, 		"amParachute",		0, 2*costFactor},
   208 	{amParachute,	 2*costFactor},
   209 	{amJetpack,		"amJetpack",		0, 8*costFactor},
   209 	{amJetpack,	 8*costFactor},
   210 	{amPortalGun,		"amPortalGun",		0, 15*costFactor},
   210 	{amPortalGun,	 15*costFactor},
   211 
   211 
   212 	{amInvulnerable,	"amInvulnerable",	0, 5*costFactor},
   212 	{amInvulnerable, 5*costFactor},
   213 	{amLaserSight,		"amLaserSight",		0, 2*costFactor},
   213 	{amLaserSight,	 2*costFactor},
   214 	{amVampiric,		"amVampiric",		0, 6*costFactor},
   214 	{amVampiric,	 6*costFactor},
   215 
   215 
   216 	{amLowGravity, 		"amLowGravity",		0, 4*costFactor},
   216 	{amLowGravity,	 4*costFactor},
   217 	{amExtraDamage, 	"amExtraDamage",	0, 6*costFactor},
   217 	{amExtraDamage,	 6*costFactor},
   218 	{amExtraTime,		"amExtraTime",		0, 8*costFactor}
   218 	{amExtraTime,	 8*costFactor}
   219 }
   219 }
   220 
   220 
   221 ----------------------------
   221 ----------------------------
   222 -- Placement stuff
   222 -- Placement stuff
   223 ----------------------------
   223 ----------------------------
   224 
   224 
   225 -- primary placement categories
   225 -- primary placement categories
   226 local cIndex = 1 -- category index
   226 local cIndex = 1 -- category index
   227 local cat = {
   227 local cat = {
   228 	"Girder Placement Mode",
   228 	loc_noop("Girder Placement Mode"),
   229 	"Rubber Placement Mode",
   229 	loc_noop("Rubber Placement Mode"),
   230 	"Mine Placement Mode",
   230 	loc_noop("Mine Placement Mode"),
   231 	"Sticky Mine Placement Mode",
   231 	loc_noop("Sticky Mine Placement Mode"),
   232 	"Barrel Placement Mode",
   232 	loc_noop("Barrel Placement Mode"),
   233 	"Weapon Crate Placement Mode",
   233 	loc_noop("Weapon Crate Placement Mode"),
   234 	"Utility Crate Placement Mode",
   234 	loc_noop("Utility Crate Placement Mode"),
   235 	"Health Crate Placement Mode",
   235 	loc_noop("Health Crate Placement Mode"),
   236 	"Structure Placement Mode"
   236 	loc_noop("Structure Placement Mode"),
   237 }
   237 }
       
   238 
   238 local catReverse = {}
   239 local catReverse = {}
   239 for c=1, #cat do
   240 for c=1, #cat do
   240 	catReverse[cat[c]] = c
   241 	catReverse[cat[c]] = c
   241 end
   242 end
   242 
   243 
       
   244 -- Track girders in proximity of CurrentHedgehog
   243 local sProx = {
   245 local sProx = {
   244 	{loc("Girder Placement Mode"),false},
   246 	["Girder Placement Mode"] = false,
   245 	{loc("Rubber Placement Mode"),false},
   247 	["Rubber Placement Mode"] = false,
   246 	{loc("Mine Placement Mode"),false},
   248 	["Mine Placement Mode"] = false,
   247 	{loc("Sticky Mine Placement Mode"),false},
   249 	["Sticky Mine Placement Mode"] = false,
   248 	{loc("Barrel Placement Mode"),false},
   250 	["Barrel Placement Mode"] = false,
   249 	{loc("Weapon Crate Placement Mode"),false},
   251 	["Weapon Crate Placement Mode"] = false,
   250 	{loc("Utility Crate Placement Mode"),false},
   252 	["Utility Crate Placement Mode"] = false,
   251 	{loc("Health Crate Placement Mode"),false},
   253 	["Health Crate Placement Mode"] = false,
   252 	{loc("Structure Placement Mode"),false},
   254 	["Structure Placement Mode"] = false,
   253 	{loc("Teleportation Mode"),false},
   255 	["Teleportation Mode"] = false,
   254 }
   256 }
   255 
       
   256 
   257 
   257 local pMode = {}	-- pMode contains custom subsets of the main categories
   258 local pMode = {}	-- pMode contains custom subsets of the main categories
   258 local pIndex = 1
   259 local pIndex = 1
   259 
   260 
   260 local currentGirderRotation = 1 -- current girder rotation, we actually need this as HW remembers what rotation you last used
   261 local currentGirderRotation = 1 -- current girder rotation, we actually need this as HW remembers what rotation you last used
   452 
   453 
   453 	local frameID = 0
   454 	local frameID = 0
   454 	local visualSprite = sprTarget
   455 	local visualSprite = sprTarget
   455 	local madness = AddVisualGear(GetX(tempG), GetY(tempG), vgtStraightShot, 1, true,1)
   456 	local madness = AddVisualGear(GetX(tempG), GetY(tempG), vgtStraightShot, 1, true,1)
   456 
   457 
   457 	if pType == loc("Reflector Shield") then
   458 	if pType == "Reflector Shield" then
   458 		table.insert(strucHealth,255)
   459 		table.insert(strucHealth,255)
   459 
   460 
   460 	else
   461 	else
   461 		table.insert(strucHealth,1)
   462 		table.insert(strucHealth,1)
   462 	end
   463 	end
   463 
   464 
   464 	table.insert(strucCirc,tempCirc)
   465 	table.insert(strucCirc,tempCirc)
   465 
   466 
   466 	table.insert(strucCircType, 1)
   467 	table.insert(strucCircType, 1)
   467 	if pType == loc("Bio-Filter") then
   468 	if pType == "Bio-Filter" then
   468 		table.insert(strucCircCol,colorRed)
   469 		table.insert(strucCircCol,colorRed)
   469 		table.insert(strucCircRadius,1000)
   470 		table.insert(strucCircRadius,1000)
   470 		frameID = 7
   471 		frameID = 7
   471 	elseif pType == loc("Healing Station") then
   472 	elseif pType == "Healing Station" then
   472 		table.insert(strucCircCol,0xFF00FF00)
   473 		table.insert(strucCircCol,0xFF00FF00)
   473 		table.insert(strucCircRadius,500)
   474 		table.insert(strucCircRadius,500)
   474 		frameID = 3
   475 		frameID = 3
   475 	elseif pType == loc("Respawner") then
   476 	elseif pType == "Respawner" then
   476 		table.insert(strucCircCol,0xFF00FF00)
   477 		table.insert(strucCircCol,0xFF00FF00)
   477 		table.insert(strucCircRadius,75)
   478 		table.insert(strucCircRadius,75)
   478 		runOnHogs(EnableHogResurrectionForThisClan)
   479 		runOnHogs(EnableHogResurrectionForThisClan)
   479 		frameID = 1
   480 		frameID = 1
   480 	elseif pType == loc("Teleportation Node") then
   481 	elseif pType == "Teleportation Node" then
   481 		table.insert(strucCircCol,0x0000FFFF)
   482 		table.insert(strucCircCol,0x0000FFFF)
   482 		table.insert(strucCircRadius,350)
   483 		table.insert(strucCircRadius,350)
   483 		frameID = 6
   484 		frameID = 6
   484 	elseif pType == loc("Generator") then
   485 	elseif pType == "Generator" then
   485 		table.insert(strucCircCol,0xFFFF00FF)
   486 		table.insert(strucCircCol,0xFFFF00FF)
   486 		table.insert(strucCircRadius,75)
   487 		table.insert(strucCircRadius,75)
   487 		setGearValue(tempG, "power", 0)
   488 		setGearValue(tempG, "power", 0)
   488 		frameID = 2
   489 		frameID = 2
   489 	elseif pType == loc("Support Station") then
   490 	elseif pType == "Support Station" then
   490 		table.insert(strucCircCol,0xFFFF00FF)
   491 		table.insert(strucCircCol,0xFFFF00FF)
   491 		table.insert(strucCircRadius,500)
   492 		table.insert(strucCircRadius,500)
   492 		frameID = 4
   493 		frameID = 4
   493 	elseif pType == loc("Construction Station") then
   494 	elseif pType == "Construction Station" then
   494 		table.insert(strucCircCol,0xFFFFFFFF)
   495 		table.insert(strucCircCol,0xFFFFFFFF)
   495 		table.insert(strucCircRadius,500)
   496 		table.insert(strucCircRadius,500)
   496 		frameID = 8
   497 		frameID = 8
   497 	elseif pType == loc("Reflector Shield") then
   498 	elseif pType == "Reflector Shield" then
   498 		table.insert(strucCircCol,0xffae00ff)
   499 		table.insert(strucCircCol,0xffae00ff)
   499 		table.insert(strucCircRadius,750)
   500 		table.insert(strucCircRadius,750)
   500 		frameID = 9
   501 		frameID = 9
   501 	elseif pType == loc("Weapon Filter") then
   502 	elseif pType == "Weapon Filter" then
   502 		table.insert(strucCircCol,0xa800ffff)
   503 		table.insert(strucCircCol,0xa800ffff)
   503 		table.insert(strucCircRadius,750)
   504 		table.insert(strucCircRadius,750)
   504 		frameID = 5
   505 		frameID = 5
   505 	end
   506 	end
   506 
   507 
   518 	local respawnerDestroyed = false
   519 	local respawnerDestroyed = false
   519 
   520 
   520 	for i = 1, #strucID do
   521 	for i = 1, #strucID do
   521 		if strucID[i] == getGearValue(gear,"uniqueStructureID") then
   522 		if strucID[i] == getGearValue(gear,"uniqueStructureID") then
   522 
   523 
   523 			if strucType[i] == loc("Respawner") then
   524 			if strucType[i] == "Respawner" then
   524 				respawnerDestroyed = true
   525 				respawnerDestroyed = true
   525 			end
   526 			end
   526 
   527 
   527 			table.remove(strucID,i)
   528 			table.remove(strucID,i)
   528 			table.remove(strucGear,i)
   529 			table.remove(strucGear,i)
   562 -- this is called when a respawner blows up
   563 -- this is called when a respawner blows up
   563 function RecalibrateRespawn(gear)
   564 function RecalibrateRespawn(gear)
   564 
   565 
   565 	local respawnerList = {}
   566 	local respawnerList = {}
   566 	for i = 1, #strucID do
   567 	for i = 1, #strucID do
   567 		if (strucType[i] == loc("Respawner")) and (strucClan[i] == GetHogClan(gear)) then
   568 		if (strucType[i] == "Respawner") and (strucClan[i] == GetHogClan(gear)) then
   568 			table.insert(respawnerList, i)
   569 			table.insert(respawnerList, i)
   569 		end
   570 		end
   570 	end
   571 	end
   571 
   572 
   572 	if #respawnerList >= 1 then
   573 	if #respawnerList >= 1 then
   580 --resposition dead hogs at a respawner if they own one
   581 --resposition dead hogs at a respawner if they own one
   581 function FindRespawner(gear)
   582 function FindRespawner(gear)
   582 
   583 
   583 	local respawnerList = {}
   584 	local respawnerList = {}
   584 	for i = 1, #strucID do
   585 	for i = 1, #strucID do
   585 		if (strucType[i] == loc("Respawner")) and (strucClan[i] == GetHogClan(gear)) then
   586 		if (strucType[i] == "Respawner") and (strucClan[i] == GetHogClan(gear)) then
   586 			table.insert(respawnerList, i)
   587 			table.insert(respawnerList, i)
   587 		end
   588 		end
   588 	end
   589 	end
   589 
   590 
   590 	if #respawnerList >= 1 then
   591 	if #respawnerList >= 1 then
   603 	local teleportOriginSuccessful = false
   604 	local teleportOriginSuccessful = false
   604 	local teleportDestinationSuccessful = false
   605 	local teleportDestinationSuccessful = false
   605 
   606 
   606 	for i = 1, #strucID do
   607 	for i = 1, #strucID do
   607 
   608 
   608 		if (strucType[i] == loc("Teleportation Node")) and (strucClan[i] == GetHogClan(CurrentHedgehog)) then
   609 		if (strucType[i] == "Teleportation Node") and (strucClan[i] == GetHogClan(CurrentHedgehog)) then
   609 
   610 
   610 			local dist = GetDistFromGearToXY(CurrentHedgehog,GetX(strucGear[i]), GetY(strucGear[i]))
   611 			local dist = GetDistFromGearToXY(CurrentHedgehog,GetX(strucGear[i]), GetY(strucGear[i]))
   611 			local NR
   612 			local NR
   612 			if strucCircType[i] == 0 then
   613 			if strucCircType[i] == 0 then
   613 				NR = strucCircRadius[i]
   614 				NR = strucCircRadius[i]
   660 
   661 
   661 	-- we're in business
   662 	-- we're in business
   662 	if dist <= NR*NR then
   663 	if dist <= NR*NR then
   663 
   664 
   664 		-- heal clan hogs
   665 		-- heal clan hogs
   665 		if strucType[sID] == loc("Healing Station") then
   666 		if strucType[sID] == "Healing Station" then
   666 
   667 
   667 			if GetGearType(gear) == gtHedgehog then
   668 			if GetGearType(gear) == gtHedgehog then
   668 				if GetHogClan(gear) == strucClan[sID] then
   669 				if GetHogClan(gear) == strucClan[sID] then
   669 
   670 
   670 					local hogLife = GetHealth(gear)
   671 					local hogLife = GetHealth(gear)
   684 
   685 
   685 				end
   686 				end
   686 			end
   687 			end
   687 
   688 
   688 		-- explode enemy clan hogs
   689 		-- explode enemy clan hogs
   689 		elseif strucType[sID] == loc("Bio-Filter") then
   690 		elseif strucType[sID] == "Bio-Filter" then
   690 
   691 
   691 			if GetGearType(gear) == gtHedgehog then
   692 			if GetGearType(gear) == gtHedgehog then
   692 				if (GetHogClan(gear) ~= strucClan[sID]) and (GetHealth(gear) > 0) then
   693 				if (GetHogClan(gear) ~= strucClan[sID]) and (GetHealth(gear) > 0) then
   693 					AddGear(GetX(gear), GetY(gear), gtGrenade, 0, 0, 0, 1)
   694 					AddGear(GetX(gear), GetY(gear), gtGrenade, 0, 0, 0, 1)
   694 				end
   695 				end
   695 			end
   696 			end
   696 
   697 
   697 		-- were those weapons in your pocket, or were you just happy to see me?
   698 		-- were those weapons in your pocket, or were you just happy to see me?
   698 		elseif strucType[sID] == loc("Weapon Filter") then
   699 		elseif strucType[sID] == "Weapon Filter" then
   699 
   700 
   700 			if GetGearType(gear) == gtHedgehog then
   701 			if GetGearType(gear) == gtHedgehog then
   701 				if (GetHogClan(gear) ~= strucClan[sID]) then
   702 				if (GetHogClan(gear) ~= strucClan[sID]) then
   702 
   703 
   703 					for wpnIndex = 1, #atkArray do
   704 					for wpnIndex = 1, #atkArray do
   714 
   715 
   715 				end
   716 				end
   716 			end
   717 			end
   717 
   718 
   718 		-- BOUNCE! POGO! POGO! POGO! POGO!
   719 		-- BOUNCE! POGO! POGO! POGO! POGO!
   719 		elseif strucType[sID] == loc("Reflector Shield") then
   720 		elseif strucType[sID] == "Reflector Shield" then
   720 
   721 
   721 			-- add check for whose projectile it is
   722 			-- add check for whose projectile it is
   722 			if gearCanBeDeflected(gear) == true then
   723 			if gearCanBeDeflected(gear) == true then
   723 
   724 
   724 				local gOwner = getGearValue(gear,"owner")
   725 				local gOwner = getGearValue(gear,"owner")
   767 					end
   768 					end
   768 				end
   769 				end
   769 			end
   770 			end
   770 
   771 
   771 		--mark as within range of a teleporter node
   772 		--mark as within range of a teleporter node
   772 		elseif strucType[sID] == loc("Teleportation Node") then
   773 		elseif strucType[sID] == "Teleportation Node" then
   773 
   774 
   774 			if GetGearType(gear) == gtHedgehog then
   775 			if GetGearType(gear) == gtHedgehog then
   775 				if GetHogClan(gear) == strucClan[sID] then
   776 				if GetHogClan(gear) == strucClan[sID] then
   776 
   777 
   777 					for i = 1, #sProx do
   778 					sProx["Teleportation Mode"] = true
   778 						if sProx[i][1] == loc("Teleportation Mode") then
       
   779 							sProx[i][2] = true
       
   780 						end
       
   781 					end
       
   782 
   779 
   783 				end
   780 				end
   784 			end
   781 			end
   785 
   782 
   786 		-- mark as within range of construction station
   783 		-- mark as within range of construction station
   787 		-- and thus allow menu access to placement modes
   784 		-- and thus allow menu access to placement modes
   788 		-- for girders, mines, sticky mines and barrels
   785 		-- for girders, mines, sticky mines and barrels
   789 		elseif strucType[sID] == loc("Construction Station") then
   786 		elseif strucType[sID] == "Construction Station" then
   790 
   787 
   791 			if GetGearType(gear) == gtHedgehog then
   788 			if GetGearType(gear) == gtHedgehog then
   792 				if GetHogClan(gear) == strucClan[sID] then
   789 				if GetHogClan(gear) == strucClan[sID] then
   793 					AddVisualGear(GetX(strucGear[sID]), GetY(strucGear[sID]), vgtSmoke, 0, true)
   790 					AddVisualGear(GetX(strucGear[sID]), GetY(strucGear[sID]), vgtSmoke, 0, true)
   794 
   791 
   795 					for i = 1, #sProx do
   792 					sProx["Girder Placement Mode"] = true
   796 						if ((sProx[i][1] == loc("Girder Placement Mode"))
   793 					sProx["Rubber Placement Mode"] = true
   797 						or (sProx[i][1] == loc("Rubber Placement Mode"))
   794 					sProx["Mine Placement Mode"] = true
   798 						or (sProx[i][1] == loc("Mine Placement Mode"))
   795 					sProx["Sticky Mine Placement Mode"] = true
   799 						or (sProx[i][1] == loc("Sticky Mine Placement Mode"))
   796 					sProx["Barrel Placement Mode"] = true
   800 						or (sProx[i][1] == loc("Barrel Placement Mode")))
       
   801 						then
       
   802 							sProx[i][2] = true
       
   803 						end
       
   804 					end
       
   805 
       
   806 
   797 
   807 				end
   798 				end
   808 			end
   799 			end
   809 
   800 
   810 		-- mark as within stupport station range
   801 		-- mark as within stupport station range
   811 		-- and thus allow menu access to placement modes
   802 		-- and thus allow menu access to placement modes
   812 		-- for weapon, utility, and med crates
   803 		-- for weapon, utility, and med crates
   813 		elseif strucType[sID] == loc("Support Station") then
   804 		elseif strucType[sID] == "Support Station" then
   814 
   805 
   815 			if GetGearType(gear) == gtHedgehog then
   806 			if GetGearType(gear) == gtHedgehog then
   816 				if GetHogClan(gear) == strucClan[sID] then
   807 				if GetHogClan(gear) == strucClan[sID] then
   817 					AddVisualGear(GetX(strucGear[sID]), GetY(strucGear[sID]), vgtSmoke, 0, true)
   808 					AddVisualGear(GetX(strucGear[sID]), GetY(strucGear[sID]), vgtSmoke, 0, true)
   818 
   809 
   819 					for i = 1, #sProx do
   810 					sProx["Health Crate Placement Mode"] = true
   820 						if ((sProx[i][1] == loc("Health Crate Placement Mode"))
   811 					sProx["Weapon Crate Placement Mode"] = true
   821 						or (sProx[i][1] == loc("Weapon Crate Placement Mode"))
   812 					sProx["Utility Crate Placement Mode"] = true
   822 						or (sProx[i][1] == loc("Utility Crate Placement Mode")))
       
   823 						then
       
   824 							sProx[i][2] = true
       
   825 						end
       
   826 					end
       
   827 
       
   828 
   813 
   829 				end
   814 				end
   830 			end
   815 			end
   831 		end
   816 		end
   832 
   817 
   834 
   819 
   835 end
   820 end
   836 
   821 
   837 -- used to check if we need to run through all hogs or just currenthedgehog
   822 -- used to check if we need to run through all hogs or just currenthedgehog
   838 function isAStructureThatAppliesToMultipleGears(pID)
   823 function isAStructureThatAppliesToMultipleGears(pID)
   839 	if 	strucType[pID] == loc("Healing Station") or
   824 	if 	strucType[pID] == "Healing Station" or
   840 		strucType[pID] == loc("Reflector Shield") or
   825 		strucType[pID] == "Reflector Shield" or
   841 		strucType[pID] == loc("Weapon Filter") or
   826 		strucType[pID] == "Weapon Filter" or
   842 		strucType[pID] == loc("Bio-Filter")
   827 		strucType[pID] == "Bio-Filter"
   843 	then
   828 	then
   844 		return(true)
   829 		return(true)
   845 	else
   830 	else
   846 		return(false)
   831 		return(false)
   847 	end
   832 	end
   848 end
   833 end
   849 
   834 
   850 function HandleStructures()
   835 function HandleStructures()
   851 
   836 
   852 	if GameTime % 100 == 0 then
   837 	if GameTime % 100 == 0 then
   853 		for i = 1, #sProx do
   838 		for k, _ in pairs(sProx) do
   854 			sProx[i][2] = false
   839 			if k ~= "Structure Placement Mode" then
   855 
   840 				sProx[k] = false
   856 			if sProx[i][1] == loc("Structure Placement Mode") then
   841 			end
   857 				sProx[i][2] = true
       
   858 			end
       
   859 
       
   860 		end
   842 		end
   861 	end
   843 	end
   862 
   844 
   863 	for i = 1, #strucID do
   845 	for i = 1, #strucID do
   864 
   846 
   876 				if CurrentHedgehog ~= nil then
   858 				if CurrentHedgehog ~= nil then
   877 					CheckProximity(CurrentHedgehog)
   859 					CheckProximity(CurrentHedgehog)
   878 				end
   860 				end
   879 			end
   861 			end
   880 
   862 
   881 			if strucType[i] == loc("Generator") then
   863 			if strucType[i] == "Generator" then
   882 
   864 
   883 				for z = 0, ClansCount-1 do
   865 				for z = 0, ClansCount-1 do
   884 					if z == strucClan[i] then
   866 					if z == strucClan[i] then
   885 						increaseGearValue(strucGear[i],"power")
   867 						increaseGearValue(strucGear[i],"power")
   886 						if getGearValue(strucGear[i],"power") == 10 then
   868 						if getGearValue(strucGear[i],"power") == 10 then
   897 
   879 
   898 		end
   880 		end
   899 
   881 
   900 	end
   882 	end
   901 
   883 
   902 
   884 	-- Add and remove ammo based on structure proximity
   903 
       
   904 	-- this is kinda messy and gross (even more than usual), fix it up at some point
       
   905 	-- it just assumes that if you have access to girders, it works for rubbers
       
   906 	-- as that is what the struc implemenation means due to construction station
       
   907 	if GameTime % 100 == 0 and CurrentHedgehog ~= nil then
   885 	if GameTime % 100 == 0 and CurrentHedgehog ~= nil then
   908 		local anyUIProx = false
   886 		if sProx["Girder Placement Mode"] then
   909 		for i = 1, #sProx do
   887 			AddAmmo(CurrentHedgehog, amGirder, 100)
   910 
   888 		else
   911 			if sProx[i][1] == loc("Girder Placement Mode") then
   889 			AddAmmo(CurrentHedgehog, amGirder, 0)
   912 				if sProx[i][2] == true then
   890 		end
   913 					AddAmmo(CurrentHedgehog, amGirder, 100)
   891 		if sProx["Rubber Placement Mode"] then
   914 					AddAmmo(CurrentHedgehog, amRubber, 100)
   892 			AddAmmo(CurrentHedgehog, amRubber, 100)
   915 					AddAmmo(CurrentHedgehog, amCMObjectPlacer, 100)
   893 		else
   916 				else
   894 			AddAmmo(CurrentHedgehog, amRubber, 0)
   917 					AddAmmo(CurrentHedgehog, amGirder, 0)
   895 		end
   918 					AddAmmo(CurrentHedgehog, amRubber, 0)
   896 		if sProx["Mine Placement Mode"] or sProx["Sticky Mine Placement Mode"] or sProx["Barrel Placement Mode"] then
   919 					AddAmmo(CurrentHedgehog, amCMObjectPlacer, 0) -- new
   897 			AddAmmo(CurrentHedgehog, amCMObjectPlacer, 100)
   920 				end
   898 		else
   921 			elseif sProx[i][1] == loc("Teleportation Mode") then
   899 			AddAmmo(CurrentHedgehog, amCMObjectPlacer, 0)
   922 				if sProx[i][2] == true then
   900 		end
   923 					AddAmmo(CurrentHedgehog, amTeleport, 100)
   901 		if sProx["Teleportation Mode"] then
   924 				else
   902 			AddAmmo(CurrentHedgehog, amTeleport, 100)
   925 					AddAmmo(CurrentHedgehog, amTeleport, 0)
   903 		else
   926 				end
   904 			AddAmmo(CurrentHedgehog, amTeleport, 0)
   927 			elseif sProx[i][1] == loc("Weapon Crate Placement Mode") then
   905 		end
   928 				-- this is new stuff
   906 		if sProx["Weapon Crate Placement Mode"] or sProx["Utility Crate Placement Mode"] or sProx["Health Crate Placement Mode"] then
   929 				if sProx[i][2] == true then
   907 			AddAmmo(CurrentHedgehog, amCMCratePlacer, 100)
   930 					AddAmmo(CurrentHedgehog, amCMCratePlacer, 100)
   908 		else
   931 				else
   909 			AddAmmo(CurrentHedgehog, amCMCratePlacer, 0)
   932 					AddAmmo(CurrentHedgehog, amCMCratePlacer, 0)
       
   933 				end
       
   934 			end
       
   935 
       
   936 			if (sProx[i][2] == true) then
       
   937 				anyUIProx = true
       
   938 			end
       
   939 
       
   940 		end
   910 		end
   941 	end
   911 	end
   942 
   912 
   943 end
   913 end
   944 
   914 
   998 		elseif cat[cIndex] == "Health Crate Placement Mode" then
   968 		elseif cat[cIndex] == "Health Crate Placement Mode" then
   999 			gear = SpawnHealthCrate(x,y)
   969 			gear = SpawnHealthCrate(x,y)
  1000 			if gear ~= nil then
   970 			if gear ~= nil then
  1001 				placed = true
   971 				placed = true
  1002 				SetHealth(gear, pMode[pIndex])
   972 				SetHealth(gear, pMode[pIndex])
  1003 				setGearValue(gear,"caseType","med")
       
  1004 				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
   973 				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
  1005 			end
   974 			end
  1006 		elseif cat[cIndex] == "Weapon Crate Placement Mode" then
   975 		elseif cat[cIndex] == "Weapon Crate Placement Mode" then
  1007 			gear = SpawnAmmoCrate(x, y, atkArray[pIndex][1])
   976 			gear = SpawnAmmoCrate(x, y, atkArray[pIndex][1])
  1008 			if gear ~= nil then
   977 			if gear ~= nil then
  1009 				placed = true
   978 				placed = true
  1010 				setGearValue(gear,"caseType","ammo")
       
  1011 				setGearValue(gear,"contents",atkArray[pIndex][2])
       
  1012 				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
   979 				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
  1013 			end
   980 			end
  1014 		elseif cat[cIndex] == "Utility Crate Placement Mode" then
   981 		elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1015 			gear = SpawnUtilityCrate(x, y, utilArray[pIndex][1])
   982 			gear = SpawnUtilityCrate(x, y, utilArray[pIndex][1])
  1016 			if gear ~= nil then
   983 			if gear ~= nil then
  1017 				placed = true
   984 				placed = true
  1018 				setGearValue(gear,"caseType","util")
       
  1019 				setGearValue(gear,"contents",utilArray[pIndex][2])
       
  1020 				if utilArray[pIndex][1] == amExtraTime then
   985 				if utilArray[pIndex][1] == amExtraTime then
  1021 					clanUsedExtraTime[GetHogClan(CurrentHedgehog)] = true
   986 					clanUsedExtraTime[GetHogClan(CurrentHedgehog)] = true
  1022 				end
   987 				end
  1023 				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
   988 				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
  1024 			end
   989 			end
  1075 
  1040 
  1076 	local team = GetHogTeamName(CurrentHedgehog)
  1041 	local team = GetHogTeamName(CurrentHedgehog)
  1077 
  1042 
  1078 	if cat[cIndex] == "Girder Placement Mode" then
  1043 	if cat[cIndex] == "Girder Placement Mode" then
  1079 		pIndex = currentGirderRotation
  1044 		pIndex = currentGirderRotation
  1080 		pMode = {loc("Girder")}
  1045 		pMode = {amGirder}
  1081 	elseif cat[cIndex] == "Rubber Placement Mode" then
  1046 	elseif cat[cIndex] == "Rubber Placement Mode" then
  1082 		pIndex = currentGirderRotation
  1047 		pIndex = currentGirderRotation
  1083 		pMode = {loc("Rubber")}
  1048 		pMode = {amRubber}
  1084 		placedExpense = 3
  1049 		placedExpense = 3
  1085 	elseif cat[cIndex] == "Barrel Placement Mode" then
  1050 	elseif cat[cIndex] == "Barrel Placement Mode" then
  1086 		pMode = {60}
  1051 		pMode = {60}
  1087 		placedExpense = 10
  1052 		placedExpense = 10
  1088 		teamLObjectMode[team] = cat[cIndex]
  1053 		teamLObjectMode[team] = cat[cIndex]
  1090 		pMode = {HealthCaseAmount}
  1055 		pMode = {HealthCaseAmount}
  1091 		placedExpense = 5
  1056 		placedExpense = 5
  1092 		teamLCrateMode[team] = cat[cIndex]
  1057 		teamLCrateMode[team] = cat[cIndex]
  1093 	elseif cat[cIndex] == "Weapon Crate Placement Mode" then
  1058 	elseif cat[cIndex] == "Weapon Crate Placement Mode" then
  1094 		for i = 1, #atkArray do
  1059 		for i = 1, #atkArray do
  1095 			pMode[i] = GetAmmoName(atkArray[i][1])
  1060 			pMode[i] = atkArray[i][1]
  1096 		end
  1061 		end
  1097 		placedExpense = atkArray[pIndex][4]
  1062 		placedExpense = atkArray[pIndex][2]
  1098 		teamLCrateMode[team] = cat[cIndex]
  1063 		teamLCrateMode[team] = cat[cIndex]
  1099 		pIndex = teamLWeapIndex[team]
  1064 		pIndex = teamLWeapIndex[team]
  1100 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1065 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1101 		for i = 1, #utilArray do
  1066 		for i = 1, #utilArray do
  1102 			pMode[i] = GetAmmoName(utilArray[i][1])
  1067 			pMode[i] = utilArray[i][1]
  1103 		end
  1068 		end
  1104 		placedExpense = utilArray[pIndex][4]
  1069 		placedExpense = utilArray[pIndex][2]
  1105 		teamLCrateMode[team] = cat[cIndex]
  1070 		teamLCrateMode[team] = cat[cIndex]
  1106 		pIndex = teamLUtilIndex[team]
  1071 		pIndex = teamLUtilIndex[team]
  1107 	elseif cat[cIndex] == "Mine Placement Mode" then
  1072 	elseif cat[cIndex] == "Mine Placement Mode" then
  1108 		pMode = {0,1000,2000,3000,4000,5000}
  1073 		pMode = {0,1000,2000,3000,4000,5000}
  1109 		placedExpense = 15
  1074 		placedExpense = 15
  1110 		teamLObjectMode[team] = cat[cIndex]
  1075 		teamLObjectMode[team] = cat[cIndex]
  1111 		pIndex = teamLMineIndex[team]
  1076 		pIndex = teamLMineIndex[team]
  1112 	elseif cat[cIndex] == "Sticky Mine Placement Mode" then
  1077 	elseif cat[cIndex] == "Sticky Mine Placement Mode" then
  1113 		pMode = {loc("Sticky Mine")}
  1078 		pMode = {amSMine}
  1114 		placedExpense = 20
  1079 		placedExpense = 20
  1115 		teamLObjectMode[team] = cat[cIndex]
  1080 		teamLObjectMode[team] = cat[cIndex]
  1116 	elseif cat[cIndex] == "Structure Placement Mode" then
  1081 	elseif cat[cIndex] == "Structure Placement Mode" then
  1117 		pMode = {
  1082 		pMode = {
  1118 			loc("Support Station"),
  1083 			loc_noop("Support Station"),
  1119 			loc("Construction Station"),
  1084 			loc_noop("Construction Station"),
  1120 			loc("Healing Station"),
  1085 			loc_noop("Healing Station"),
  1121 			loc("Teleportation Node"),
  1086 			loc_noop("Teleportation Node"),
  1122 			loc("Weapon Filter"),
  1087 			loc_noop("Weapon Filter"),
  1123 
  1088 
  1124 			loc("Bio-Filter"),
  1089 			loc_noop("Bio-Filter"),
  1125 			loc("Reflector Shield"),
  1090 			loc_noop("Reflector Shield"),
  1126 			loc("Respawner"),
  1091 			loc_noop("Respawner"),
  1127 			loc("Generator"),
  1092 			loc_noop("Generator"),
  1128 		}
  1093 		}
  1129 		pIndex = teamLStructIndex[team]
  1094 		pIndex = teamLStructIndex[team]
  1130 	end
  1095 	end
  1131 
  1096 
  1132 	return true
  1097 	return true
  1255 
  1220 
  1256 function updateCost()
  1221 function updateCost()
  1257 
  1222 
  1258 	if CurrentHedgehog == nil or band(GetState(CurrentHedgehog), gstHHDriven) == 0 then return end
  1223 	if CurrentHedgehog == nil or band(GetState(CurrentHedgehog), gstHHDriven) == 0 then return end
  1259 
  1224 
  1260 	if pMode[pIndex] == loc("Healing Station") then
  1225 	if pMode[pIndex] == "Healing Station" then
  1261 		placedExpense = 50
  1226 		placedExpense = 50
  1262 	elseif pMode[pIndex] == loc("Weapon Filter") then
  1227 	elseif pMode[pIndex] == "Weapon Filter" then
  1263 		placedExpense = 50
  1228 		placedExpense = 50
  1264 	elseif pMode[pIndex] == loc("Bio-Filter") then
  1229 	elseif pMode[pIndex] == "Bio-Filter" then
  1265 		placedExpense = 100
  1230 		placedExpense = 100
  1266 	elseif pMode[pIndex] == loc("Respawner") then
  1231 	elseif pMode[pIndex] == "Respawner" then
  1267 		placedExpense = 300
  1232 		placedExpense = 300
  1268 	elseif pMode[pIndex] == loc("Teleportation Node") then
  1233 	elseif pMode[pIndex] == "Teleportation Node" then
  1269 		placedExpense = 30
  1234 		placedExpense = 30
  1270 	elseif pMode[pIndex] == loc("Support Station") then
  1235 	elseif pMode[pIndex] == "Support Station" then
  1271 		placedExpense = 50
  1236 		placedExpense = 50
  1272 	elseif pMode[pIndex] == loc("Construction Station") then
  1237 	elseif pMode[pIndex] == "Construction Station" then
  1273 		placedExpense = 50
  1238 		placedExpense = 50
  1274 	elseif pMode[pIndex] == loc("Generator") then
  1239 	elseif pMode[pIndex] == "Generator" then
  1275 			placedExpense = 300
  1240 		placedExpense = 300
  1276 	elseif pMode[pIndex] == loc("Reflector Shield") then
  1241 	elseif pMode[pIndex] == "Reflector Shield" then
  1277 			placedExpense = 200
  1242 		placedExpense = 200
  1278 	elseif cat[cIndex] == "Weapon Crate Placement Mode" then
  1243 	elseif cat[cIndex] == "Weapon Crate Placement Mode" then
  1279 		placedExpense = atkArray[pIndex][4]
  1244 		placedExpense = atkArray[pIndex][2]
  1280 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1245 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1281 		placedExpense = utilArray[pIndex][4]
  1246 		placedExpense = utilArray[pIndex][2]
  1282 	end
  1247 	end
  1283 
  1248 
  1284 	AddCaption(loc("Cost") .. ": " .. placedExpense,0xffba00ff,capgrpAmmostate)
  1249 	AddCaption(string.format(loc("Cost: %d"), placedExpense), 0xffba00ff, capgrpAmmostate)
  1285 
  1250 
  1286 end
  1251 end
  1287 
  1252 
  1288 -- Should be called when the index of the mode was changed by the player.
  1253 -- Should be called when the index of the mode was changed by the player.
  1289 -- E.g. new weapon crate contents or structure type
  1254 -- E.g. new weapon crate contents or structure type
  1313 	local val = pMode[pIndex]
  1278 	local val = pMode[pIndex]
  1314 	local str
  1279 	local str
  1315 	if cat[cIndex] == "Mine Placement Mode" then
  1280 	if cat[cIndex] == "Mine Placement Mode" then
  1316 		-- timer in seconds
  1281 		-- timer in seconds
  1317 		str = string.format(loc("%d sec"), div(val, 1000))
  1282 		str = string.format(loc("%d sec"), div(val, 1000))
       
  1283 	elseif cat[cIndex] == "Structure Placement Mode" then
       
  1284 		str = loc(val)
  1318 	elseif cat[cIndex] == "Girder Placement Mode" then
  1285 	elseif cat[cIndex] == "Girder Placement Mode" then
  1319 		str = loc("Girder")
  1286 		str = GetAmmoName(amGirder)
  1320 	elseif cat[cIndex] == "Rubber Placement Mode" then
  1287 	elseif cat[cIndex] == "Rubber Placement Mode" then
  1321 		str = loc("Rubber")
  1288 		str = GetAmmoName(amRubber)
       
  1289 	elseif cat[cIndex] == "Weapon Crate Placement Mode"
       
  1290 	or cat[cIndex] == "Utility Crate Placement Mode"
       
  1291 	or cat[cIndex] == "Sticky Mine Placement Mode" then
       
  1292 		str = GetAmmoName(val)
  1322 	else
  1293 	else
  1323 		str = tostring(val)
  1294 		str = tostring(val)
  1324 	end
  1295 	end
  1325 	AddCaption(str,0xffba00ff,capgrpMessage2)
  1296 	AddCaption(str, 0xffba00ff, capgrpMessage2)
  1326 end
  1297 end
  1327 
  1298 
  1328 function rotateMode(pDir)
  1299 function rotateMode(pDir)
  1329 	curWep = GetCurAmmoType()
  1300 	curWep = GetCurAmmoType()
  1330 	local foundMatch = false
  1301 	local foundMatch = false
  1336 		elseif cIndex > #cat then
  1307 		elseif cIndex > #cat then
  1337 			cIndex = 3       -- we no longer hit girder by normal means
  1308 			cIndex = 3       -- we no longer hit girder by normal means
  1338 		end
  1309 		end
  1339 
  1310 
  1340 		if (GetCurAmmoType() == amCMCratePlacer) then
  1311 		if (GetCurAmmoType() == amCMCratePlacer) then
  1341 			if (sProx[cIndex][1] == loc("Health Crate Placement Mode")) or
  1312 			if (cat[cIndex] == "Health Crate Placement Mode") or
  1342 				(sProx[cIndex][1] == loc("Weapon Crate Placement Mode")) or
  1313 				(cat[cIndex] == "Weapon Crate Placement Mode") or
  1343 				(sProx[cIndex][1] == loc("Utility Crate Placement Mode")) then
  1314 				(cat[cIndex] == "Utility Crate Placement Mode") then
  1344 					foundMatch = true
  1315 					foundMatch = true
  1345 			end
  1316 			end
  1346 		elseif (GetCurAmmoType() == amCMObjectPlacer) then
  1317 		elseif (GetCurAmmoType() == amCMObjectPlacer) then
  1347 			if (sProx[cIndex][1] == loc("Mine Placement Mode")) or
  1318 			if (cat[cIndex] == "Mine Placement Mode") or
  1348 				(sProx[cIndex][1] == loc("Sticky Mine Placement Mode")) or
  1319 				(cat[cIndex] == "Sticky Mine Placement Mode") or
  1349 				(sProx[cIndex][1] == loc("Barrel Placement Mode")) then
  1320 				(cat[cIndex] == "Barrel Placement Mode") then
  1350 				foundMatch = true
  1321 				foundMatch = true
  1351 			end
  1322 			end
  1352 		elseif (GetCurAmmoType() == amCMStructurePlacer) then
  1323 		elseif (GetCurAmmoType() == amCMStructurePlacer) then
  1353 			if sProx[cIndex][1] == loc("Structure Placement Mode") then
  1324 			if cat[cIndex] == "Structure Placement Mode" then
  1354 				foundMatch = true
  1325 				foundMatch = true
  1355 			end
  1326 			end
  1356 		end
  1327 		end
  1357 	end
  1328 	end
  1358 
  1329