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

« back to all changes in this revision

Viewing changes to share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.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
 
--------------------------------
 
1
---------------------------------------
 
2
-- CAPTURE_THE_FLAG GAMEPLAY MODE 0.5
2
3
-- by mikade
3
 
--------------------------------
 
4
---------------------------------------
4
5
 
5
6
-- Version History
6
7
---------
50
50
-- added a check to make sure the player doesn't kamikaze straight down and make the flag's starting point underwater
51
51
-- added a check to make sure the player drops the flag if he has it and he uses kamikaze
52
52
 
 
53
--------
 
54
-- 0.4
 
55
--------
 
56
 
 
57
-- remove user-branding and version numbers
 
58
-- removed some stuff that wasn't needed
 
59
-- fix piano strike exploit
 
60
-- changed delay to allow for better portals
 
61
-- changed starting feedback a little
 
62
-- increased the radius around the circle indicating the flag thief so that it doesn't obscure his health
 
63
 
 
64
--------
 
65
-- 0.5
 
66
--------
 
67
 
 
68
-- add support for more players
 
69
-- allow limited sudden death
 
70
-- stop TimeBox ruining my life
 
71
-- profit???
 
72
 
53
73
-----------------
54
74
--SCRIPT BEGINS
55
75
-----------------
64
84
------------------ "Oh well, they probably have the memory"
65
85
 
66
86
local gameStarted = false
67
 
local gameTurns = 0     
 
87
local gameTurns = 0
68
88
 
69
89
--------------------------
70
90
-- hog and team tracking variales
122
142
 
123
143
        if fCaptures[teamID] == 3 then
124
144
                for i = 0, (numhhs-1) do
125
 
                        if hhs[i] ~= nil then                   
 
145
                        if hhs[i] ~= nil then
126
146
                                if GetHogClan(hhs[i]) == alt then
127
147
                                        SetEffect(hhs[i], heResurrectable, false)
128
148
                                        SetHealth(hhs[i],0)
129
149
                                end
130
150
                        end
131
151
                end
132
 
                if CurrentHedgehog ~= nil then          
 
152
                if CurrentHedgehog ~= nil then
133
153
                        ShowMission(loc("GAME OVER!"), loc("Victory for the ") .. GetHogTeamName(CurrentHedgehog), loc("Hooray!"), 0, 0)
134
154
                end
135
155
        end
145
165
                wtf = 1
146
166
                bbq = 0
147
167
        end
148
 
        
 
168
 
149
169
        -- player has successfully captured the enemy flag
150
170
        if (GetHogClan(CurrentHedgehog) == wtf) and (CurrentHedgehog == fThief[bbq]) and (fIsMissing[wtf] == false) then
151
 
                
 
171
 
152
172
                DeleteVisualGear(fGear[wtf])
153
 
                fGear[wtf] = nil -- the flag has now disappeared                                
154
 
                                
 
173
                fGear[wtf] = nil -- the flag has now disappeared
 
174
 
155
175
                fIsMissing[wtf] = false
156
176
                fNeedsRespawn[wtf] = true
157
177
                fIsMissing[bbq] = false
158
178
                fNeedsRespawn[bbq] = true
159
 
                fCaptures[wtf] = fCaptures[wtf] +1                              
 
179
                fCaptures[wtf] = fCaptures[wtf] +1
160
180
                ShowMission(loc("You have SCORED!!"), GetHogTeamName(CurrentHedgehog) .. ": " .. fCaptures[wtf], loc("Opposing Team: ") .. fCaptures[bbq], 0, 0)
161
181
                PlaySound(sndVictory)
162
182
                fThief[bbq] = nil -- player no longer has the enemy flag
164
184
 
165
185
        --if the player is returning the flag
166
186
        elseif (GetHogClan(CurrentHedgehog) == wtf) and (fIsMissing[wtf] == true) then
167
 
                        
 
187
 
168
188
                DeleteVisualGear(fGear[wtf])
169
189
                fGear[wtf] = nil -- the flag has now disappeared
170
 
                                        
171
 
                fNeedsRespawn[wtf] = true                                       
 
