share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
changeset 12944 712ae7ff8c3d
parent 12943 3feab46234dd
child 12945 0e698562d76d
equal deleted inserted replaced
12943:3feab46234dd 12944:712ae7ff8c3d
   175 clanBoundsEX = {}
   175 clanBoundsEX = {}
   176 clanBoundsEY = {}
   176 clanBoundsEY = {}
   177 
   177 
   178 clanPower = {}
   178 clanPower = {}
   179 clanID = {}
   179 clanID = {}
   180 clanLStrucIndex = {}
   180 
   181 
   181 -- for ease of use let's track previous selection
   182 clanLWepIndex = {} -- for ease of use let's track this stuff
   182 teamLStructIndex = {}
   183 clanLUtilIndex = {}
   183 teamLObjectMode = {}
   184 clanLGearIndex = {}
   184 teamLCrateMode = {}
       
   185 teamLMineIndex = {}
       
   186 teamLWeapIndex = {}
       
   187 teamLUtilIndex = {}
       
   188 
   185 clanUsedExtraTime = {}
   189 clanUsedExtraTime = {}
   186 clanCratesSpawned = {}
   190 clanCratesSpawned = {}
   187 clanFirstTurn = {}
   191 clanFirstTurn = {}
   188 
   192 
   189 effectTimer = 0
   193 effectTimer = 0
  1202 
  1206 
  1203 	pIndex = 1
  1207 	pIndex = 1
  1204 	pMode = {}
  1208 	pMode = {}
  1205 	placedExpense = 1
  1209 	placedExpense = 1
  1206 
  1210 
       
  1211 	if not CurrentHedgehog then
       
  1212 		return false
       
  1213 	end
       
  1214 
       
  1215 	local team = GetHogTeamName(CurrentHedgehog)
       
  1216 
  1207 	if cat[cIndex] == "Girder Placement Mode" then
  1217 	if cat[cIndex] == "Girder Placement Mode" then
  1208 		pIndex = CGR
  1218 		pIndex = CGR
  1209 		pMode = {loc("Girder")}
  1219 		pMode = {loc("Girder")}
  1210 	elseif cat[cIndex] == "Rubber Placement Mode" then
  1220 	elseif cat[cIndex] == "Rubber Placement Mode" then
  1211 		pIndex = CGR
  1221 		pIndex = CGR
  1212 		pMode = {loc("Rubber")}
  1222 		pMode = {loc("Rubber")}
  1213 		placedExpense = 3
  1223 		placedExpense = 3
  1214 	elseif cat[cIndex] == "Barrel Placement Mode" then
  1224 	elseif cat[cIndex] == "Barrel Placement Mode" then
  1215 		pMode = {60}
  1225 		pMode = {60}
  1216 		placedExpense = 10
  1226 		placedExpense = 10
       
  1227 		teamLObjectMode[team] = cat[cIndex]
  1217 	elseif cat[cIndex] == "Health Crate Placement Mode" then
  1228 	elseif cat[cIndex] == "Health Crate Placement Mode" then
  1218 		pMode = {HealthCaseAmount}
  1229 		pMode = {HealthCaseAmount}
  1219 		placedExpense = 5
  1230 		placedExpense = 5
       
  1231 		teamLCrateMode[team] = cat[cIndex]
  1220 	elseif cat[cIndex] == "Weapon Crate Placement Mode" then
  1232 	elseif cat[cIndex] == "Weapon Crate Placement Mode" then
  1221 		for i = 1, #atkArray do
  1233 		for i = 1, #atkArray do
  1222 			pMode[i] = GetAmmoName(atkArray[i][1])
  1234 			pMode[i] = GetAmmoName(atkArray[i][1])
  1223 		end
  1235 		end
  1224 		placedExpense = atkArray[pIndex][4]
  1236 		placedExpense = atkArray[pIndex][4]
       
  1237 		teamLCrateMode[team] = cat[cIndex]
       
  1238 		pIndex = teamLWeapIndex[team]
  1225 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1239 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1226 		for i = 1, #utilArray do
  1240 		for i = 1, #utilArray do
  1227 			pMode[i] = GetAmmoName(utilArray[i][1])
  1241 			pMode[i] = GetAmmoName(utilArray[i][1])
  1228 		end
  1242 		end
  1229 		placedExpense = utilArray[pIndex][4]
  1243 		placedExpense = utilArray[pIndex][4]
       
  1244 		teamLCrateMode[team] = cat[cIndex]
       
  1245 		pIndex = teamLUtilIndex[team]
  1230 	elseif cat[cIndex] == "Mine Placement Mode" then
  1246 	elseif cat[cIndex] == "Mine Placement Mode" then
  1231 		pMode = {0,1000,2000,3000,4000,5000}
  1247 		pMode = {0,1000,2000,3000,4000,5000}
  1232 		placedExpense = 15
  1248 		placedExpense = 15
       
  1249 		teamLObjectMode[team] = cat[cIndex]
       
  1250 		pIndex = teamLMineIndex[team]
  1233 	elseif cat[cIndex] == "Sticky Mine Placement Mode" then
  1251 	elseif cat[cIndex] == "Sticky Mine Placement Mode" then
  1234 		pMode = {loc("Sticky Mine")}
  1252 		pMode = {loc("Sticky Mine")}
  1235 		placedExpense = 20
  1253 		placedExpense = 20
       
  1254 		teamLObjectMode[team] = cat[cIndex]
  1236 	elseif cat[cIndex] == "Structure Placement Mode" then
  1255 	elseif cat[cIndex] == "Structure Placement Mode" then
  1237 		pMode = {
  1256 		pMode = {
  1238 			loc("Support Station"),
  1257 			loc("Support Station"),
  1239 			loc("Construction Station"),
  1258 			loc("Construction Station"),
  1240 			loc("Healing Station"),
  1259 			loc("Healing Station"),
  1244 			loc("Bio-Filter"),
  1263 			loc("Bio-Filter"),
  1245 			loc("Reflector Shield"),
  1264 			loc("Reflector Shield"),
  1246 			loc("Respawner"),
  1265 			loc("Respawner"),
  1247 			loc("Generator"),
  1266 			loc("Generator"),
  1248 		}
  1267 		}
  1249 	end
  1268 		pIndex = teamLStructIndex[team]
  1250 
  1269 	end
  1251 
  1270 
  1252 
  1271 	return true
  1253 
       
  1254 end
  1272 end
  1255 
  1273 
  1256 -- called in onGameTick()
  1274 -- called in onGameTick()
  1257 function HandleHedgeEditor()
  1275 function HandleHedgeEditor()
  1258 
  1276 
  1432 			structureID = structureID + 5
  1450 			structureID = structureID + 5
  1433 		end
  1451 		end
  1434 		-- Check for valid pIndex
  1452 		-- Check for valid pIndex
  1435 		if structureID <= #pMode then
  1453 		if structureID <= #pMode then
  1436 			pIndex = structureID
  1454 			pIndex = structureID
  1437 			showModeMessage()
  1455 			updateIndex()
  1438 			updateCost()
       
  1439 		end
  1456 		end
  1440 	elseif (curWep == amCMObjectPlacer) then
  1457 	elseif (curWep == amCMObjectPlacer) then
  1441 		-- [Timer X]: Set mine time 1-5
  1458 		-- [Timer X]: Set mine time 1-5
  1442 		if cat[cIndex] == "Mine Placement Mode" then
  1459 		if cat[cIndex] == "Mine Placement Mode" then
  1443 			local index = key + 1
  1460 			local index = key + 1
  1444 			if key <= #pMode then
  1461 			if key <= #pMode then
  1445 				pIndex = index
  1462 				pIndex = index
  1446 				showModeMessage()
  1463 				updateIndex()
  1447 				updateCost()
       
  1448 			end
  1464 			end
  1449 		end
  1465 		end
  1450 	end
  1466 	end
  1451 
  1467 
  1452 end
  1468 end
  1453 
  1469 
  1454 function onSwitch()
  1470 function onSwitch()
  1455 	if (curWep == amCMObjectPlacer) then
  1471 	if (curWep == amCMObjectPlacer) then
  1456 		-- [Switch]: Set mine time to 0
  1472 		-- [Switch]: Set mine time to 0
  1457 		pIndex = 1
  1473 		pIndex = 1
       
  1474 		updateIndex()
       
  1475 	end
       
  1476 end
       
  1477 
       
  1478 function onLeft()
       
  1479 	if (curWep == amGirder) or (curWep == amRubber) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
       
  1480 		pIndex = pIndex - 1
       
  1481 		if pIndex == 0 then
       
  1482 			pIndex = #pMode
       
  1483 		end
       
  1484 		updateIndex()
       
  1485 	end
       
  1486 end
       
  1487 
       
  1488 function onRight()
       
  1489 	if (curWep == amGirder) or (curWep == amRubber) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
       
  1490 		pIndex = pIndex + 1
       
  1491 		if pIndex > #pMode then
       
  1492 			pIndex = 1
       
  1493 		end
       
  1494 		updateIndex()
       
  1495 	end
       
  1496 end
       
  1497 
       
  1498 -- Should be called when the index of the mode was changed by the player.
       
  1499 -- E.g. new weapon crate contents or structure type
       
  1500 function updateIndex()
       
  1501 	if (curWep == amGirder) or (curWep == amRubber) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
  1458 		showModeMessage()
  1502 		showModeMessage()
  1459 		updateCost()
  1503 		updateCost()
  1460 	end
  1504 	end
  1461 end
  1505 
  1462 
  1506 	-- Update team variables so the previous state can be restored later
  1463 function onLeft()
  1507 	if CurrentHedgehog == nil or band(GetState(CurrentHedgehog), gstHHDriven) == 0 then return end
  1464 
  1508 	local val = pMode[pIndex]
  1465 	pIndex = pIndex - 1
  1509 	local team = GetHogTeamName(CurrentHedgehog)
  1466 	if pIndex == 0 then
  1510 	if cat[cIndex] == "Mine Placement Mode" then
  1467 		pIndex = #pMode
  1511 		teamLMineIndex[team] = pIndex
  1468 	end
  1512 	elseif cat[cIndex] == "Weapon Crate Placement Mode" then
  1469 
  1513 		teamLWeapIndex[team] = pIndex
  1470 	if (curWep == amGirder) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
  1514 	elseif cat[cIndex] == "Utility Crate Placement Mode" then
  1471 		showModeMessage()
  1515 		teamLUtilIndex[team] = pIndex
  1472 		updateCost()
  1516 	end
  1473 	end
       
  1474 
       
  1475 
       
  1476 end
       
  1477 
       
  1478 function onRight()
       
  1479 
       
  1480 	pIndex = pIndex + 1
       
  1481 	if pIndex > #pMode then
       
  1482 		pIndex = 1
       
  1483 	end
       
  1484 
       
  1485 	if (curWep == amGirder) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
       
  1486 		showModeMessage()
       
  1487 		updateCost()
       
  1488 	end
       
  1489 
       
  1490 end
  1517 end
  1491 
  1518 
  1492 function showModeMessage()
  1519 function showModeMessage()
  1493 	if CurrentHedgehog == nil or band(GetState(CurrentHedgehog), gstHHDriven) == 0 then return end
  1520 	if CurrentHedgehog == nil or band(GetState(CurrentHedgehog), gstHHDriven) == 0 then return end
  1494 	local val = pMode[pIndex]
  1521 	local val = pMode[pIndex]
  1686 	sCirc = AddVisualGear(0,0,vgtCircle,0,true)
  1713 	sCirc = AddVisualGear(0,0,vgtCircle,0,true)
  1687 	SetVisualGearValues(sCirc, 0, 0, 100, 255, 1, 10, 0, 40, 3, 0x00000000)
  1714 	SetVisualGearValues(sCirc, 0, 0, 100, 255, 1, 10, 0, 40, 3, 0x00000000)
  1688 
  1715 
  1689 	for i = 0, ClansCount-1 do
  1716 	for i = 0, ClansCount-1 do
  1690 		clanPower[i] = math.min(conf_initialEnergy, conf_maxEnergy)
  1717 		clanPower[i] = math.min(conf_initialEnergy, conf_maxEnergy)
  1691 		clanLWepIndex[i] = 1 -- for ease of use let's track this stuff
  1718 
  1692 		clanLUtilIndex[i] = 1
       
  1693 		clanLGearIndex[i] = 1
       
  1694 		clanUsedExtraTime[i] = false
  1719 		clanUsedExtraTime[i] = false
  1695 		clanCratesSpawned[i] = 0
  1720 		clanCratesSpawned[i] = 0
  1696 		clanFirstTurn[i] = true
  1721 		clanFirstTurn[i] = true
  1697 
  1722 
       
  1723 	end
       
  1724 	for i = 0, TeamsCount-1 do
       
  1725 		local team = GetTeamName(i)
       
  1726 		teamLStructIndex[team] = 1
       
  1727 		teamLObjectMode[team] = "Mine Placement Mode"
       
  1728 		teamLCrateMode[team] = "Weapon Crate Placement Mode"
       
  1729 		teamLMineIndex[team] = 1
       
  1730 		teamLWeapIndex[team] = 1
       
  1731 		teamLUtilIndex[team] = 1
  1698 	end
  1732 	end
  1699 
  1733 
  1700 	tMapWidth = RightX - LeftX
  1734 	tMapWidth = RightX - LeftX
  1701 	tMapHeight = WaterLine - TopY
  1735 	tMapHeight = WaterLine - TopY
  1702 	clanInterval = div(tMapWidth,ClansCount)
  1736 	clanInterval = div(tMapWidth,ClansCount)