File: RogueGenocide.cpp

package info (click to toggle)
bzflag 2.4.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,488 kB
  • sloc: cpp: 150,376; ansic: 3,463; sh: 2,535; makefile: 2,194; perl: 486; python: 260; objc: 246; php: 206
file content (95 lines) | stat: -rw-r--r-- 2,796 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// rogueGenocide.cpp : Defines the entry point for the DLL application.
//

#include "bzfsAPI.h"
#include <map>


// event handler callback
class RogueGenoHandler : public bz_Plugin
{
public:
    virtual const char* Name ()
    {
        return "Rogue Genocide";
    }
    virtual void Init (const char* config);

    virtual void Event (bz_EventData *eventData);

    bool allowSuicide;
};

BZ_PLUGIN(RogueGenoHandler)

void RogueGenoHandler::Init(const char* commandLine)
{
    Register(bz_ePlayerDieEvent);

    std::string param = commandLine;

    allowSuicide = (param == "suicide");
}

void RogueGenoHandler::Event (bz_EventData *eventData)
{
    switch (eventData->eventType)
    {
    default:
        // no clue
        break;

    // wait for a tank death and start checking for genocide and rogues
    case bz_ePlayerDieEvent:
    {
        bz_PlayerDieEventData_V1 *dieData = (bz_PlayerDieEventData_V1*)eventData;
        //if its not a genocide kill, dont care
        if (dieData->flagKilledWith != "G")
            break;
        // if the tank killed was not a rogue, let the server/client do the normal killing
        if (dieData->team != eRogueTeam)
            break;
        // option to disallow rogues getting points for shooting themselves
        if (!allowSuicide && dieData->killerID == dieData->playerID)
            break;

        // if the tank killed was a rogue, kill all rogues.
        bz_APIIntList *playerList = bz_newIntList();

        bz_getPlayerIndexList(playerList);

        for (unsigned int i = 0; i < playerList->size(); i++)
        {
            int targetID = (*playerList)[i];
            bz_BasePlayerRecord *playRec = bz_getPlayerByIndex (targetID);
            if (!playRec)
                continue;

            // the sucker is a spawned rogue, kill him.  This generates another death event,
            // so if you kill another rogue with geno while you are a rogue you end up dead too.
            // and you get both messages (victim and be careful)
            if (playRec->spawned && playRec->team == eRogueTeam)
            {
                bz_killPlayer(targetID, false, dieData->killerID, "G");
                bz_sendTextMessage(BZ_SERVER, targetID, "You were a victim of Rogue Genocide");

                // oops, I ended up killing myself (directly or indirectly) with Genocide!
                if (targetID == dieData->killerID)
                    bz_sendTextMessage(BZ_SERVER, targetID, "You should be more careful with Genocide!");
            }

            bz_freePlayerRecord(playRec);
        }
        bz_deleteIntList(playerList);
    }
    break;
    }
}

// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4