190
 
 
191
                fNeedsRespawn[wtf] = true
172
192
                HandleRespawns() -- this will set fIsMissing[wtf] to false :)
173
193
                AddCaption(loc("Flag returned!"))
174
 
        
 
194
 
175
195
        --if the player is taking the enemy flag
176
196
        elseif GetHogClan(CurrentHedgehog) == bbq then
177
 
                                
 
197
 
178
198
                DeleteVisualGear(fGear[wtf])
179
 
                fGear[wtf] = nil -- the flag has now disappeared                                
180
 
                                
 
199
                fGear[wtf] = nil -- the flag has now disappeared
 
200
 
181
201
                fIsMissing[wtf] = true
182
202
                for i = 0,numhhs-1 do
183
 
                        if CurrentHedgehog ~= nil then                  
 
203
                        if CurrentHedgehog ~= nil then
184
204
                                if CurrentHedgehog == hhs[i] then
185
205
                                        fThief[wtf] = hhs[i]
186
206
                                end
188
208
                end
189
209
                AddCaption(loc("Flag captured!"))
190
210
 
191
 
        --below line doesnt usually get called
192
 
        --else 
193
 
                -- now gets called if you go over your own flag, presumably             
194
 
                --AddCaption("Hmm... that wasn't supposed to happen...")
195
211
        end
196
 
        
 
212
 
197
213
end
198
214
 
199
 
function CheckFlagProximity() 
 
215
function CheckFlagProximity()
200
216
 
201
217
        for i = 0, 1 do
202
218
                if fGear[i] ~= nil then
203
 
                        
 
219
 
204
220
                        g1X = fGearX[i]
205
 
                        g1Y = fGearY[i]                 
206
 
        
 
221
                        g1Y = fGearY[i]
 
222
 
207
223
                        g2X, g2Y = GetGearPosition(CurrentHedgehog)
208
224
 
209
225
                        q = g1X - g2X
210
226
                        w = g1Y - g2Y
211
227
                        dist = (q*q) + (w*w)
212
 
                        
 
228
 
213
229
                        if dist < 500 then --1600
214
230
                                DoFlagStuff(fGear[i])
215
231
                        end
226
242
                if fNeedsRespawn[i] == true then
