[2771] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / FlightMaster.h
blob20ec50799fc3f9fdcff0a856b4209e7c8ae2c76c
1 /*
2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_FLIGHTMASERT_H
20 #define MANGOS_FLIGHTMASERT_H
22 /** @page FlightMaster keeps all current flight that's in progress so
23 * that every small time interval, it updates its location
24 * to generate ground and air activities. When the activities occur
25 * player update himself and other players within its visibility
26 * range so that both ground player and in the air player
27 * see each other's movement.
30 #include "Policies/Singleton.h"
31 #include "WaypointMovementGenerator.h"
32 #include "Log.h"
34 #include "zthread/FastMutex.h"
35 #include <functional>
36 #include <vector>
37 #include <cassert>
39 class MANGOS_DLL_DECL FlightMaster : public MaNGOS::Singleton<FlightMaster, MaNGOS::ClassLevelLockable<FlightMaster, ZThread::FastMutex> >
41 friend class MaNGOS::OperatorNew<FlightMaster>;
42 typedef ZThread::FastMutex LockType;
43 typedef MaNGOS::ClassLevelLockable<FlightMaster, ZThread::FastMutex>::Lock Guard;
44 typedef std::map<Player *, FlightPathMovementGenerator *> FlightMapType;
45 FlightMapType i_flights;
47 public:
49 /** ReportFlight reports a certain flight just started
50 * so that the flight master can keep track of the flight.
52 inline void ReportFlight(Player *pl, FlightPathMovementGenerator *gen)
54 Guard guard(*this);
55 i_flights[pl] = gen;
58 /** FlightReportUpdate updates each flight and if the flight has arrived
59 * to its destination, it will report to its player that the flight has
60 * finish and the flight path will be remove.
62 inline void FlightReportUpdate(const uint32 &diff)
64 Guard guard(*this);
65 for(FlightMapType::iterator iter=i_flights.begin(); iter != i_flights.end();)
67 //DEBUG_LOG("id=%d IsInWorld=%d", iter->first,iter->first->IsInWorld());
68 if( iter->first->IsInWorld() != 1 )
70 // do not use any func like "getname()" if player is offline, or it crash server
71 DEBUG_LOG("Removing player id=%d flight from flight master. (player offline)", iter->first);
72 delete iter->second;
73 i_flights.erase(iter++);
75 else if( iter->second->CheckFlight(diff) )
77 DEBUG_LOG("Removing player %s flight from flight master.", iter->first->GetName());
78 delete iter->second;
79 i_flights.erase(iter++);
81 else
82 ++iter;
87 #endif