share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
changeset 12092 9fe7eb1f7df2
parent 12091 db5e12d623cc
child 12093 0d6e0ed36c9e
equal deleted inserted replaced
12091:db5e12d623cc 12092:9fe7eb1f7df2
    31 -- Possible keys:
    31 -- Possible keys:
    32 --- initialenergy: Amount of energy that each team starts with (default: 550)
    32 --- initialenergy: Amount of energy that each team starts with (default: 550)
    33 ---                Note: Must be smaller than or equal to maxenergy
    33 ---                Note: Must be smaller than or equal to maxenergy
    34 --- energyperround: Amount of energy that each team gets per round (default: 50)
    34 --- energyperround: Amount of energy that each team gets per round (default: 50)
    35 --- maxenergy: Maximum amount of energy each team can hold (default: 1000)
    35 --- maxenergy: Maximum amount of energy each team can hold (default: 1000)
       
    36 --- cratesperround: Maximum number of crates you can place per round (default: 5)
       
    37 
       
    38 -- For the previous 2 keys, you can use the value “inf” for an unlimited amount
    36 
    39 
    37 -- Example: “initialenergy=750, maxenergy=2000” starts thee game with 750 energy
    40 -- Example: “initialenergy=750, maxenergy=2000” starts thee game with 750 energy
    38 -- and sets the maximum energy to 2000
    41 --          and sets the maximum energy to 2000.
       
    42 -- Example: “craterperround=inf” disables the crate placement limit.
    39 
    43 
    40 ------------------------------------------------------------------------------
    44 ------------------------------------------------------------------------------
    41 --version history
    45 --version history
    42 ------------------------------------------------------------------------------
    46 ------------------------------------------------------------------------------
    43 --v0.1
    47 --v0.1
   199 
   203 
   200 -- Config variables (script parameter)
   204 -- Config variables (script parameter)
   201 conf_initialEnergy = 550
   205 conf_initialEnergy = 550
   202 conf_energyPerRound = 50
   206 conf_energyPerRound = 50
   203 conf_maxEnergy = 1000
   207 conf_maxEnergy = 1000
       
   208 conf_cratesPerRound = 5
   204 
   209 
   205 function HideTags()
   210 function HideTags()
   206 
   211 
   207 	for i = 0, 2 do
   212 	for i = 0, 2 do
   208 		SetVisualGearValues(vTag[i],0,0,0,0,0,1,0, 0, 240000, 0xffffff00)
   213 		SetVisualGearValues(vTag[i],0,0,0,0,0,1,0, 0, 240000, 0xffffff00)
  1105 	placedY[placedCount] = y
  1110 	placedY[placedCount] = y
  1106 	placedType[placedCount] = cat[cIndex]
  1111 	placedType[placedCount] = cat[cIndex]
  1107 	placedSpec[placedCount] = pMode[pIndex]
  1112 	placedSpec[placedCount] = pMode[pIndex]
  1108 
  1113 
  1109 	if (clanUsedExtraTime[GetHogClan(CurrentHedgehog)] == true) and (cat[cIndex] == "Utility Crate Placement Mode") and (utilArray[pIndex][1] == amExtraTime) then
  1114 	if (clanUsedExtraTime[GetHogClan(CurrentHedgehog)] == true) and (cat[cIndex] == "Utility Crate Placement Mode") and (utilArray[pIndex][1] == amExtraTime) then
  1110 		AddCaption(loc("You may only spawn 1 Extra Time per turn."),0xffba00ff,capgrpVolume)
  1115 		AddCaption(loc("You may only place 1 Extra Time crate per turn."),0xffba00ff,capgrpVolume)
  1111 		PlaySound(sndDenied)
  1116 		PlaySound(sndDenied)
  1112 	elseif (clanCratesSpawned[GetHogClan(CurrentHedgehog)] > 4) and ( (cat[cIndex] == "Health Crate Placement Mode") or (cat[cIndex] == "Utility Crate Placement Mode") or (cat[cIndex] == "Weapon Crate Placement Mode")  )  then
  1117 	elseif (conf_cratesPerRound ~= "inf" and clanCratesSpawned[GetHogClan(CurrentHedgehog)] >= conf_cratesPerRound) and ( (cat[cIndex] == "Health Crate Placement Mode") or (cat[cIndex] == "Utility Crate Placement Mode") or (cat[cIndex] == "Weapon Crate Placement Mode")  )  then
  1113 		AddCaption(loc("You may only spawn 5 crates per turn."),0xffba00ff,capgrpVolume)
  1118 		AddCaption(string.format(loc("You may only place %d crates per round."), conf_cratesPerRound),0xffba00ff,capgrpVolume)
  1114 		PlaySound(sndDenied)
  1119 		PlaySound(sndDenied)
  1115 	elseif (XYisInRect(x,y, clanBoundsSX[GetHogClan(CurrentHedgehog)],clanBoundsSY[GetHogClan(CurrentHedgehog)],clanBoundsEX[GetHogClan(CurrentHedgehog)],clanBoundsEY[GetHogClan(CurrentHedgehog)]) == true)
  1120 	elseif (XYisInRect(x,y, clanBoundsSX[GetHogClan(CurrentHedgehog)],clanBoundsSY[GetHogClan(CurrentHedgehog)],clanBoundsEX[GetHogClan(CurrentHedgehog)],clanBoundsEY[GetHogClan(CurrentHedgehog)]) == true)
  1116 	and (clanPower[GetHogClan(CurrentHedgehog)] >= placedExpense)
  1121 	and (clanPower[GetHogClan(CurrentHedgehog)] >= placedExpense)
  1117 	then
  1122 	then
  1118 		-- For checking if the actual placement succeeded
  1123 		-- For checking if the actual placement succeeded
  1524 ----------------------------
  1529 ----------------------------
  1525 -- standard event handlers
  1530 -- standard event handlers
  1526 ----------------------------
  1531 ----------------------------
  1527 
  1532 
  1528 -- Parses a positive integer
  1533 -- Parses a positive integer
  1529 function parseInt(str, default)
  1534 function parseInt(str, default, infinityPermitted)
       
  1535 	if str == "inf" and infinityPermitted then
       
  1536 		return "inf"
       
  1537 	end
  1530 	if str == nil then return default end
  1538 	if str == nil then return default end
  1531 	local s = string.match(str, "(%d*)")
  1539 	local s = string.match(str, "(%d*)")
  1532 	if s ~= nil then
  1540 	if s ~= nil then
  1533 		return math.min(4294967295, math.max(0, tonumber(s)))
  1541 		return math.min(4294967295, math.max(0, tonumber(s)))
  1534 	else
  1542 	else
  1539 -- Parse parameters
  1547 -- Parse parameters
  1540 function onParameters()
  1548 function onParameters()
  1541 	parseParams()
  1549 	parseParams()
  1542 	conf_initialEnergy = parseInt(params["initialenergy"], conf_initialEnergy)
  1550 	conf_initialEnergy = parseInt(params["initialenergy"], conf_initialEnergy)
  1543 	conf_energyPerRound = parseInt(params["energyperround"], conf_energyPerRound)
  1551 	conf_energyPerRound = parseInt(params["energyperround"], conf_energyPerRound)
  1544 	if params["maxenergy"] == "inf" then
  1552 	conf_maxEnergy = parseInt(params["maxenergy"], conf_maxEnergy, true)
  1545 		conf_maxEnergy = "inf"
  1553 	conf_cratesPerRound = parseInt(params["cratesperround"], conf_cratesPerRound, true)
  1546 	else
       
  1547 		conf_maxEnergy = parseInt(params["maxenergy"], conf_maxEnergy)
       
  1548 	end
       
  1549 end
  1554 end
  1550 
  1555 
  1551 function onGameInit()
  1556 function onGameInit()
  1552 
  1557 
  1553 	Explosives = 0
  1558 	Explosives = 0
  1604 	loc("Construction Station: Allows placement of|    girders, rubber, mines, sticky mines|    and barrels.")  .. "|" ..
  1609 	loc("Construction Station: Allows placement of|    girders, rubber, mines, sticky mines|    and barrels.")  .. "|" ..
  1605 	loc("Support Station: Allows placement of crates.") .. "| |" ..
  1610 	loc("Support Station: Allows placement of crates.") .. "| |" ..
  1606 
  1611 
  1607 	loc("Left/right: Choose structure type|Cursor: Build structure"))
  1612 	loc("Left/right: Choose structure type|Cursor: Build structure"))
  1608 
  1613 
  1609 	SetAmmoTexts(amNapalm, loc("Crate Placer"), loc("Construction Mode tool"), loc("This allows you to create a crate anywhere|within your clan's area of influence,|at the cost of energy.|Up/down: Choose crate type|Left/right: Choose crate contents|Cursor: Place crate"))
  1614 	local txt_crateLimit = ""
       
  1615 	if conf_cratesPerRound ~= "inf" then
       
  1616 		txt_crateLimit = string.format(loc("You may only place %d crates per round."), conf_cratesPerRound) .. "|"
       
  1617 	end
       
  1618 
       
  1619 	SetAmmoTexts(amNapalm, loc("Crate Placer"), loc("Construction Mode tool"),
       
  1620 		loc("This allows you to create a crate anywhere|within your clan's area of influence,|at the cost of energy.") .. "|" ..
       
  1621 		txt_crateLimit ..
       
  1622 		loc("Up/down: Choose crate type") .. "|" .. 
       
  1623 		loc("Left/right: Choose crate contents") .. "|" ..
       
  1624 		loc("|Cursor: Place crate"))
  1610 	SetAmmoTexts(amDrillStrike, loc("Object Placer"), loc("Construction Mode tool"), loc("This allows you to create and place mines,|sticky mines and barrels anywhere within your|clan's area of influence at the cost of energy.|Up/down: Choose object type|Left/right: Choose timer (for mines)|Cursor: Place object"))
  1625 	SetAmmoTexts(amDrillStrike, loc("Object Placer"), loc("Construction Mode tool"), loc("This allows you to create and place mines,|sticky mines and barrels anywhere within your|clan's area of influence at the cost of energy.|Up/down: Choose object type|Left/right: Choose timer (for mines)|Cursor: Place object"))
  1611 
  1626 
  1612 	sCirc = AddVisualGear(0,0,vgtCircle,0,true)
  1627 	sCirc = AddVisualGear(0,0,vgtCircle,0,true)
  1613 	SetVisualGearValues(sCirc, 0, 0, 100, 255, 1, 10, 0, 40, 3, 0x00000000)
  1628 	SetVisualGearValues(sCirc, 0, 0, 100, 255, 1, 10, 0, 40, 3, 0x00000000)
  1614 
  1629