Merge branch '164-crash-on-patching-and-possibly-right-after-login' into main/gingo...
[ryzomcore.git] / ryzom / client / src / faction_war_manager.cpp
blob55f3439bc5155f446cd0a2f26654ce49ebb4b044
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 /////////////
20 // INCLUDE //
21 /////////////
22 #include "stdpch.h"
23 #include "faction_war_manager.h"
26 ///////////
27 // USING //
28 ///////////
29 using namespace NLMISC;
30 using namespace std;
33 ////////////
34 // METHOD //
35 ////////////
36 CFactionWarManager * CFactionWarManager::_Instance = NULL;
39 //----------------------------------------------------------------------------
40 void CFactionWarManager::addFactionWar(PVP_CLAN::CFactionWar fw)
42 for( uint i=0; i<_FactionWarOccurs.size(); ++i )
44 if( _FactionWarOccurs[i].inPvPFaction(fw.Clan1, fw.Clan2) )
46 return;
49 nldebug("<CFactionWarManager::addFactionWar> Adding faction war %s vs %s",PVP_CLAN::toString(fw.Clan1).c_str(),PVP_CLAN::toString(fw.Clan2).c_str());
50 _FactionWarOccurs.push_back(fw);
53 //----------------------------------------------------------------------------
54 void CFactionWarManager::stopFactionWar(PVP_CLAN::CFactionWar fw)
56 vector< PVP_CLAN::CFactionWar >::iterator it;
57 for( it=_FactionWarOccurs.begin(); it!=_FactionWarOccurs.end(); ++it )
59 if( (*it).inPvPFaction(fw.Clan1, fw.Clan2) )
61 nldebug("<CFactionWarManager::stopFactionWar> Stopping faction war %s vs %s",PVP_CLAN::toString(fw.Clan1).c_str(),PVP_CLAN::toString(fw.Clan2).c_str());
62 _FactionWarOccurs.erase(it);
63 return;
68 //----------------------------------------------------------------------------
69 bool CFactionWarManager::areFactionsInWar(PVP_CLAN::TPVPClan clan1, PVP_CLAN::TPVPClan clan2)
71 for( uint i=0; i<_FactionWarOccurs.size(); ++i )
73 if( _FactionWarOccurs[i].inPvPFaction(clan1, clan2) )
75 return true;
78 return false;
81 //----------------------------------------------------------------------------
82 void CFactionWarManager::init()
84 if( _Instance != 0 )
85 return;
87 _Instance = new CFactionWarManager();
90 //----------------------------------------------------------------------------
91 CFactionWarManager * CFactionWarManager::getInstance()
93 if(CFactionWarManager::_Instance == 0)
95 CFactionWarManager::init();
97 return CFactionWarManager::_Instance;
100 //----------------------------------------------------------------------------
101 void CFactionWarManager::release()
103 if( _Instance != 0 )
105 delete _Instance;
106 _Instance = 0;
110 //----------------------------------------------------------------------------
111 CFactionWarManager::~CFactionWarManager()
113 _FactionWarOccurs.clear();