share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
changeset 12946 1a1a514aef2e
parent 12945 0e698562d76d
child 12948 f85a040d0350
equal deleted inserted replaced
12945:0e698562d76d 12946:1a1a514aef2e
  1272 	end
  1272 	end
  1273 
  1273 
  1274 	return true
  1274 	return true
  1275 end
  1275 end
  1276 
  1276 
       
  1277 -- Updates the handling of the main construction mode tools:
       
  1278 -- Structure Placer, Crate Placer, Object Placer.
       
  1279 -- This handles the internal category state,
       
  1280 -- the HUD display and the clans outline.
       
  1281 function HandleConstructionModeTools()
       
  1282 	-- Update display selection criteria
       
  1283 	if (CurrentHedgehog ~= nil and band(GetState(CurrentHedgehog), gstHHDriven) ~= 0) then
       
  1284 		curWep = GetCurAmmoType()
       
  1285 
       
  1286 		local updated = false
       
  1287 		local team = GetHogTeamName(CurrentHedgehog)
       
  1288 		if (curWep == amGirder) then
       
  1289 			cIndex = 1
       
  1290 			RedefineSubset()
       
  1291 			updated = true
       
  1292 		elseif (curWep == amRubber) then
       
  1293 			cIndex = 2
       
  1294 			RedefineSubset()
       
  1295 			updated = true
       
  1296 		elseif (curWep == amCMStructurePlacer) then
       
  1297 			cIndex = 9
       
  1298 			RedefineSubset()
       
  1299 			updateCost()
       
  1300 			updated = true
       
  1301 		elseif (curWep == amCMCratePlacer) then
       
  1302 			cIndex = catReverse[teamLCrateMode[team]]
       
  1303 			RedefineSubset()
       
  1304 			updateCost()
       
  1305 			updated = true
       
  1306 		elseif (curWep == amCMObjectPlacer) then
       
  1307 			cIndex = catReverse[teamLObjectMode[team]]
       
  1308 			RedefineSubset()
       
  1309 			updateCost()
       
  1310 			updated = true
       
  1311 		end
       
  1312 
       
  1313 		if updated then
       
  1314 			AddCaption(loc(cat[cIndex]), 0xffba00ff, capgrpMessage)
       
  1315 			showModeMessage()
       
  1316 			wallsVisible = true
       
  1317 		else
       
  1318 			wallsVisible = false
       
  1319 		end
       
  1320 	else
       
  1321 		curWep = amNothing
       
  1322 		wallsVisible = false
       
  1323 	end
       
  1324 end
       
  1325 
       
  1326 
  1277 -- called in onGameTick()
  1327 -- called in onGameTick()
  1278 function HandleHedgeEditor()
  1328 function HandleConstructionMode()
  1279 
  1329 
  1280 	HandleStructures()
  1330 	HandleStructures()
  1281 
  1331 
  1282 	if CurrentHedgehog ~= nil then
  1332 	if CurrentHedgehog ~= nil then
  1283 
  1333 
  1298 
  1348 
  1299 		if GameTime % 100 == 0 then
  1349 		if GameTime % 100 == 0 then
  1300 
  1350 
  1301 			DrawClanPowerTag()
  1351 			DrawClanPowerTag()
  1302 
  1352 
  1303 
  1353 			-- Force-update the construction mode tools every 100ms.
  1304 			-- Update display selection criteria
  1354 			-- This makes sure the announcer messages don't disappear
       
  1355 			-- while the tool is selected.
  1305 			if (band(GetState(CurrentHedgehog), gstHHDriven) ~= 0) then
  1356 			if (band(GetState(CurrentHedgehog), gstHHDriven) ~= 0) then
  1306 				curWep = GetCurAmmoType()
  1357 				curWep = GetCurAmmoType()
  1307 
  1358 				HandleConstructionModeTools()
  1308 				local updated = false
       
  1309 				local team = GetHogTeamName(CurrentHedgehog)
       
  1310 				if (curWep == amGirder) then
       
  1311 					cIndex = 1
       
  1312 					RedefineSubset()
       
  1313 					updated = true
       
  1314 				elseif (curWep == amRubber) then
       
  1315 					cIndex = 2
       
  1316 					RedefineSubset()
       
  1317 					updated = true
       
  1318 				elseif (curWep == amCMStructurePlacer) then
       
  1319 					cIndex = 9
       
  1320 					RedefineSubset()
       
  1321 					updateCost()
       
  1322 					updated = true
       
  1323 				elseif (curWep == amCMCratePlacer) then
       
  1324 					cIndex = catReverse[teamLCrateMode[team]]
       
  1325 					RedefineSubset()
       
  1326 					updateCost()
       
  1327 					updated = true
       
  1328 				elseif (curWep == amCMObjectPlacer) then
       
  1329 					cIndex = catReverse[teamLObjectMode[team]]
       
  1330 					RedefineSubset()
       
  1331 					updateCost()
       
  1332 					updated = true
       
  1333 				end
       
  1334 
       
  1335 				if updated then
       
  1336 					AddCaption(loc(cat[cIndex]), 0xffba00ff, capgrpMessage)
       
  1337 					showModeMessage()
       
  1338 					wallsVisible = true
       
  1339 				else
       
  1340 					wallsVisible = false
       
  1341 				end
       
  1342 			else
  1359 			else
  1343 				curWep = amNothing
  1360 				curWep = amNothing
  1344 				wallsVisible = false
       
  1345 			end
  1361 			end
  1346 
  1362 
  1347 		end
  1363 		end
  1348 
  1364 
  1349 	end
  1365 	end
  1410 	AddCaption(loc("Cost") .. ": " .. placedExpense,0xffba00ff,capgrpAmmostate)
  1426 	AddCaption(loc("Cost") .. ": " .. placedExpense,0xffba00ff,capgrpAmmostate)
  1411 
  1427 
  1412 end
  1428 end
  1413 
  1429 
  1414 function onTimer(key)
  1430 function onTimer(key)
       
  1431 	curWep = GetCurAmmoType()
  1415 
  1432 
  1416 	-- Hacky workaround for object placer: Since this is based on the drill strike, it
  1433 	-- Hacky workaround for object placer: Since this is based on the drill strike, it
  1417 	-- allows the 5 timer keys to be pressed, causing the announcer to show up
  1434 	-- allows the 5 timer keys to be pressed, causing the announcer to show up
  1418 	-- This triggers code in 1 tick to send other message to mask the earlier one.
  1435 	-- This triggers code in 1 tick to send other message to mask the earlier one.
  1419 	checkForSpecialWeaponsIn = 1
  1436 	checkForSpecialWeaponsIn = 1
  1445 	end
  1462 	end
  1446 
  1463 
  1447 end
  1464 end
  1448 
  1465 
  1449 function onSwitch()
  1466 function onSwitch()
       
  1467 	curWep = GetCurAmmoType()
  1450 	if (curWep == amCMObjectPlacer) then
  1468 	if (curWep == amCMObjectPlacer) then
  1451 		-- [Switch]: Set mine time to 0
  1469 		-- [Switch]: Set mine time to 0
  1452 		pIndex = 1
  1470 		pIndex = 1
  1453 		updateIndex()
  1471 		updateIndex()
  1454 	end
  1472 	end
  1455 end
  1473 end
  1456 
  1474 
  1457 function onLeft()
  1475 function onLeft()
       
  1476 	curWep = GetCurAmmoType()
  1458 	if (curWep == amGirder) or (curWep == amRubber) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
  1477 	if (curWep == amGirder) or (curWep == amRubber) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
  1459 		pIndex = pIndex - 1
  1478 		pIndex = pIndex - 1
  1460 		if pIndex == 0 then
  1479 		if pIndex == 0 then
  1461 			pIndex = #pMode
  1480 			pIndex = #pMode
  1462 		end
  1481 		end
  1463 		updateIndex()
  1482 		updateIndex()
  1464 	end
  1483 	end
  1465 end
  1484 end
  1466 
  1485 
  1467 function onRight()
  1486 function onRight()
       
  1487 	curWep = GetCurAmmoType()
  1468 	if (curWep == amGirder) or (curWep == amRubber) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
  1488 	if (curWep == amGirder) or (curWep == amRubber) or (curWep == amCMStructurePlacer) or (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) then
  1469 		pIndex = pIndex + 1
  1489 		pIndex = pIndex + 1
  1470 		if pIndex > #pMode then
  1490 		if pIndex > #pMode then
  1471 			pIndex = 1
  1491 			pIndex = 1
  1472 		end
  1492 		end
  1512 		str = tostring(val)
  1532 		str = tostring(val)
  1513 	end
  1533 	end
  1514 	AddCaption(str,0xffba00ff,capgrpMessage2)
  1534 	AddCaption(str,0xffba00ff,capgrpMessage2)
  1515 end
  1535 end
  1516 
  1536 
  1517 function updatePlacementDisplay(pDir)
  1537 function rotateMode(pDir)
  1518 
  1538 	curWep = GetCurAmmoType()
  1519 	foundMatch = false
  1539 	local foundMatch = false
  1520 	while(foundMatch == false) do
  1540 	while(foundMatch == false) do
  1521 		cIndex = cIndex + pDir
  1541 		cIndex = cIndex + pDir
  1522 
  1542 
  1523 		if (cIndex == 1) or (cIndex == 2) then --1	--we no longer hit girder by normal means
  1543 		if (cIndex == 1) or (cIndex == 2) then -- we no longer hit girder by normal means
  1524 			cIndex = #cat
  1544 			cIndex = #cat
  1525 		elseif cIndex > #cat then
  1545 		elseif cIndex > #cat then
  1526 			cIndex = 3	 -- 2 ----we no longer hit girder by normal means
  1546 			cIndex = 3       -- we no longer hit girder by normal means
  1527 		end
  1547 		end
  1528 
  1548 
  1529 		if sProx[cIndex][2] == true then
  1549 		if (GetCurAmmoType() == amCMCratePlacer) then
  1530 			if (GetCurAmmoType() == amCMCratePlacer) then
  1550 			if (sProx[cIndex][1] == loc("Health Crate Placement Mode")) or
  1531 				if (sProx[cIndex][1] == loc("Health Crate Placement Mode")) or
  1551 				(sProx[cIndex][1] == loc("Weapon Crate Placement Mode")) or
  1532 					(sProx[cIndex][1] == loc("Weapon Crate Placement Mode")) or
  1552 				(sProx[cIndex][1] == loc("Utility Crate Placement Mode")) then
  1533 					(sProx[cIndex][1] == loc("Utility Crate Placement Mode"))
       
  1534 					then
       
  1535 						foundMatch = true
       
  1536 					end
       
  1537 			elseif (GetCurAmmoType() == amCMObjectPlacer) then
       
  1538 				if (sProx[cIndex][1] == loc("Mine Placement Mode")) or
       
  1539 					(sProx[cIndex][1] == loc("Sticky Mine Placement Mode")) or
       
  1540 					(sProx[cIndex][1] == loc("Barrel Placement Mode"))
       
  1541 					then
       
  1542 						foundMatch = true
       
  1543 					end
       
  1544 			elseif (GetCurAmmoType() == amCMStructurePlacer) then
       
  1545 				if sProx[cIndex][1] == loc("Structure Placement Mode") then
       
  1546 					foundMatch = true
  1553 					foundMatch = true
  1547 				end
  1554 			end
  1548 			end
  1555 		elseif (GetCurAmmoType() == amCMObjectPlacer) then
  1549 		end
  1556 			if (sProx[cIndex][1] == loc("Mine Placement Mode")) or
  1550 
  1557 				(sProx[cIndex][1] == loc("Sticky Mine Placement Mode")) or
  1551 
  1558 				(sProx[cIndex][1] == loc("Barrel Placement Mode")) then
  1552 		if foundMatch == true then
  1559 				foundMatch = true
  1553 			RedefineSubset()
  1560 			end
  1554 			updateCost()
  1561 		elseif (GetCurAmmoType() == amCMStructurePlacer) then
  1555 		end
  1562 			if sProx[cIndex][1] == loc("Structure Placement Mode") then
  1556 
  1563 				foundMatch = true
  1557 	end
  1564 			end
  1558 
  1565 		end
       
  1566 	end
       
  1567 
       
  1568 	if foundMatch == true then
       
  1569 		RedefineSubset()
       
  1570 		--updateCost()
       
  1571 		HandleConstructionModeTools()
       
  1572 	end
  1559 end
  1573 end
  1560 
  1574 
  1561 ---------------------------------------------------------
  1575 ---------------------------------------------------------
  1562 -- Cycle through primary categories (by changing cIndex)
  1576 -- Cycle through primary categories (by changing cIndex)
  1563 -- i.e 	mine, sticky mine, barrels
  1577 -- i.e 	mine, sticky mine, barrels
  1564 --		health/weapon/utility crate, placement of gears
  1578 --		health/weapon/utility crate, placement of gears
  1565 ---------------------------------------------------------
  1579 ---------------------------------------------------------
  1566 function onUp()
  1580 function onUp()
  1567 
  1581 
       
  1582 	curWep = GetCurAmmoType()
  1568 	if ( (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) ) then
  1583 	if ( (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) ) then
  1569 		if CurrentHedgehog ~= nil and band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 then
  1584 		if CurrentHedgehog ~= nil and band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 then
  1570 			updatePlacementDisplay(-1)
  1585 			rotateMode(-1)
  1571 		end
  1586 		end
  1572 	end
  1587 	end
  1573 
  1588 
  1574 end
  1589 end
  1575 
  1590 
  1576 function onDown()
  1591 function onDown()
  1577 
  1592 
       
  1593 	curWep = GetCurAmmoType()
  1578 	if ( (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) ) then
  1594 	if ( (curWep == amCMCratePlacer) or (curWep == amCMObjectPlacer) ) then
  1579 		if CurrentHedgehog ~= nil and band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 then
  1595 		if CurrentHedgehog ~= nil and band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 then
  1580 			updatePlacementDisplay(1)
  1596 			rotateMode(1)
  1581 		end
  1597 		end
  1582 	end
  1598 	end
  1583 
  1599 
  1584 end
  1600 end
       
  1601 
       
  1602 onSetWeapon = HandleConstructionModeTools()
       
  1603 onSlot = onSetWeapon
  1585 
  1604 
  1586 ----------------------------
  1605 ----------------------------
  1587 -- standard event handlers
  1606 -- standard event handlers
  1588 ----------------------------
  1607 ----------------------------
  1589 
  1608 
  1750 
  1769 
  1751 function onNewTurn()
  1770 function onNewTurn()
  1752 
  1771 
  1753 	curWep = GetCurAmmoType()
  1772 	curWep = GetCurAmmoType()
  1754 
  1773 
       
  1774 	HandleConstructionModeTools()
       
  1775 
  1755 	local clan = GetHogClan(CurrentHedgehog)
  1776 	local clan = GetHogClan(CurrentHedgehog)
  1756 	if clanFirstTurn[clan] then
  1777 	if clanFirstTurn[clan] then
  1757 		clanFirstTurn[clan] = false
  1778 		clanFirstTurn[clan] = false
  1758 	else
  1779 	else
  1759 		clanPower[clan] = clanPower[clan] + conf_energyPerRound
  1780 		clanPower[clan] = clanPower[clan] + conf_energyPerRound
  1761 			clanPower[clan] = conf_maxEnergy
  1782 			clanPower[clan] = conf_maxEnergy
  1762 		end
  1783 		end
  1763 	end
  1784 	end
  1764 	clanUsedExtraTime[clan] = false
  1785 	clanUsedExtraTime[clan] = false
  1765 	clanCratesSpawned[clan] = 0
  1786 	clanCratesSpawned[clan] = 0
  1766 
  1787 end
  1767 end
  1788 
  1768 
  1789 function onEndTurn()
  1769 function onTurnEnd()
       
  1770 	curWep = amNothing
  1790 	curWep = amNothing
       
  1791 	HandleConstructionModeTools()
  1771 end
  1792 end
  1772 
  1793 
  1773 function onGameTick()
  1794 function onGameTick()
  1774 	HandleHedgeEditor()
  1795 	HandleConstructionMode()
  1775 end
  1796 end
  1776 
  1797 
  1777 function isATrackedGear(gear)
  1798 function isATrackedGear(gear)
  1778 	if 	(GetGearType(gear) == gtHedgehog) or
  1799 	if 	(GetGearType(gear) == gtHedgehog) or
  1779 		(GetGearType(gear) == gtTarget) or
  1800 		(GetGearType(gear) == gtTarget) or