share/hedgewars/Data/Scripts/Multiplayer/Battalion.lua
changeset 12980 263d006c56a9
parent 12979 b6d67e975b51
child 12981 4c7472d3d483
equal deleted inserted replaced
12979:b6d67e975b51 12980:263d006c56a9
    13   ########################################################################
    13   ########################################################################
    14 ]]--
    14 ]]--
    15 
    15 
    16 --[[
    16 --[[
    17   ########################################################################
    17   ########################################################################
    18   Todo/Idea-List
    18   TODO / ideas list
    19   ########################################################################
    19   ########################################################################
    20 
    20 
    21   - Make Hogs sorted by rareness for teams with less hogs (more fair)
    21   - Make Hogs sorted by rareness for teams with less hogs (more fair)
    22   - Keep first picked up unused crate utitlity until next round
    22   - Keep first picked up unused crate utitlity until next round
    23   - Ship default scheme but let user overwrite it
    23   - Ship default scheme but let user overwrite it
    40 
    40 
    41 -- List of all hog variants with belonging weapons,
    41 -- List of all hog variants with belonging weapons,
    42 --  hitpoints, chances and more
    42 --  hitpoints, chances and more
    43 local variants = {}
    43 local variants = {}
    44 local varName = ""
    44 local varName = ""
    45 local newLine = ""--string.char(0x0A)
    45 local newLine = ""
    46 local gmAny = 0xFFFFFFFF
    46 local gmAny = 0xFFFFFFFF
    47 local version = "0.33"
       
    48 
    47 
    49 --[[
    48 --[[
    50   ##############################################################################
    49   ##############################################################################
    51   ### VARIANT SETUP                                                          ###
    50   ### VARIANT SETUP                                                          ###
    52   ##############################################################################
    51   ##############################################################################
   430   end
   429   end
   431 end
   430 end
   432 
   431 
   433 function AddHogAmmo(hog, ammo)
   432 function AddHogAmmo(hog, ammo)
   434   -- Add weapons of variant
   433   -- Add weapons of variant
   435   --for key, val in pairs(variants[var]["weapons"]) do
       
   436   for key, val in pairs(ammo) do
   434   for key, val in pairs(ammo) do
   437     --AddAmmo(hog, val, 1)
       
   438     AddAmmo(hog, val, GetAmmoCount(hog, val) +1)
   435     AddAmmo(hog, val, GetAmmoCount(hog, val) +1)
   439   end
   436   end
   440 end
   437 end
   441 
   438 
   442 function GetRandomAmmo(hog, sourceType)
   439 function GetRandomAmmo(hog, sourceType)
   736   SetHealth(hog, variants[hogVar]["hp"])
   733   SetHealth(hog, variants[hogVar]["hp"])
   737 end
   734 end
   738 
   735 
   739 function getHogInfo(hog, info)
   736 function getHogInfo(hog, info)
   740   if hog == nil then
   737   if hog == nil then
   741     WriteLnToChat("ERROR [getHogInfo]: Hog is nil!")
   738     WriteLnToChat("ERROR [getHogInfo]: hog is nil!")
   742     WriteLnToConsole("ERROR [getHogInfo]: Hog is nil!")
   739     WriteLnToConsole("ERROR [getHogInfo]: hog is nil!")
   743     return
   740     return
   744   end
   741   end
   745 
   742 
   746   if hogInfo[hog] == nil then
   743   if hogInfo[hog] == nil then
   747     return nil
   744     return nil
   750   return hogInfo[hog][info]
   747   return hogInfo[hog][info]
   751 end
   748 end
   752 
   749 
   753 function setHogInfo(hog)
   750 function setHogInfo(hog)
   754   if hog == nil then
   751   if hog == nil then
   755     WriteLnToChat("ERROR [getHogInfo]: Hog is nil!")
   752     WriteLnToChat("ERROR [setHogInfo]: hog is nil!")
   756     WriteLnToConsole("ERROR [getHogInfo]: Hog is nil!")
   753     WriteLnToConsole("ERROR [setHogInfo]: hog is nil!")
   757     return
   754     return
   758   end
   755   end
   759 
   756 
   760   hogInfo[hog] = {}
   757   hogInfo[hog] = {}
   761   hogInfo[hog]['maxHp'] = GetHealth(hog)
   758   hogInfo[hog]['maxHp'] = GetHealth(hog)
  1011   if gearType == gtHedgehog then
  1008   if gearType == gtHedgehog then
  1012     trackGear(gear)
  1009     trackGear(gear)
  1013   elseif gearType == gtRCPlane then
  1010   elseif gearType == gtRCPlane then
  1014     SetHealth(gear, 2)
  1011     SetHealth(gear, 2)
  1015   elseif gearType == gtAirBomb then
  1012   elseif gearType == gtAirBomb then
  1016     -- gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, ImpactSounds, Tint, Damage, Boom
  1013     -- Set Boom
  1017     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 20)
  1014     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 20)
  1018   elseif gearType == gtCake then
  1015   elseif gearType == gtCake then
  1019     -- gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, ImpactSounds, Tint, Damage, Boom
  1016     -- Set Boom
  1020     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 50)
  1017     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 50)
  1021   elseif gearType == gtDEagleShot then
  1018   elseif gearType == gtDEagleShot then
  1022     -- gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, ImpactSounds, Tint, Damage, Boom
  1019     -- Set Boom
  1023     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 12)
  1020     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 12)
  1024   end
  1021   end
  1025 end
  1022 end
  1026 
  1023 
  1027 function onHighlandKill(gear)
  1024 function onHighlandKill(gear)
  1124     hpDiff = div(deathMaxHP * highEnemyKillHPBonus, 100)
  1121     hpDiff = div(deathMaxHP * highEnemyKillHPBonus, 100)
  1125     newHP = curHP + hpDiff
  1122     newHP = curHP + hpDiff
  1126     SetHealth(CurHog, newHP)
  1123     SetHealth(CurHog, newHP)
  1127 
  1124 
  1128     local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) - cratePickupGap, vgtHealthTag, hpDiff, false)
  1125     local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) - cratePickupGap, vgtHealthTag, hpDiff, false)
  1129     -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
  1126     -- Set Tint
  1130     SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(CurHog)))
  1127     SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(CurHog)))
  1131   -- Friendly fire! Remove all weapons and helpers from pool
  1128   -- Friendly fire! Remove all weapons and helpers from pool
  1132   else
  1129   else
  1133     highWeapons[CurHog] = {}
  1130     highWeapons[CurHog] = {}
  1134     highHelpers[CurHog] = {}
  1131     highHelpers[CurHog] = {}
  1140     else
  1137     else
  1141       SetHealth(CurHog, 0)
  1138       SetHealth(CurHog, 0)
  1142     end
  1139     end
  1143 
  1140 
  1144     local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) - cratePickupGap, vgtHealthTag, hpDiff, false)
  1141     local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) - cratePickupGap, vgtHealthTag, hpDiff, false)
  1145     -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
  1142     -- Set Tint
  1146     SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(CurHog)))
  1143     SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(CurHog)))
  1147   end
  1144   end
  1148 end
  1145 end
  1149 
  1146 
  1150 function onKingDeath(KingHog)
  1147 function onKingDeath(KingHog)
  1193 
  1190 
  1194   pointsPerTeam[team]['weapons'] = pointsPerTeam[team]['weapons'] + 2
  1191   pointsPerTeam[team]['weapons'] = pointsPerTeam[team]['weapons'] + 2
  1195   pointsPerTeam[team]['helpers'] = pointsPerTeam[team]['helpers'] + 1
  1192   pointsPerTeam[team]['helpers'] = pointsPerTeam[team]['helpers'] + 1
  1196 
  1193 
  1197   local effect = AddVisualGear(GetX(CurHog) - (cratePickupGap / 2), GetY(CurHog), vgtHealthTag, 2, false)
  1194   local effect = AddVisualGear(GetX(CurHog) - (cratePickupGap / 2), GetY(CurHog), vgtHealthTag, 2, false)
  1198   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
  1195   -- Set Tint
  1199   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xFFFFFFFF)
  1196   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xFFFFFFFF)
  1200 
  1197 
  1201   local effect = AddVisualGear(GetX(CurHog) + (cratePickupGap / 2), GetY(CurHog), vgtHealthTag, 1, false)
  1198   local effect = AddVisualGear(GetX(CurHog) + (cratePickupGap / 2), GetY(CurHog), vgtHealthTag, 1, false)
  1202   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
  1199   -- Set Tint
  1203   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0x444444FF)
  1200   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0x444444FF)
  1204 end
  1201 end
  1205 
  1202 
  1206 function onGearDelete(gear)
  1203 function onGearDelete(gear)
  1207   trackDeletion(gear)
  1204   trackDeletion(gear)
  1276     end
  1273     end
  1277 
  1274 
  1278     if hp ~= newHP then
  1275     if hp ~= newHP then
  1279       SetHealth(hog, newHP)
  1276       SetHealth(hog, newHP)
  1280       local effect = AddVisualGear(GetX(hog), GetY(hog) - cratePickupGap, vgtHealthTag, diff, false)
  1277       local effect = AddVisualGear(GetX(hog), GetY(hog) - cratePickupGap, vgtHealthTag, diff, false)
  1281       -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
  1278       -- Set Tint
  1282       SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(hog)))
  1279       SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(hog)))
  1283     end
  1280     end
  1284   end
  1281   end
  1285 end
  1282 end
  1286 
  1283 
  1357     pointsPerTeam[team]['weapons'] = pointsPerTeam[team]['weaponsRem'] + wepWoTax + div(wepToTax * pointsKeepSDPerc, 100)
  1354     pointsPerTeam[team]['weapons'] = pointsPerTeam[team]['weaponsRem'] + wepWoTax + div(wepToTax * pointsKeepSDPerc, 100)
  1358     pointsPerTeam[team]['helpers'] = pointsPerTeam[team]['helpersRem'] + hlpWoTax + div(hlpToTax * pointsKeepSDPerc, 100)
  1355     pointsPerTeam[team]['helpers'] = pointsPerTeam[team]['helpersRem'] + hlpWoTax + div(hlpToTax * pointsKeepSDPerc, 100)
  1359   end
  1356   end
  1360 
  1357 
  1361   local effect = AddVisualGear(GetX(hog) - (cratePickupGap / 2), GetY(hog), vgtHealthTag, pointsPerTeam[team]['weapons'], false)
  1358   local effect = AddVisualGear(GetX(hog) - (cratePickupGap / 2), GetY(hog), vgtHealthTag, pointsPerTeam[team]['weapons'], false)
  1362   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
  1359   -- Set Tint
  1363   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xFFFFFFFF)
  1360   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xFFFFFFFF)
  1364 
  1361 
  1365   local effect = AddVisualGear(GetX(hog) + (cratePickupGap / 2), GetY(hog), vgtHealthTag, pointsPerTeam[team]['helpers'], false)
  1362   local effect = AddVisualGear(GetX(hog) + (cratePickupGap / 2), GetY(hog), vgtHealthTag, pointsPerTeam[team]['helpers'], false)
  1366   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
  1363   -- Set Tint
  1367   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0x444444FF)
  1364   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0x444444FF)
  1368 end
  1365 end
  1369 
  1366 
  1370 function onPointsTurn()
  1367 function onPointsTurn()
  1371   local hogWepPoints = 0
  1368   local hogWepPoints = 0
  1547 
  1544 
  1548     -- Shuffle group for more randomness
  1545     -- Shuffle group for more randomness
  1549     shuffle(group['all'])
  1546     shuffle(group['all'])
  1550   -- We are in points mode, setup other weapons
  1547   -- We are in points mode, setup other weapons
  1551   elseif mode == 'points' then
  1548   elseif mode == 'points' then
  1552     --variants['King']['chance'] = 0
       
  1553     --if variants['Air General'] ~= nil then
       
  1554     --  variants['Air General']['chance'] = 0
       
  1555     --end
       
  1556 
       
  1557     -- Translate [ammo] -> points to [points] -> {ammo1, ammo2}
  1549     -- Translate [ammo] -> points to [points] -> {ammo1, ammo2}
  1558     for ammoType, ammoPoints in pairs(pointsWeaponVal) do
  1550     for ammoType, ammoPoints in pairs(pointsWeaponVal) do
  1559       if pointsToWep[ammoPoints] == nil then
  1551       if pointsToWep[ammoPoints] == nil then
  1560         pointsToWep[ammoPoints] = {}
  1552         pointsToWep[ammoPoints] = {}
  1561       end
  1553       end
  1579       table.insert(hlpPoints, points)
  1571       table.insert(hlpPoints, points)
  1580     end
  1572     end
  1581 
  1573 
  1582     table.sort(wepPoints)
  1574     table.sort(wepPoints)
  1583     table.sort(hlpPoints)
  1575     table.sort(hlpPoints)
  1584 
       
  1585     -- All done, sort the table
       
  1586     --table.sort(pointsToWep)
       
  1587     --table.sort(pointsToHlp)
       
  1588   end
  1576   end
  1589 
  1577 
  1590   -- Initial Hog Setup
  1578   -- Initial Hog Setup
  1591   runOnGears(countTeamHogs)
  1579   runOnGears(countTeamHogs)
  1592 
  1580 
  1656   elseif mode == 'king' then
  1644   elseif mode == 'king' then
  1657     txt = txt .. " |"
  1645     txt = txt .. " |"
  1658     txt = txt .. loc("--- King ---").."|"
  1646     txt = txt .. loc("--- King ---").."|"
  1659     txt = txt .. loc("Variants: The last hog of each team will be a king").."|"
  1647     txt = txt .. loc("Variants: The last hog of each team will be a king").."|"
  1660     txt = txt .. string.format(loc("Turns: King's health is set to %d%% of the team health"), kingLinkPerc).."|"
  1648     txt = txt .. string.format(loc("Turns: King's health is set to %d%% of the team health"), kingLinkPerc).."|"
  1661     icon = 0 -- Golen Crown
  1649     icon = 0 -- Golden Crown
  1662   elseif mode == 'points' then
  1650   elseif mode == 'points' then
  1663     txt = txt .. " |"
  1651     txt = txt .. " |"
  1664     txt = txt .. loc("--- Points ---").."|"
  1652     txt = txt .. loc("--- Points ---").."|"
  1665     txt = txt .. loc("Variants: Kings and air generals are disabled").."|"
  1653     txt = txt .. loc("Variants: Kings and air generals are disabled").."|"
  1666     txt = txt .. string.format(loc("Weapons: Each team starts with %d weapon points"), pointsWepBase).."|"
  1654     txt = txt .. string.format(loc("Weapons: Each team starts with %d weapon points"), pointsWepBase).."|"
  1669     icon = 4 -- Golden Star
  1657     icon = 4 -- Golden Star
  1670   else
  1658   else
  1671     icon = -amGrenade -- Grenade
  1659     icon = -amGrenade -- Grenade
  1672   end
  1660   end
  1673 
  1661 
  1674   --txt = txt .. "Switch: Max. 3 times a game per team, cooldown of 5 turns|"
       
  1675   txt = txt .. " |"
  1662   txt = txt .. " |"
  1676   txt = txt .. loc("--- Sudden Death ---").."|"
  1663   txt = txt .. loc("--- Sudden Death ---").."|"
  1677   txt = txt .. loc("Weapons: Nearly every hog variant gets 1 kamikaze").."|"
  1664   txt = txt .. loc("Weapons: Nearly every hog variant gets 1 kamikaze").."|"
  1678   txt = txt .. loc("Crates: Crates drop more often with a higher chance of bonus ammo").."|"
  1665   txt = txt .. loc("Crates: Crates drop more often with a higher chance of bonus ammo").."|"
  1679   txt = txt .. loc("Water: Rises by 37 per turn").."|"
  1666   txt = txt .. loc("Water: Rises by 37 per turn").."|"