227
243
                        fGear[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
228
244
                        fGearX[i] = fSpawnX[i]
229
 
                        fGearY[i] = fSpawnY[i]                  
230
 
                        --fGear[i] = SpawnAmmoCrate(fSpawnX[i],fSpawnY[i],amSkip)
 
245
                        fGearY[i] = fSpawnY[i]
 
246
 
231
247
                        fNeedsRespawn[i] = false
232
248
                        fIsMissing[i] = false -- new, this should solve problems of a respawned flag being "returned" when a player tries to score
233
249
                        AddCaption(loc("Flag respawned!"))
249
265
        end
250
266
 
251
267
        if fThief[wtf] ~= nil then
252
 
                -- falls into water             
253
 
                --ShowMission(LAND_HEIGHT,  fThiefY[wtf], (LAND_HEIGHT - fThiefY[wtf]), 0, 0)   
 
268
                -- falls into water
 
269
                --ShowMission(LAND_HEIGHT,  fThiefY[wtf], (LAND_HEIGHT - fThiefY[wtf]), 0, 0)
254
270
                if (LAND_HEIGHT - fThiefY[wtf]) < 15 then
255
271
                        fIsMissing[wtf] = true
256
272
                        fNeedsRespawn[wtf] = true
257
273
                        HandleRespawns()
258
 
                        --AddCaption("hah??")
259
 
                else    --normally      
 
274
                else    --normally
260
275
                        fGearX[wtf]  =  fThiefX[wtf]
261
 
                        fGearY[wtf]  =  fThiefY[wtf]    
262
 
                        fGear[wtf] = AddVisualGear(fGearX[wtf],fGearY[wtf],vgtCircle,0,true)            
263
 
                        --fGear[wtf] = AddVisualGear(fThiefX[wtf],fThiefY[wtf],vgtCircle,0,true)
 
276
                        fGearY[wtf]  =  fThiefY[wtf]
 
277
                        fGear[wtf] = AddVisualGear(fGearX[wtf],fGearY[wtf],vgtCircle,0,true)
264
278
                end
265
279
 
266
280
                AddVisualGear(fThiefX[wtf], fThiefY[wtf], vgtBigExplosion, 0, false)
276
290
                fGearTimer = 0
277
291
                fGearRad = fGearRad + 1
278
292
                if fGearRad > fGearRadMax then
279
 
                        fGearRad = fGearRadMin  
 
293
                        fGearRad = fGearRadMin
280
294
                end
281
295
        end
282
296
 
283
297
        for i = 0, 1 do
284
 
                
 
298
 
285
299
                --SetVisualGearValues(fSpawnC[i], fSpawnX[i],fSpawnY[i], 20, 200, 0, 0, 100, 50, 3, fCol[i]) -- draw a circ for spawning area
286
 
                
 
300
 
287
301
                if fIsMissing[i] == false then -- draw a flag marker at the flag's spawning place
288
302
                        SetVisualGearValues(fCirc[i], fSpawnX[i],fSpawnY[i], 20, 20, 0, 10, 0, 33, 3, fCol[i])
289
303
                        if fGear[i] ~= nil then -- draw the flag gear itself
290
304
                                SetVisualGearValues(fGear[i], fSpawnX[i],fSpawnY[i], 20, 200, 0, 0, 100, fGearRad, 2, fCol[i])
291
305
                        end
292
306
                elseif (fIsMissing[i] == true) and (fNeedsRespawn[i] == false) then
293
 
                        if fThief[i] ~= nil then -- draw circle round flag carrier
294
 
                                SetVisualGearValues(fCirc[i], fThiefX[i], fThiefY[i], 20, 200, 0, 0, 100, 33, 3, fCol[i])
 
307
                        if fThief[i] ~= nil then -- draw circle round flag carrier                      -- 33
 
308
                                SetVisualGearValues(fCirc[i], fThiefX[i], fThiefY[i], 20, 200, 0, 0, 100, 50, 3, fCol[i])
295
309
                                --AddCaption("circle marking carrier")
296
310
                        elseif fThief[i] == nil then -- draw cirle round dropped flag
297
 
                                --g1X,g1Y,g4,g5,g6,g7,g8,g9,g10,g11 =  GetVisualGearValues(fGear[i])                            
 
311
                                --g1X,g1Y,g4,g5,g6,g7,g8,g9,g10,g11 =  GetVisualGearValues(fGear[i])
298
312
                                --SetVisualGearValues(fCirc[i], g1X, g1Y, 20, 200, 0, 0, 100, 33, 2, fCol[i])
299
313
                                SetVisualGearValues(fCirc[i], fGearX[i], fGearY[i], 20, 200, 0, 0, 100, 33, 3, fCol[i])
300
 
                                --AddCaption('dropped circle marker')                           
 
314
                                --AddCaption('dropped circle marker')
301
315
                                if fGear[i] ~= nil then -- flag gear itself
302
 
                                        --SetVisualGearValues(fGear[i], g1X, g1Y, 20, 200, 0, 0, 100, 10, 4, fCol[i])                                   
 
316
                                        --SetVisualGearValues(fGear[i], g1X, g1Y, 20, 200, 0, 0, 100, 10, 4, fCol[i])
303
317
                                        SetVisualGearValues(fGear[i], fGearX[i], fGearY[i], 20, 200, 0, 0, 100, fGearRad, 2, fCol[i])
304
318
                                        --AddCaption('dropped flag itself')
305
319
                                end
337
351
 
338
352
 
339
353
        -- make a list of individual team names
340
 
        for i = 0, 5 do
 
354
        for i = 0, (TeamsCount-1) do
341
355
                teamNameArr[i] = i
342
356
                teamSize[i] = 0
343
357
                teamIndex[i] = 0
396
410
 
397
411
        for i = 0, 1 do
398
412
 
399
 
                -- if someone uses kamikaze downwards, this can happen as the hog won't respawn         
 
413
                -- if someone uses kamikaze downwards, this can happen as the hog won't respawn
400
414
                if (LAND_HEIGHT - fSpawnY[i]) < 0 then
401
415
                        tempG = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
402
 
                        FindPlace(tempG, true, 0, LAND_WIDTH, true)                     
 
416
                        FindPlace(tempG, true, 0, LAND_WIDTH, true)
403
417
                        fSpawnX[i], fSpawnY[i] = GetGearPosition(tempG)
404
418
                        DeleteGear(tempG)
405
 
                end             
 
419
                end
406
420
 
407
421
                fGear[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
408
422
                fCirc[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
415
429
                fIsMissing[i] = false
416
430
                fNeedsRespawn[i] = false
417
431
                fCaptures[i] = 0
418
 
                
419
 
                --SetVisualGearValues(zxc, 1000,1000, 20, 100, 0,    10,                     1,         100,        5,      GetClanColor(0))            
420
 
                
 
432
 
 
433
                --SetVisualGearValues(zxc, 1000,1000, 20, 100, 0,    10,                     1,         100,        5,      GetClanColor(0))
 
434
 
421
435
                SetVisualGearValues(fSpawnC[i], fSpawnX[i],fSpawnY[i], 20, 100, 0, 10, 0, 75, 5, fCol[i])
422
 
                --SetVisualGearValues(fCirc[i], fSpawnX[i],fSpawnY[i], 20, 20, 0, 10, 0, 33, 3, fCol[i])
423
436
 
424
 
                                
425
437
        end
426
438
 
427
439
end
432
444
 
433
445
function onGameInit()
434
446
 
435
 
        -- Things we don't modify here will use their default values.
436
 
        
437
447
        GameFlags = band(bor(GameFlags, gfDivideTeams), bnot(gfKing + gfForts))
438
 
        SuddenDeathTurns = 99 -- suddendeath is off, effectively
439
 
        --TurnTime = 30000 -- (was 30) The time the player has to move each round (in ms)
440
 
        --Delay = 10 -- The delay between each round
 
448
        --SuddenDeathTurns = 999 -- suddendeath is off, effectively
 
449
        WaterRise = 0
 
450
        Delay = 10
441
451
 
442
452
end
443
453
 
445
455
function onGameStart()
446
456
 
447
457
        --ShowMission(loc(caption), loc(subcaption), loc(goal), 0, 0)
448
 
        ShowMission(loc("CAPTURE THE FLAG"), loc("by mikade"), loc("CUSTOM BUILD 0.2"), 0, 0)
 
458
        ShowMission(loc("CAPTURE THE FLAG"), loc("Flags, and their home base will be placed where each team ends their first turn."), "", 0, 0)
449
459
 
450
460
        RebuildTeamInfo()
451
 
        
452
 
        -- should gfDivideTeams do this automatically?  
 
461
 
 
462
        -- should gfDivideTeams do this automatically?
453
463
        --[[for i = 0, (TeamsCount-1) do
454
464
                for g = teamIndex[i], (teamIndex[i]+teamSize[i]-1) do
455
465
                        if GetHogClan(hhs[g]) == 0 then
465
475
 
466
476
        --zxc = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
467
477
 
468
 
        
 
478
 
469
479
        --SetVisualGearValues(zxc, 1000,1000, 20, 255, 1,    10,                     0,         200,        1,      GetClanColor(0))
470
480
                                        --minO,max0 -glowyornot --pulsate timer  -- fuckall      -- radius -- width  -- colour
471
481
end
474
484
function onNewTurn()
475
485
 
476
486
        gameTurns = gameTurns + 1
477
 
        
 
487
 
478
488
        if lastTeam ~= GetHogTeamName(CurrentHedgehog) then
479
489
                lastTeam = GetHogTeamName(CurrentHedgehog)
480
490
        end
482
492
        --AddCaption("Handling respawns")
483
493
        if gameStarted == true then
484
494
                HandleRespawns()
485
 
        --new method of placing starting flags  
 
495
        --new method of placing starting flags
486
496
        elseif gameTurns == 1 then
487
 
                ShowMission(loc("CAPTURE THE FLAG"), loc("Flags will be placed where each team ends their turn."), "", 0, 0)
 
497
                ShowMission(loc("CAPTURE THE FLAG"), loc("Flags, and their home base will be placed where each team ends their first turn."), "", 0, 0)
488
498
        elseif gameTurns == 2 then
489
499
                fPlaced[0] = true
490
500
                ShowMission(loc("CAPTURE THE FLAG"), loc("RULES OF THE GAME [Press ESC to view]"), loc(" - Return the enemy flag to your base to score | - First team to 3 captures wins | - You may only score when your flag is in your base | - Hogs will drop the flag if killed, or drowned | - Dropped flags may be returned or recaptured | - Hogs respawn when killed"), 0, 0)
491
501
        elseif gameTurns == 3 then
492
 
                fPlaced[1] = true       
 
502
                fPlaced[1] = true
493
503
                StartTheGame()
494
504
        end
495
505
 
525
535
                        CheckFlagProximity()
526
536
                end
527
537
        elseif CurrentHedgehog ~= nil then -- if the game hasn't started yet, keep track of where we are gonna put the flags on turn end
528
 
                                
 
538
 
529
539
                if GetHogClan(CurrentHedgehog) == 0 then
530
 
                        i = 0                   
 
540
                        i = 0
531
541
                elseif GetHogClan(CurrentHedgehog) == 1 then
532
 
                        i = 1                   
533
 
                end                     
534
 
                
 
542
                        i = 1
 
543
                end
 
544
 
535
545
                fSpawnX[i] = GetX(CurrentHedgehog)
536
546
                fSpawnY[i] = GetY(CurrentHedgehog)
537
 
                        
 
547
 
538
548
        end
539
549
 
540
550
end
562
572
 
563
573
end
564
574
 
565
 
function onGearDamage(gear, damage)
566
 
--
567
 
end
 
575
function InABetterPlaceNow(gear)
 
576
        for i = 0, (numhhs-1) do
 
577
                if gear == hhs[i] then
 
578
 
 
579
                        for i = 0,1 do
 
580
                                if gear == fThief[i] then
 
581
                                        FlagThiefDead(gear)
 
582
                                end
 
583
                        end
 
584
                        hhs[i] = nil
 
585
                end
 
586
        end
 
587
end
 
588
 
 
589
function onHogHide(gear)
 
590
         InABetterPlaceNow(gear)
 
591
end
 
592
 
 
593
function onHogRestore(gear)
 
594
        match = false
 
595
        for i = 0, (numhhs-1) do
 
596
                if (hhs[i] == nil) and (match == false) then
 
597
                        hhs[i] = gear
 
598
                        --AddCaption(GetHogName(gear) .. " has reappeared it seems!")
 
599
                        match = true
 
600
                end
 
601
        end
 
602
end
 
603
 
568
604
 
569
605
function onGearAdd(gear)
570
606
 
572
608
                hhs[numhhs] = gear
573
609
                numhhs = numhhs + 1
574
610
                SetEffect(gear, heResurrectable, true)
 
611
 
 
612
        elseif GetGearType(gear) == gtPiano then
 
613
 
 
614
                for i = 0, 1 do
 
615
                        if CurrentHedgehog == fThief[i] then
 
616
                                FlagThiefDead(gear)
 
617
                        end
 
618
                end
 
619
 
575
620
        end
576
621
 
577
622
end
579
624
function onGearDelete(gear)
580
625
 
581
626
        if GetGearType(gear) == gtHedgehog then
582
 
        --AddCaption("gear deleted!")
583
 
                for i = 0, (numhhs-1) do
584
 
                        if gear == hhs[i] then
585
 
                                
586
 
                                for i = 0,1 do
587
 
                                        if gear == fThief[i] then
588
 
                                                FlagThiefDead(gear)
589
 
                                        end
590
 
                                end                             
591
 
                                hhs[i] = nil
592
 
                                --AddCaption("for real")        
593
 
                        end             
594
 
                end
 
627
                InABetterPlaceNow(gear)
595
628
        end
596
629
 
597
630
end