File: RogueGenocide.cpp

package info (click to toggle)
bzflag 2.4.2%2Bds1-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 28,016 kB
  • ctags: 18,545
  • sloc: cpp: 149,420; sh: 13,654; ansic: 3,831; makefile: 2,404; perl: 482; python: 260; objc: 251; php: 162; xml: 24
file content (91 lines) | stat: -rw-r--r-- 2,495 bytes parent folder | download
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
// 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 noSuicide;
};

BZ_PLUGIN(RogueGenoHandler)

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

  std::string param = commandLine;

  noSuicide = (param == "nosuicide");
}

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 ( noSuicide && 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: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8