share/hedgewars/Data/Scripts/Multiplayer/Battalion.lua
changeset 12420 e11758f70cce
parent 12417 ed33ef8a0fc5
child 12421 91697da092ff
equal deleted inserted replaced
12419:d43ded9a0c34 12420:e11758f70cce
   723   SetHealth(hog, variants[hogVar]["hp"])
   723   SetHealth(hog, variants[hogVar]["hp"])
   724 end
   724 end
   725 
   725 
   726 function getHogInfo(hog, info)
   726 function getHogInfo(hog, info)
   727   if hog == nil then
   727   if hog == nil then
   728     AddCaption(loc("ERROR [getHogInfo]: Hog") .. hog .. " is nil!", 0xFFFFFFFF, capgrpMessage)
   728     AddCaption(loc("ERROR [getHogInfo]: Hog is nil!"), 0xFFFFFFFF, capgrpMessage)
   729     WriteLnToConsole(loc("ERROR [getHogInfo]: Hog") .. hog .. " is nil!")
   729     WriteLnToConsole(loc("ERROR [getHogInfo]: Hog is nil!"), 0xFFFFFFFF, capgrpMessage)
   730     return
   730     return
   731   end
   731   end
   732 
   732 
   733   if hogInfo[hog] == nil then
   733   if hogInfo[hog] == nil then
   734     return nil
   734     return nil
   737   return hogInfo[hog][info]
   737   return hogInfo[hog][info]
   738 end
   738 end
   739 
   739 
   740 function setHogInfo(hog)
   740 function setHogInfo(hog)
   741   if hog == nil then
   741   if hog == nil then
   742     AddCaption(loc("ERROR [setHogInfo]: Hog") .. hog .. " is nil!", 0xFFFFFFFF, capgrpMessage)
   742     AddCaption(loc("ERROR [getHogInfo]: Hog is nil!"), 0xFFFFFFFF, capgrpMessage)
   743     WriteLnToConsole(loc("ERROR [setHogInfo]: Hog") .. hog .. " is nil!")
   743     WriteLnToConsole(loc("ERROR [getHogInfo]: Hog is nil!"), 0xFFFFFFFF, capgrpMessage)
   744     return
   744     return
   745   end
   745   end
   746 
   746 
   747   hogInfo[hog] = {}
   747   hogInfo[hog] = {}
   748   hogInfo[hog]['maxHp'] = GetHealth(hog)
   748   hogInfo[hog]['maxHp'] = GetHealth(hog)
   770   local msgColor = getHogInfo(CurHog, 'clanColor')
   770   local msgColor = getHogInfo(CurHog, 'clanColor')
   771   local healHp = 0
   771   local healHp = 0
   772   PlaySound(sndShotgunReload)
   772   PlaySound(sndShotgunReload)
   773 
   773 
   774   if GetRandom(100) < emptyCrateChance then
   774   if GetRandom(100) < emptyCrateChance then
   775     AddCaption(loc("empty crate"), msgColor, capgrpMessage)
   775     AddCaption(loc("It's empty!"), msgColor, capgrpMessage)
   776     return
   776     return
   777   elseif GetRandom(100) < bonusCrateChance then
   777   elseif GetRandom(100) < bonusCrateChance then
   778     factor = 3
   778     factor = 3
   779   end
   779   end
   780 
   780 
   783   healHp = 5 * factor
   783   healHp = 5 * factor
   784 
   784 
   785   -- Add extra 10% of hogs base hp to heal
   785   -- Add extra 10% of hogs base hp to heal
   786   healHp = healHp + div(getHogInfo(CurHog, 'maxHp'), 10)
   786   healHp = healHp + div(getHogInfo(CurHog, 'maxHp'), 10)
   787 
   787 
   788   AddCaption(loc("+ ") .. healHp .. loc(" hp"), msgColor, capgrpMessage)
   788   AddCaption(string.format(loc("+%d"), healHp), msgColor, capgrpMessage)
   789 
   789 
   790   SetEffect(CurHog, hePoisoned, 0)
   790   SetEffect(CurHog, hePoisoned, 0)
   791   SetHealth(CurHog, hogHealth + healHp)
   791   SetHealth(CurHog, hogHealth + healHp)
   792   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtHealthTag, healHp, false)
   792   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtHealthTag, healHp, false)
   793   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
   793   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
   803   local factor = 1 * strength
   803   local factor = 1 * strength
   804   local msgColor = GetClanColor(GetHogClan(CurHog))
   804   local msgColor = GetClanColor(GetHogClan(CurHog))
   805   PlaySound(sndShotgunReload)
   805   PlaySound(sndShotgunReload)
   806 
   806 
   807   if GetRandom(100) < emptyCrateChance then
   807   if GetRandom(100) < emptyCrateChance then
   808     AddCaption(loc("empty crate"), msgColor, capgrpMessage)
   808     AddCaption(loc("It's empty!"), msgColor, capgrpMessage)
   809     return
   809     return
   810   elseif GetRandom(100) < bonusCrateChance then
   810   elseif GetRandom(100) < bonusCrateChance then
   811     factor = 2 * strength
   811     factor = 2 * strength
   812   end
   812   end
   813 
   813 
   829 
   829 
   830     randIndex = GetRandom(table.getn(possibleWeapons)) +1
   830     randIndex = GetRandom(table.getn(possibleWeapons)) +1
   831     randAmmo = possibleWeapons[randIndex]
   831     randAmmo = possibleWeapons[randIndex]
   832   end
   832   end
   833 
   833 
   834   AddCaption(loc("+ ") .. factor .. loc(" ammo"), msgColor, capgrpMessage)
   834   AddCaption(string.format(loc("+%d ammo"), factor), msgColor, capgrpMessage)
   835 
   835 
   836   AddAmmo(CurHog, randAmmo, GetAmmoCount(CurHog, randAmmo) +factor)
   836   AddAmmo(CurHog, randAmmo, GetAmmoCount(CurHog, randAmmo) +factor)
   837   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtAmmo, 0, true)
   837   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtAmmo, 0, true)
   838   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
   838   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
   839   SetVisualGearValues(effect, nil, nil, nil, nil, nil, randAmmo, nil, nil, nil, msgColor)
   839   SetVisualGearValues(effect, nil, nil, nil, nil, nil, randAmmo, nil, nil, nil, msgColor)
   847   local factor = 1 * strength
   847   local factor = 1 * strength
   848   local msgColor = GetClanColor(GetHogClan(CurHog))
   848   local msgColor = GetClanColor(GetHogClan(CurHog))
   849   PlaySound(sndShotgunReload)
   849   PlaySound(sndShotgunReload)
   850 
   850 
   851   if GetRandom(100) < emptyCrateChance then
   851   if GetRandom(100) < emptyCrateChance then
   852     AddCaption(loc("empty crate"), msgColor, capgrpMessage)
   852     AddCaption(loc("It's empty!"), msgColor, capgrpMessage)
   853     return
   853     return
   854   elseif GetRandom(100) < bonusCrateChance then
   854   elseif GetRandom(100) < bonusCrateChance then
   855     factor = 2 * strength
   855     factor = 2 * strength
   856   end
   856   end
   857 
   857 
   870 
   870 
   871     randIndex = GetRandom(table.getn(possibleHelpers)) +1
   871     randIndex = GetRandom(table.getn(possibleHelpers)) +1
   872     randUtility = possibleHelpers[randIndex]
   872     randUtility = possibleHelpers[randIndex]
   873   end
   873   end
   874   
   874   
   875   AddCaption(loc("+ ") .. factor .. loc(" ammo"), msgColor, capgrpMessage)
   875   AddCaption(string.format(loc("+%d ammo"), factor), msgColor, capgrpMessage)
   876 
   876 
   877   AddAmmo(CurHog, randUtility, GetAmmoCount(CurHog, randUtility) +factor)
   877   AddAmmo(CurHog, randUtility, GetAmmoCount(CurHog, randUtility) +factor)
   878   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtAmmo, 0, true)
   878   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtAmmo, 0, true)
   879   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
   879   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
   880   SetVisualGearValues(effect, nil, nil, nil, nil, nil, randUtility, nil, nil, nil, msgColor)
   880   SetVisualGearValues(effect, nil, nil, nil, nil, nil, randUtility, nil, nil, nil, msgColor)
  1136 
  1136 
  1137 function onKingDeath(KingHog)
  1137 function onKingDeath(KingHog)
  1138   local team = getHogInfo(KingHog, 'team')
  1138   local team = getHogInfo(KingHog, 'team')
  1139   local msgColor = getHogInfo(KingHog, 'clanColor')
  1139   local msgColor = getHogInfo(KingHog, 'clanColor')
  1140 
  1140 
  1141   AddCaption(team .. loc("s king died"), msgColor, capgrpGameState)
  1141   AddCaption(string.format(loc("The king of %s has died!"), team), 0xFFFFFFFF, capgrpGameState)
  1142   PlaySound(sndByeBye)
  1142   PlaySound(sndByeBye)
  1143   DismissTeam(team)
  1143   DismissTeam(team)
  1144 
  1144 
  1145   -- for hog, val in pairs(hogInfo) do
  1145   -- for hog, val in pairs(hogInfo) do
  1146   --   if getHogInfo(hog, 'team') == team then
  1146   --   if getHogInfo(hog, 'team') == team then
  1401   TurnEnded = false
  1401   TurnEnded = false
  1402 
  1402 
  1403   if suddenDeath == true then
  1403   if suddenDeath == true then
  1404     onSuddenDeathTurn()
  1404     onSuddenDeathTurn()
  1405   else
  1405   else
  1406     AddCaption(loc("Round #") .. (TotalRounds +1).. loc(" (SD on #") .. (SuddenDeathTurns +2) .. ")", getHogInfo(CurHog, 'clanColor'),  capgrpGameState)
  1406     AddCaption(string.format(loc("Round %d (Sudden Death in round %d)"), (TotalRounds +1), (SuddenDeathTurns +2)), getHogInfo(CurHog, 'clanColor'),  capgrpGameState)
  1407   end
  1407   end
  1408 
  1408 
  1409   -- Generate new weapons for last hog if it's still alive
  1409   -- Generate new weapons for last hog if it's still alive
  1410   if LastHog ~= nil and LastHog ~= CurHog then
  1410   if LastHog ~= nil and LastHog ~= CurHog then
  1411     if mode == 'points' then
  1411     if mode == 'points' then
  1610 
  1610 
  1611   local txt = ''
  1611   local txt = ''
  1612   local icon = 0
  1612   local icon = 0
  1613 
  1613 
  1614   if mode ~= 'points' then
  1614   if mode ~= 'points' then
  1615     txt = txt .. loc("Variants: Hogs will be randomized from 12 different variants|")
  1615     txt = txt .. loc("Variants: Hogs will be randomized from 12 different variants") .. "|"
  1616     txt = txt .. loc("Weapon: Hogs will get 1 out of 3 weapons randomly each turn|")
  1616     txt = txt .. loc("Weapons: Hogs will get 1 out of 3 weapons randomly each turn") .. "|"
  1617     txt = txt .. loc("Helper: Hogs will get 1 out of 2 helpers randomly each turn|")
  1617     txt = txt .. loc("Helpers: Hogs will get 1 out of 2 helpers randomly each turn") .. "|"
  1618     txt = txt .. loc("Crates: Crates spawn randomly with chance of being empty|")
  1618     txt = txt .. loc("Crates: Crates drop randomly with chance of being empty") .. "|"
  1619     txt = txt .. loc("Hogs: Less than 25% base hp gives +Kamikaze|")
  1619     txt = txt .. loc("Last Resort: Having less than 25% base health gives kamikaze") .. "|"
  1620     txt = txt .. loc("Flags: Unlimited Ammo, Per Hog Ammo|")
  1620     txt = txt .. loc("Modifiers: Unlimited ammo, per-hog ammo") .. "|"
  1621   else
  1621   else
  1622     txt = txt .. loc("Crates: Crates spawn randomly with chance of being empty|")
  1622     txt = txt .. loc("Crates: Crates drop randomly and may be empty") .. "|"
  1623     txt = txt .. loc("Flags: Unlimited Ammo, Shared Team Ammo|")
  1623     txt = txt .. loc("Modifiers: Unlimited ammo, shared clan ammo") .. "|"
  1624   end
  1624   end
  1625 
  1625 
  1626   if luck ~= 100 then
  1626   if luck ~= 100 then
  1627     txt = txt .. loc("Luck: ") .. luck .. loc("% (modifier for crates)|")
  1627     txt = txt .. string.format(loc("Luck: %d%% (modifier for crates)"), luck) .. "|"
  1628   end
  1628   end
  1629 
  1629 
  1630   if strength > 1 then
  1630   if strength > 1 then
  1631     txt = txt .. loc("Strength: ") .. strength .. loc(" (multiplier for ammo)|")
  1631     txt = txt .. string.format(loc("Strength: %d (multiplier for ammo)"), strength) .. "|"
  1632   end
  1632   end
  1633 
  1633 
  1634   if mode == 'highland' then
  1634   if mode == 'highland' then
  1635     txt = txt .. loc(" |")
  1635     txt = txt .. " |"
  1636     txt = txt .. loc("--- Highland --- |")
  1636     txt = txt .. loc("--- Highland ---").."|"
  1637     txt = txt .. loc("Enemy kills: Collect victims weapons and + ") .. highEnemyKillHPBonus .. loc(" % of its base health|")
  1637     txt = txt .. string.format(loc("Enemy kills: Collect victim's weapons and +%d%% of its base health"), highEnemyKillHPBonus).."|"
  1638     txt = txt .. loc("Friendly kills: Clears killers pool and - ") .. highFriendlyKillHPBonus .. loc(" % of its base health|")
  1638     txt = txt .. string.format(loc("Friendly kills: Clear killer's pool and -%d%% of its base health"), highFriendlyKillHPBonus).."|"
  1639     txt = txt .. loc("Turns: Hogs get ") .. highPickupCount .. loc(" random weapon(s) from their pool|")
  1639     txt = txt .. string.format(loc("Turns: Hogs get %d random weapon(s) from their pool"), highPickupCount).."|"
  1640     txt = txt .. loc("Hint: Kills wont transfer a hogs pool to the killers pool|")
  1640     txt = txt .. loc("Hint: Kills won't transfer a hog's pool to the killer's pool").."|"
  1641     txt = txt .. loc("Specials: Kings and Air-General drop helpers, not weapons|")
  1641     txt = txt .. loc("Specials: Kings and air generals drop helpers, not weapons").."|"
  1642     icon = 1 -- Target
  1642     icon = 1 -- Target
  1643   elseif mode == 'king' then
  1643   elseif mode == 'king' then
  1644     txt = txt .. loc(" |")
  1644     txt = txt .. " |"
  1645     txt = txt .. loc("--- King --- |")
  1645     txt = txt .. loc("--- King ---").."|"
  1646     txt = txt .. loc("Variants: The last hog of each team will be a king|")
  1646     txt = txt .. loc("Variants: The last hog of each team will be a king").."|"
  1647     txt = txt .. loc("Turns: Kings health are set to ") .. kingLinkPerc .. loc("% of the team health|")
  1647     txt = txt .. string.format(loc("Turns: King's health is set to %d%% of the team health"), kingLinkPerc).."|"
  1648     icon = 0 -- Golen Crown
  1648     icon = 0 -- Golen Crown
  1649   elseif mode == 'points' then
  1649   elseif mode == 'points' then
  1650     txt = txt .. loc(" |")
  1650     txt = txt .. " |"
  1651     txt = txt .. loc("--- Points --- |")
  1651     txt = txt .. loc("--- Points ---").."|"
  1652     txt = txt .. loc("Variants: Disables King and Air-General|")
  1652     txt = txt .. loc("Variants: King and air general are disabled").."|"
  1653     txt = txt .. loc("Weapons: Every team starts with ") .. pointsWepBase .. loc(" weapon points|")
  1653     txt = txt .. string.format(loc("Weapons: Each team starts with %d weapon points"), pointsWepBase).."|"
  1654     txt = txt .. loc("Helpers: Every team starts with ") .. pointsHlpBase .. loc(" helper points|")
  1654     txt = txt .. string.format(loc("Helpers: Each team starts with %d helper points"), pointsHlpBase).."|"
  1655     txt = txt .. loc("Turns: Refills ") .. pointsWepTurn .. loc(" weapon and ") .. pointsHlpTurn .. loc(" helper points|")
  1655     txt = txt .. string.format(loc("Turns: Refill %d weapon and %d helper points|and randomize weapons and helpers based on team points"), pointsWepTurn, pointsHlpTurn).."|"
  1656     txt = txt .. loc(" and randomizes weapons and helpers based on team points|")
       
  1657     icon = 4 -- Golden Star
  1656     icon = 4 -- Golden Star
  1658   else
  1657   else
  1659     icon = -amGrenade -- Grenade
  1658     icon = -amGrenade -- Grenade
  1660   end
  1659   end
  1661 
  1660 
  1662   --txt = txt .. "Switch: Max. 3 times a game per team, cooldown of 5 turns|"
  1661   --txt = txt .. "Switch: Max. 3 times a game per team, cooldown of 5 turns|"
  1663   txt = txt .. loc(" |")
  1662   txt = txt .. " |"
  1664   txt = txt .. loc("--- Sudden Death --- |")
  1663   txt = txt .. loc("--- Sudden Death ---").."|"
  1665   txt = txt .. loc("Weapons: +Kamikaze, +1 for nearly every hog variant|")
  1664   txt = txt .. loc("Weapons: Nearly every hog variant gets 1 kamikaze").."|"
  1666   txt = txt .. loc("Crates: Crates spawn more frequently with higher chance of bonus|")
  1665   txt = txt .. loc("Crates: Crates drop more often with a higher chance of bonus ammo").."|"
  1667   txt = txt .. loc("Water: Rises by 37 per Round|")
  1666   txt = txt .. loc("Water: Rises by 37 per turn").."|"
  1668   txt = txt .. loc("Hogs: Loose up to 7% base hp per turn|")
  1667   txt = txt .. loc("Health: Hogs lose up to 7% base health per turn").."|"
  1669 
  1668 
  1670   if mode == 'default' then
  1669   if mode == 'default' then
  1671     txt = txt .. loc(' |')
  1670     txt = txt .. " |"
  1672     txt = txt .. loc('--- Hint ---|')
  1671     txt = txt .. loc("--- Hint ---").."|"
  1673     txt = txt .. loc('Modes: Activate highland, king or points mode by putting mode=<name>|')
  1672     txt = txt .. loc("Modes: Activate “highland”, “king” or “points” mode by putting mode=<name>|into the script parameter").."|"
  1674     txt = txt .. loc(' into the script params|')
       
  1675   end
  1673   end
  1676 
  1674 
  1677   if mode == 'highland' then
  1675   if mode == 'highland' then
  1678     txt = txt .. loc("Highland: Hogs get ") .. highPickupSDCount .. loc(" random weapons from their pool|")
  1676     txt = txt .. string.format(loc("Highland: Hogs get %d random weapons from their pool"), highPickupSDCount) .. "|"
  1679   end
  1677   end
  1680 
  1678 
  1681   ShowMission(loc("Battalion v") .. version, loc("Less tools, more fun.") .. " (by Anachron)", txt, icon, 1000)
  1679   ShowMission(loc("Battalion"), loc("Less tools, more fun"), txt, icon, 1000)
  1682 
  1680 
  1683   -- Tell the user about the amount of rounds until sudden death
  1681   -- Tell the user about the amount of rounds until sudden death
  1684   AddCaption(loc("SuddenDeathTurns set to ") .. (SuddenDeathTurns +2), 0x808080,  capgrpGameState)
  1682   AddCaption(string.format(loc("Rounds until Sudden Death: %d"), SuddenDeathTurns +2), 0xFFFFFFFF, capgrpGameState)
  1685 end
  1683 end
  1686 
  1684 
  1687 function onGameInit()
  1685 function onGameInit()
  1688   --[[ CONFIGURATEABLE FOR PLAYERS ]]--
  1686   --[[ CONFIGURATEABLE FOR PLAYERS ]]--
  1689   --[[ ONCE IT HAS BEEN ADDED TO HW ]]--
  1687   --[[ ONCE IT HAS BEEN ADDED TO HW ]]--