Planeshift

factions.h

Go to the documentation of this file.
00001 /*
00002  * factions.h
00003  *      written by Keith Fulton <[email protected]>
00004  *
00005  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00006  *
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation (version 2 of the License)
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  *
00019  */
00020 #ifndef __FACTIONS_H__
00021 #define __FACTIONS_H__
00022 
00023 #include <csutil/hash.h>
00024 #include <csutil/csstring.h>
00025 
00029 struct FactionLifeEvent
00030 {
00031     int value;                  
00032     csString event_description; 
00033     
00034     bool operator== (FactionLifeEvent OtherEvt) const { return value == OtherEvt.value; }
00035     bool operator<  (FactionLifeEvent OtherEvt) const { return value <  OtherEvt.value; }
00036 };
00037 
00041 struct Faction
00042 {
00043     csString name;
00044     csString description;
00045     int      id;
00046     float    weight;
00047     csArray<FactionLifeEvent> PositiveFactionEvents; 
00048     csArray<FactionLifeEvent> NegativeFactionEvents; 
00049 };
00050 
00051 
00056 struct FactionStanding
00057 {
00058     Faction *faction;
00059     int score;
00060     bool dirty;
00061 };
00062 
00063 
00068 class FactionSet
00069 {
00070 protected:
00072     csHash<FactionStanding*, int>   factionstandings;
00073 
00075     csHash<Faction*, int>*   factions_by_id;
00076 
00077 public:
00082     FactionSet(const char *csv_list,csHash<Faction*, int, CS::Memory::AllocatorMalloc> &factionset);
00083 
00084     ~FactionSet();
00085 
00086     bool GetFactionStanding(int factionID,int& standing, float& weight);
00087 
00100     void UpdateFactionStanding(int factionID, int delta, bool setDirty = true, bool overwrite = false);
00101 
00105     void GetFactionListCSV(csString& csv);
00106 
00107     float FindWeightedDiff(FactionSet* other);
00108 
00109     csHash<FactionStanding*, int>&  GetStandings() { return factionstandings; }
00110 
00114     bool CheckFaction(Faction * faction, int value);
00115 
00119     int GetFaction(Faction *faction);
00120 };
00121 
00122 
00123 
00124 #endif
00125