void RegFlag::Event ( bz_EventData *eventData ) { bz_BasePlayerRecord *player = NULL; int playerID = -1; switch (eventData->eventType) { case bz_ePlayerUpdateEvent: playerID = ((bz_PlayerUpdateEventData_V1*)eventData)->playerID; break; case bz_eShotFiredEvent: playerID = ((bz_PlayerUpdateEventData_V1*)eventData)->playerID; break; default: return; } player = bz_getPlayerByIndex(playerID); if (!player) return; if (player->globalUser) { bz_freePlayerRecord(player); return; } bz_freePlayerRecord(player); const char* flagAbrev = bz_getPlayerFlag(playerID); if (!flagAbrev) return; bz_removePlayerFlag(playerID); bz_sendTextMessage(BZ_SERVER,playerID, "Flags are for registered players only"); }
void KeepAwayPlayerPaused( bz_EventData *eventData ) { if (eventData->eventType != bz_ePlayerPausedEvent || !keepaway.enabled || keepaway.flagToKeep == "") return; bz_PlayerPausedEventData_V1 *PauseData = (bz_PlayerPausedEventData_V1*)eventData; bz_BasePlayerRecord *player = bz_getPlayerByIndex(PauseData->playerID); if (player) { const char* flagHeld = bz_getPlayerFlag(player->playerID); if (flagHeld) { if (flagHeld == keepaway.flagToKeep) { bz_removePlayerFlag (player->playerID); bz_sendTextMessage (BZ_SERVER, PauseData->playerID, "Flag removed - cannot pause while holding flag."); keepaway.id = -1; keepaway.team = eNoTeam; keepaway.toldFlagFree = false; } } } bz_freePlayerRecord(player); return; }
void TCTFPlayerUpdates ( bz_EventData *eventData ) { if (eventData->eventType != bz_ePlayerUpdateEvent) return; // no CTF if teams not balanced, drop team flags asap: if (!tctf.fairCTF) { int playerID = ((bz_PlayerUpdateEventData_V1*)eventData)->playerID; const char* FlagHeld = bz_getPlayerFlag(playerID); if (FlagHeld != NULL) { if (strcmp(FlagHeld, "R*") == 0 || strcmp(FlagHeld, "G*") == 0 || strcmp(FlagHeld, "B*") == 0 || strcmp(FlagHeld, "P*") == 0 ) { bz_removePlayerFlag ( playerID ); bz_sendTextMessagef (BZ_SERVER, playerID, "Capture The Flag disabled - teams are not evenly balanced."); } } } return; }
std::string getFlag() { if (keepaway.flagToKeepIndex < -1) // this should never happen, but save a crash if something goes nuts return ""; // get next flag; if not free take it from player (if forced flags) for (unsigned int h = 0; h < keepaway.flagsList.size(); h++) // check all specified flags { keepaway.flagToKeepIndex++; // get next one in line if (keepaway.flagToKeepIndex > ((int)keepaway.flagsList.size() - 1)) // go back to start if at end keepaway.flagToKeepIndex = 0; std::string flagCandidate = keepaway.flagsList[keepaway.flagToKeepIndex]; bool flagNotHeld = true; bz_APIIntList *playerList = bz_newIntList(); bz_getPlayerIndexList ( playerList ); for ( unsigned int i = 0; i < playerList->size(); i++ ) { bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i)); if (player) { const char* playerFlag = bz_getPlayerFlag(player->playerID); if (playerFlag) { if (playerFlag == flagCandidate && keepaway.forcedFlags) // take it, if forced flags { bz_removePlayerFlag (player->playerID); bz_sendTextMessage (BZ_SERVER, player->playerID, "Sorry, server needs your flag for Keep Away :/"); } if (playerFlag == flagCandidate && !keepaway.forcedFlags) // look for next free flag in list flagNotHeld = false; } } bz_freePlayerRecord(player); } bz_deleteIntList(playerList); if (flagNotHeld) return flagCandidate; } if (!keepaway.flagsList.empty()) // we should never get here, but if we do keep going return keepaway.flagsList[0]; else return ""; }
inline void checkKeepAwayHolder() { bz_APIIntList *playerList = bz_newIntList(); bz_getPlayerIndexList ( playerList ); for ( unsigned int i = 0; i < playerList->size(); i++ ){ bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i)); if (player) { const char* flagHeld = bz_getPlayerFlag(player->playerID); if (flagHeld) { if (flagHeld == keepaway.flagToKeep && keepaway.id == -1) // gotta a new one; initiate { initiatekeepaway(player->team, player->callsign, player->playerID); bz_freePlayerRecord(player); bz_deleteIntList(playerList); return; } if (flagHeld == keepaway.flagToKeep && keepaway.id == player->playerID) // someone still has it; leave { bz_freePlayerRecord(player); bz_deleteIntList(playerList); return; } if (flagHeld == keepaway.flagToKeep && keepaway.id != player->playerID) // must have stolen it { initiatekeepaway(player->team, player->callsign, player->playerID); bz_freePlayerRecord(player); bz_deleteIntList(playerList); return; } } } bz_freePlayerRecord(player); } keepaway.id = -1; // no one has flag keepaway.team = eNoTeam; bz_deleteIntList(playerList); return; }
void fairCTF::SetDropTime() { bz_APIIntList *playerList = bz_newIntList(); bz_getPlayerIndexList(playerList); bool TeamFlagIsCarried = false; // is any tank carrying a team flag? for (unsigned int i = 0; i < playerList->size(); i++) { const char *FlagHeld = bz_getPlayerFlag((*playerList)[i]); if (FlagHeld != NULL && (strcmp(FlagHeld, "R*") == 0 || strcmp(FlagHeld, "G*") == 0 || strcmp(FlagHeld, "B*") == 0 || strcmp(FlagHeld, "P*") == 0)) { TeamFlagIsCarried = true; break; } } bz_deleteIntList(playerList); // announce drop delay only if some tank is carrying a team flag if (TeamFlagIsCarried) { if (drop_delay >= 0) { droptime = bz_getCurrentTime() + (double)drop_delay; if (drop_delay > 1) { bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, bz_format("Currently-held team flags will be dropped in %d seconds.", drop_delay)); } else { bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Currently-held team flags will be dropped in 1 second."); } } else { bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, "Currently-held team flags will not be dropped."); } } }
void EventHandler::Event ( bz_EventData *eventData ) { 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; } const char* flagAbrev = bz_getPlayerFlag(playerID); if (!flagAbrev) return; std::vector<FlagStayZone*> validZones; // check and see if a zone cares about the current flag for ( unsigned int i = 0; i < zoneList.size(); i++ ) { if ( zoneList[i].checkFlag(flagAbrev) ) validZones.push_back(&zoneList[i]); } // Check each zone for this flag to see if we are in one bool insideOne = false; for ( unsigned int i = 0; i < validZones.size(); i++ ) { if ( validZones[i]->pointInZone(pos) ) { insideOne = true; playerIDToZoneMap[playerID] = i; } } // if they have taken the flag out of a zone, pop it. if (!insideOne && validZones.size() > 0) { int lastZone = -1; if ( playerIDToZoneMap.find(playerID) != playerIDToZoneMap.end() ) lastZone = playerIDToZoneMap[playerID]; bz_removePlayerFlag(playerID); if (lastZone != -1 && zoneList[lastZone].message.size()) bz_sendTextMessage(BZ_SERVER,playerID,zoneList[lastZone].message.c_str()); } }
void TeamFlagResetHandler::Event ( bz_EventData *eventData ) { if (eventData->eventType != bz_eTickEvent) return; if (tfr.timerOff == true) return; bz_APIIntList *playerList = bz_newIntList(); bz_getPlayerIndexList ( playerList ); // check to see if anyone has picked up a team flag & count players per team for ( unsigned int i = 0; i < playerList->size(); i++ ){ bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerList->operator[](i)); if (player) { tfr.flagTouched = bz_getPlayerFlag(player->playerID); if (tfr.flagTouched){ if (strcmp(tfr.flagTouched, "R*") == 0){ tfr.redLastTouched = bz_getCurrentTime(); tfr.redFlagWasHeld = true; } if (strcmp(tfr.flagTouched, "G*") == 0){ tfr.greenLastTouched = bz_getCurrentTime(); tfr.greenFlagWasHeld = true; } if (strcmp(tfr.flagTouched, "B*") == 0){ tfr.blueLastTouched = bz_getCurrentTime(); tfr.blueFlagWasHeld = true; } if (strcmp(tfr.flagTouched, "P*") == 0){ tfr.purpleLastTouched = bz_getCurrentTime(); tfr.purpleFlagWasHeld = true; } } bz_freePlayerRecord(player); } } bz_deleteIntList(playerList); // if no teamplay, no need to reset flags tfr.OKToReset = false; if (bz_getTeamCount(eRedTeam) * bz_getTeamCount(eGreenTeam) > 0) tfr.OKToReset = true; if (bz_getTeamCount(eRedTeam) * bz_getTeamCount(eBlueTeam) > 0) tfr.OKToReset = true; if (bz_getTeamCount(eRedTeam) * bz_getTeamCount(ePurpleTeam) > 0) tfr.OKToReset = true; if (bz_getTeamCount(eGreenTeam) * bz_getTeamCount(eBlueTeam) > 0) tfr.OKToReset = true; if (bz_getTeamCount(eGreenTeam) * bz_getTeamCount(ePurpleTeam) > 0) tfr.OKToReset = true; if (bz_getTeamCount(eBlueTeam) * bz_getTeamCount(ePurpleTeam) > 0) tfr.OKToReset = true; if (tfr.OKToReset == false){ ResetFlagData(); return; } // check if time's up on flags and reset (if they were held at least once after last reset) if (bz_getCurrentTime() - tfr.redLastTouched > tfr.idleTime && tfr.redFlagWasHeld){ if (bz_getTeamCount(eRedTeam) > 0){ resetTeamFlag ("R*"); bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Red flag sat idle too long - reset by server."); } tfr.redFlagWasHeld = false; tfr.redLastTouched = bz_getCurrentTime(); } if (bz_getCurrentTime() - tfr.greenLastTouched > tfr.idleTime && tfr.greenFlagWasHeld){ if (bz_getTeamCount(eGreenTeam) > 0){ resetTeamFlag ("G*"); bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Green flag sat idle too long - reset by server."); } tfr.greenLastTouched = bz_getCurrentTime(); tfr.greenFlagWasHeld = false; } if (bz_getCurrentTime() - tfr.blueLastTouched > tfr.idleTime && tfr.blueFlagWasHeld){ if (bz_getTeamCount(eBlueTeam) > 0){ resetTeamFlag ("B*"); bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Blue flag sat idle too long - reset by server."); } tfr.blueLastTouched = bz_getCurrentTime(); tfr.blueFlagWasHeld = false; } if (bz_getCurrentTime() - tfr.purpleLastTouched > tfr.idleTime && tfr.purpleFlagWasHeld){ if (bz_getTeamCount(ePurpleTeam) > 0){ resetTeamFlag ("P*"); bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "Purple flag sat idle too long - reset by server."); } tfr.purpleLastTouched = bz_getCurrentTime(); tfr.purpleFlagWasHeld = false; } return; }