All pastes #59275 Raw Edit

Someone

public text v1 · immutable
#59275 ·published 2006-05-27 23:51 UTC
rendered paste body

// maxcaptures.cpp : Defines the entry point for the DLL application.
//

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

BZ_GET_PLUGIN_VERSION

bool matchInProgress = false;
int maxcaptures = 0;

class MaxCaptures : public bz_EventHandler
{
public:
  virtual void  process ( bz_EventData *eventData )
  {
    if (eventData->eventType == bz_eGameEndEvent) matchInProgress = false;
    else if (eventData->eventType == bz_eGameStartEvent) matchInProgress = true;
    else if (eventData->eventType == bz_eCaptureEvent && matchInProgress) {
      bz_CTFCaptureEventData *ctfData = (bz_CTFCaptureEventData*) eventData;
      bz_PlayerRecord *player = bz_getPlayerByIndex(ctfData->playerCapping);
      if (!player) return;

      if (ctfData->teamCapping != player->team) bz_setTeamWins(ctfData->teamCapping, bz_getTeamWins(ctfData->teamCapping) + 1);
      bz_freePlayerRecord(player);
    }
    else if (eventData->eventType == bz_eCheckTeamScore && matchInProgress) {
      bz_CheckTeamScoreEventData *checkData = (bz_CheckTeamScoreEventData*) eventData;

      if (bz_getTeamWins(checkData->team) >= maxcaptures) checkData->gameover = true;
    }
  }
};

MaxCaptures     maxCaptures;

BZF_PLUGIN_CALL int bz_Load ( const char* commandLine )
{
  bz_debugMessage(4,"maxcaptures plugin loaded");

  std::istringstream command(commandLine);
  command >> maxcaptures;

  bz_registerEvent(bz_eGameEndEvent,&maxCaptures);
  bz_registerEvent(bz_eGameStartEvent,&maxCaptures);
  bz_registerEvent(bz_eCaptureEvent,&maxCaptures);
  bz_registerEvent(bz_eCheckTeamScore,&maxCaptures);
  return 0;
}

BZF_PLUGIN_CALL int bz_Unload ( void )
{
  bz_removeEvent(bz_eCheckTeamScore,&maxCaptures);
  bz_removeEvent(bz_eCaptureEvent,&maxCaptures);
  bz_removeEvent(bz_eGameStartEvent,&maxCaptures);
  bz_removeEvent(bz_eGameEndEvent,&maxCaptures);
  bz_debugMessage(4,"maxcaptures plugin unloaded");
  return 0;
}

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