Contruction Mode: Fix rubber being placable in land and invalid girder placement costing energy
authorWuzzy <almikes@aol.com>
Sun, 27 Nov 2016 05:56:45 +0100
changeset 12091 db5e12d623cc
parent 12090 fac17dd2bc2f
child 12092 9fe7eb1f7df2
Contruction Mode: Fix rubber being placable in land and invalid girder placement costing energy
ChangeLog.txt
share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
--- a/ChangeLog.txt	Sun Nov 27 05:33:26 2016 +0100
+++ b/ChangeLog.txt	Sun Nov 27 05:56:45 2016 +0100
@@ -41,6 +41,8 @@
   + energyperround: New energy per round
   + maxenergy: Maximum allowed
  + Completely reworked all in-game texts and descriptions
+ * Fix rubber being placable inside land
+ * Fix invalid girder placement costing energy
  * Special tools like structure placer now have their own proper descriptions (instead of Air Attack description, etc.)
  * Costs for weapon and utility crates were all equal
  * Many other fixes and tweaks
--- a/share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua	Sun Nov 27 05:33:26 2016 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua	Sun Nov 27 05:56:45 2016 +0100
@@ -1115,52 +1115,70 @@
 	elseif (XYisInRect(x,y, clanBoundsSX[GetHogClan(CurrentHedgehog)],clanBoundsSY[GetHogClan(CurrentHedgehog)],clanBoundsEX[GetHogClan(CurrentHedgehog)],clanBoundsEY[GetHogClan(CurrentHedgehog)]) == true)
 	and (clanPower[GetHogClan(CurrentHedgehog)] >= placedExpense)
 	then
-
-
-
+		-- For checking if the actual placement succeeded
+		local placed = false
 		if cat[cIndex] == "Girder Placement Mode" then
-			PlaceGirder(x, y, CGR)
+			placed = PlaceGirder(x, y, CGR)
 			placedSpec[placedCount] = CGR
 		elseif cat[cIndex] == "Rubber Placement Mode" then
-			PlaceSprite(x,y, sprAmRubber, CGR, nil, nil, nil, nil, lfBouncy)
+			placed = PlaceRubber(x, y, CGR)
 			placedSpec[placedCount] = CGR
 		elseif cat[cIndex] == "Health Crate Placement Mode" then
 			gear = SpawnHealthCrate(x,y)
-			SetHealth(gear, pMode[pIndex])
-			setGearValue(gear,"caseType","med")
-			clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
+			if gear ~= nil then
+				placed = true
+				SetHealth(gear, pMode[pIndex])
+				setGearValue(gear,"caseType","med")
+				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
+			end
 		elseif cat[cIndex] == "Weapon Crate Placement Mode" then
 			gear = SpawnAmmoCrate(x, y, atkArray[pIndex][1])
-			placedSpec[placedCount] = atkArray[pIndex][2]
-			setGearValue(gear,"caseType","ammo")
-			setGearValue(gear,"contents",atkArray[pIndex][2])
-			clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
+			if gear ~= nil then
+				placed = true
+				placedSpec[placedCount] = atkArray[pIndex][2]
+				setGearValue(gear,"caseType","ammo")
+				setGearValue(gear,"contents",atkArray[pIndex][2])
+				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
+			end
 		elseif cat[cIndex] == "Utility Crate Placement Mode" then
 			gear = SpawnUtilityCrate(x, y, utilArray[pIndex][1])
-			placedSpec[placedCount] = utilArray[pIndex][2]
-			setGearValue(gear,"caseType","util")
-			setGearValue(gear,"contents",utilArray[pIndex][2])
-			if utilArray[pIndex][1] == amExtraTime then
-				clanUsedExtraTime[GetHogClan(CurrentHedgehog)] = true
+			if gear ~= nil then
+				placed = true
+				placedSpec[placedCount] = utilArray[pIndex][2]
+				setGearValue(gear,"caseType","util")
+				setGearValue(gear,"contents",utilArray[pIndex][2])
+				if utilArray[pIndex][1] == amExtraTime then
+					clanUsedExtraTime[GetHogClan(CurrentHedgehog)] = true
+				end
+				clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
 			end
-			clanCratesSpawned[GetHogClan(CurrentHedgehog)] = clanCratesSpawned[GetHogClan(CurrentHedgehog)] +1
 		elseif cat[cIndex] == "Barrel Placement Mode" then
 			gear = AddGear(x, y, gtExplosives, 0, 0, 0, 0)
-			SetHealth(gear, pMode[pIndex])
+			if gear ~= nil then
+				placed = true
+				SetHealth(gear, pMode[pIndex])
+			end
 		elseif cat[cIndex] == "Mine Placement Mode" then
 			gear = AddGear(x, y, gtMine, 0, 0, 0, 0)
-			SetTimer(gear, pMode[pIndex])
+			if gear ~= nil then
+				placed = true
+				SetTimer(gear, pMode[pIndex])
+			end
 		elseif cat[cIndex] == "Sticky Mine Placement Mode" then
 			gear = AddGear(x, y, gtSMine, 0, 0, 0, 0)
-
+			placed = gear ~= nil
 		elseif cat[cIndex] == "Structure Placement Mode" then
-
 			AddStruc(x,y, pMode[pIndex],GetHogClan(CurrentHedgehog))
-
+			placed = true
 		end
 
-		clanPower[GetHogClan(CurrentHedgehog)] = clanPower[GetHogClan(CurrentHedgehog)] - placedExpense
-		placedCount = placedCount + 1
+		if placed then
+			clanPower[GetHogClan(CurrentHedgehog)] = clanPower[GetHogClan(CurrentHedgehog)] - placedExpense
+			placedCount = placedCount + 1
+		else
+			AddCaption(loc("Invalid Placement"),0xffba00ff,capgrpVolume)
+			PlaySound(sndDenied)
+		end
 
 	else
 	    if (clanPower[GetHogClan(CurrentHedgehog)] >= placedExpense) then