~ubuntu-branches/ubuntu/wily/hedgewars/wily

« back to all changes in this revision

Viewing changes to share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-09-23 10:16:55 UTC
  • mfrom: (1.2.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110923101655-3977th2gc5n0a3pv
Tags: 0.9.16-1
* New upstream version.
 + Downloadable content! Simply click to install any content.
   New voices, hats, maps, themes, translations, music, scripts...
   Hedgewars is now more customisable than ever before! As time goes
   by we will be soliciting community content to feature on this page,
   so remember to check it from time to time. If you decide you want
   to go back to standard Hedgewars, just remove the Data directory
   from your Hedgewars config directory.
 + 3-D rendering! Diorama-like rendering of the game in a variety
   of 3D modes. Let us know which ones work best for you, we didn't
   really have the equipment to test them all.
 + Resizable game window.
 + New utilities! The Time Box will remove one of your hedgehogs
   from the game for a while, protecting from attack until it returns,
   somewhere else on the map. Land spray will allow you to build bridges,
   seal up holes, or just make life unpleasant for your enemies.
 + New single player: Bamboo Thicket, That Sinking Feeling, Newton and
   the Tree and multi-player: The Specialists, Space Invaders,
   Racer - scripts! And a ton more script hooks for scripters
 + New twists on old weapons. Drill strike, seduction and fire have
   been adjusted. Defective mines have been added, rope can attach to
   hogs/crates/barrels again, grenades now have variable bounce (use
   precise key + 1-5). Portal gun is now more usable in flight and
   all game actions are a lot faster.
 + New theme - Golf, dozens of new community hats and a new
   localised Default voice, Ukranian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- Random Weapons, example for gameplay scripts
 
2
 
 
3
-- Load the library for localisation ("loc" function)
1
4
loadfile(GetDataPath() .. "Scripts/Locale.lua")()
2
5
 
 
6
-- Load the gear tracker
 
7
loadfile(GetDataPath() .. "Scripts/Tracker.lua")()
 
8
 
 
9
-- List of available weapons
3
10
local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun,
4
11
            amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer,
5
12
            amBaseballBat, amTeleport, amMortar, amCake, amSeduction,
6
13
            amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane,
7
14
            amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb,
8
 
            amFlamethrower, amSMine, amHammer, amSnowball }
 
15
            amFlamethrower, amSMine, amHammer }
9
16
 
 
17
-- List of weapons that attack from the air
10
18
local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
11
19
 
 
20
-- Function that assigns the team their weapon
 
21
function assignAmmo(hog)
 
22
    -- Get name of the current team
 
23
    local name = GetHogTeamName(hog)
 
24
    -- Get whither the team has been processed
 
25
    local processed = getTeamValue(name, "processed")
 
26
    -- If it has not, process it
 
27
    if processed == nil or not processed then
 
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)
 
39
    end
 
40
end
 
41
 
 
42
-- Mark team as not processed
 
43
function reset(hog)
 
44
    setTeamValue(GetHogTeamName(hog), "processed", false)
 
45
end
12
46
 
13
47
function onGameInit()
14
 
    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo))
 
48
    -- Limit flags that can be set, but allow game schemes to be used
 
49
    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack))
 
50
    -- Set a custom game goal that will show together with the scheme ones
 
51
    Goals = loc("Each turn you get one random weapon")
15
52
end
16
53
 
17
54
function onGameStart()
 
55
    -- Initialize the tracking of hogs and teams
 
56
    trackTeams()
 
57
    -- Add air weapons to the game if the border is not active
18
58
    if MapHasBorder() == false then
19
59
        for i, w in pairs(airweapons) do
20
60
            table.insert(weapons, w)
21
61
        end
22
62
    end
23
 
 
24
 
    ShowMission(loc("Random Weapons"), loc("A game of luck"), loc("There has been a mix-up with your gear and now you|have to utilize whatever is coming your way!"), -amSkip, 0)
25
63
end
26
64
 
27
65
function onAmmoStoreInit()
 
66
    -- Allow skip at all times
28
67
    SetAmmo(amSkip, 9, 0, 0, 0)
29
68
 
 
69
    -- Let utilities be available through crates
30
70
    SetAmmo(amParachute, 0, 1, 0, 1)
31
71
    SetAmmo(amGirder, 0, 1, 0, 2)
32
72
    SetAmmo(amSwitch, 0, 1, 0, 1)
40
80
    SetAmmo(amPortalGun, 0, 1, 0, 1)
41
81
    SetAmmo(amResurrector, 0, 1, 0, 1)
42
82
 
 
83
    -- Allow weapons to be used
43
84
    for i, w in pairs(weapons) do
44
85
        SetAmmo(w, 0, 0, 0, 1)
45
86
    end
46
87
 
 
88
    -- Allow air weapons to be used
47
89
    for i, w in pairs(airweapons) do
48
90
        SetAmmo(w, 0, 0, 0, 1)
49
91
    end
50
92
end
51
93
 
52
94
function onNewTurn()
53
 
    AddAmmo(CurrentHedgehog, weapons[GetRandom(table.maxn(weapons)) + 1])
 
95
    -- Give every team their weapons, so one can plan during anothers turn
 
96
    runOnGears(assignAmmo)
 
97
    -- Mark all teams as not processed
 
98
    runOnGears(reset)
 
99
    -- Set the current teams weapons to nil so they will get new after the turn has ended
 
100
    setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
 
101
end
 
102
 
 
103
function onGearAdd(gear)
 
104
    -- Catch hedgehogs for the tracker
 
105
    if GetGearType(gear) == gtHedgehog then
 
106
        trackGear(gear)
 
107
    end
 
108
end
 
109
 
 
110
function onGearDelete(gear)
 
111
    -- Remove hogs that are gone
 
112
    trackDeletion(gear)
54
113
end