Beispiel #1
0
inline void KOTHEventHandler::process(bz_EventData * eventData)
{
  if (!koth.enabled)		// King of the Hill disabled - we can leave
    return;

  if (onePlayer())		// Not enough players - we can leave
    return;

  float pos[3] = { 0 };

  int playerID = -1;

  switch (eventData->eventType) {
  case bz_ePlayerUpdateEvent:
    pos[0] = ((bz_PlayerUpdateEventData_V1 *) eventData)->state.pos[0];
    pos[1] = ((bz_PlayerUpdateEventData_V1 *) eventData)->state.pos[1];
    pos[2] = ((bz_PlayerUpdateEventData_V1 *) eventData)->state.pos[2];
    playerID = ((bz_PlayerUpdateEventData_V1 *) eventData)->playerID;
    break;

  case bz_eShotFiredEvent:
    pos[0] = ((bz_ShotFiredEventData_V1 *) eventData)->pos[0];
    pos[1] = ((bz_ShotFiredEventData_V1 *) eventData)->pos[1];
    pos[2] = ((bz_ShotFiredEventData_V1 *) eventData)->pos[2];
    playerID = ((bz_ShotFiredEventData_V1 *) eventData)->playerID;
    break;

  default:
    return;
  }

  if (!koth.toldHillOpen && koth.id == -1)	// Hill is open - inform players
  {
    bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Hill is not controlled - take it!");
    koth.toldHillOpen = true;
  }

  if (kothzone.pointIn(pos))	// player is on Hill
  {
    bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerID);

    if (player) {
      if (player->playerID != koth.playerJustWon && player->spawned) {
	if ((koth.id == -1 && player->team != koth.team) || (koth.id == -1 && teamClear(koth.team)))
	  initiatekoth(player->team, player->callsign, player->playerID);

	double timeStanding = bz_getCurrentTime() - koth.startTime;

	if (timeStanding >= koth.adjustedTime && koth.id != -1)	// time's up - kill 'em
	{
	  if (koth.teamPlay && koth.team != eRogueTeam)
	    killTeams(koth.team, koth.callsign);
	  else
	    killPlayers(koth.id, koth.callsign);

	  if (!koth.teamPlay || koth.team == eRogueTeam)
	    bz_sendTextMessage(BZ_SERVER, koth.id, "You are King of the Hill!  You must leave hill to retake it.");
	  else
	    bz_sendTextMessage(BZ_SERVER, koth.team, "Your team is King of the Hill!  Entire team must leave hill to retake it.");

	  koth.playerJustWon = koth.id;

	  koth.id = -1;

	  return;
	}
	if (koth.id != -1)
	  sendWarnings(getTeamColor(koth.team), koth.callsign, koth.startTime);
      }
    }

    bz_freePlayerRecord(player);
  } else {			// player is off Hill
    if (playerID == koth.playerJustWon)
      koth.playerJustWon = -1;

    if (playerID == koth.id) {
      koth.id = -1;
      koth.team = eNoTeam;
    }
  }
}
Beispiel #2
0
void KeepAwayEventHandler::Event ( bz_EventData *eventData )
{
	if (eventData->eventType == bz_ePlayerDieEvent)
		KeepAwayPlayerDied(eventData);
	else if (eventData->eventType == bz_ePlayerPartEvent)
		KeepAwayPlayerLeft(eventData);
	else if (eventData->eventType == bz_ePlayerJoinEvent)
		KeepAwayPlayerJoined(eventData);
	else if (eventData->eventType == bz_ePlayerPausedEvent)
		KeepAwayPlayerPaused(eventData);

	if (eventData->eventType != bz_ePlayerUpdateEvent || !keepaway.enabled || keepaway.flagToKeep == "")
		return;

	if (keepaway.notEnoughTeams) // Not enough teams - we can leave
		return;

	checkKeepAwayHolder(); // check for someone holding flag

	if (!keepaway.toldFlagFree && keepaway.id == -1) // Flag is free - inform players
	{
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away flag: %s is free; find it and keep it!", convertFlag(keepaway.flagToKeep).c_str());
		keepaway.toldFlagFree = true;

		if ((bz_getCurrentTime() - keepaway.lastReminder) > 2 && keepaway.soundEnabled) // do not play free flag sound alert if player just won/lost (overlapping sounds)
			playAlert();
	}

	if (timeForReminder() && keepaway.id == -1)
		bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Keep Away flag: %s is free; find it and keep it!", convertFlag(keepaway.flagToKeep).c_str());

	if (keepaway.id == -1)  // no one has it, we can leave
		return;

	sendWarnings(getTeamColor(keepaway.team), keepaway.callsign, keepaway.startTime);

	double timeStanding = bz_getCurrentTime() - keepaway.startTime;

	if (timeStanding >= keepaway.adjustedTime) // time's up - kill 'em
	{
		if (keepaway.teamPlay && keepaway.team != eRogueTeam)
		{
			killTeams(keepaway.team, keepaway.callsign);
			bz_sendTextMessage (BZ_SERVER, keepaway.team, "Your team did it!  Go find the next Keep Away flag and keep it!");
		}
		else
		{
			killPlayers(keepaway.id, keepaway.callsign);
			bz_sendTextMessage (BZ_SERVER, keepaway.id, "You did it!  Go find the next Keep Away flag and keep it!");
		}

		if (!keepaway.forcedFlags)  // this will always create an open spot for getFlag(), if it's needed
			bz_removePlayerFlag (keepaway.id);

		keepaway.id = -1;
		keepaway.team = eNoTeam;
		keepaway.toldFlagFree = false;
		keepaway.flagToKeep = getFlag();
		keepaway.lastReminder = bz_getCurrentTime();

		return;
	}
}