share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua
changeset 5141 2fb6555011d3
parent 5138 f991f87969ff
child 5352 7f57d0c7816a
equal deleted inserted replaced
5140:932307228d05 5141:2fb6555011d3
    16 
    16 
    17 -- List of weapons that attack from the air
    17 -- List of weapons that attack from the air
    18 local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
    18 local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
    19 
    19 
    20 -- Function that assigns the team their weapon
    20 -- Function that assigns the team their weapon
    21 -- Due to the fact that the gameplay uses reset weapons and no inf attack there is no point in limiting the ammo count
    21 function assignAmmo(hog)
    22 function assignWeapon(hog)
    22     -- Get name of the current team
    23     -- Get the ammo for this hog's team
    23     local name = GetHogTeamName(hog)
    24     local ammo = getTeamValue(GetHogTeamName(hog), "ammo")
    24     -- Get whither the team has been processed
    25     -- If there is no ammo, get a random one from the list and store it
    25     local processed = getTeamValue(name, "processed")
    26     if ammo == nil then
    26     -- If it has not, process it
    27         ammo = weapons[GetRandom(table.maxn(weapons)) + 1]
    27     if processed == nil or not processed then
    28         setTeamValue(GetHogTeamName(hog), "ammo", ammo)
    28         -- Get the ammo for this hog's team
       
    29         local ammo = getTeamValue(name, "ammo")
       
    30         -- If there is no ammo, get a random one from the list and store it
       
    31         if ammo == nil then
       
    32             ammo = weapons[GetRandom(table.maxn(weapons)) + 1]
       
    33             setTeamValue(name, "ammo", ammo)
       
    34         end
       
    35         -- Add the ammo for the hog
       
    36         AddAmmo(hog, ammo)
       
    37         -- Mark as processed
       
    38         setTeamValue(name, "processed", true)
    29     end
    39     end
    30     -- Add the ammo for the hog
    40 end
    31     AddAmmo(hog, ammo)
    41 
       
    42 -- Mark team as not processed
       
    43 function reset(hog)
       
    44     setTeamValue(GetHogTeamName(hog), "processed", false)
    32 end
    45 end
    33 
    46 
    34 function onGameInit()
    47 function onGameInit()
    35     -- Limit flags that can be set, but allow game schemes to be used
    48     -- Limit flags that can be set, but allow game schemes to be used
    36     GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo))
    49     GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo))
    78     end
    91     end
    79 end
    92 end
    80 
    93 
    81 function onNewTurn()
    94 function onNewTurn()
    82     -- Give every team their weapons, so one can plan during anothers turn
    95     -- Give every team their weapons, so one can plan during anothers turn
    83     runOnGears(assignWeapon)
    96     runOnGears(assignAmmo)
       
    97     -- Mark all teams as not processed
       
    98     runOnGears(reset)
    84     -- Set the current teams weapons to nil so they will get new after the turn has ended
    99     -- Set the current teams weapons to nil so they will get new after the turn has ended
    85     setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
   100     setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
    86 end
   101 end
    87 
   102 
    88 function onGearAdd(gear)
   103 function onGearAdd(gear)