Add infos into target window
[ryzomcore.git] / ryzom / server / src / entities_game_service / trade_structures.h
blob36916b4201fda3d1d2471fc0e2648a46535bda3b
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 #ifndef TRADE_H
20 #define TRADE_H
22 // Misc
23 #include "nel/misc/vectord.h"
25 #include "game_item_manager/game_item.h"
26 #include "game_share/constants.h"
28 namespace RYZOM_TRADE
32 //type of a trade
33 enum TTradeType
35 unknown = 0,
36 item,
37 teleport,
38 brick,
39 phrase,
40 pact,
41 plan,
45 // Specialized part of trading struct for item
46 struct SItemTrade
48 NL_INSTANCE_COUNTER_DECL(SItemTrade);
49 public:
51 // constructor
52 SItemTrade() { ItemPtr = 0; Quality = 0; Level = 0; }
54 uint16 Quality;
55 uint16 Level;
56 CGameItemPtr ItemPtr;
58 void copy( SItemTrade * i )
60 if (!i)
61 return;
63 Quality = i->Quality;
64 Level = i->Level;
65 ItemPtr = i->ItemPtr;
70 ///////////////////////////////////////////////////////
71 // User interface : Common interface for trading struct
72 ///////////////////////////////////////////////////////
73 class CTradeBase
75 public:
76 uint32 Price;
77 uint8 Type;
78 NLMISC::CSheetId Sheet;
79 void* Specialized;
81 CTradeBase() { Type = unknown; Specialized = 0; Price = 0; }
83 CTradeBase( TTradeType type )
85 Type = type;
86 if ( Type == item || Type == plan )
88 Specialized = new SItemTrade();
90 else
91 Specialized = 0;
94 // destructor
95 virtual ~CTradeBase()
97 if( (Specialized && Type == item || Type == plan ) && Specialized != 0 )
99 delete ( (SItemTrade *) Specialized);
103 // Copy constructor
104 CTradeBase( const CTradeBase& t )
106 Price = t.Price;
107 Type = t.Type;
108 Sheet = t.Sheet;
109 if ( (Type == item || Type == plan ) && t.Specialized != 0)
111 Specialized = new SItemTrade();
112 ( (SItemTrade *) Specialized)->copy( (SItemTrade *) t.Specialized );
114 else
115 Specialized = 0;
118 // = operator
119 const CTradeBase &operator = (const CTradeBase &a)
121 Price = a.Price;
122 Type = a.Type;
123 Sheet = a.Sheet;
124 if ( ( Type == item || Type == plan ) && a.Specialized != 0 )
126 if (Specialized)
127 delete (SItemTrade *) Specialized ;
129 Specialized = new SItemTrade();
130 ( (SItemTrade *) Specialized)->copy( (SItemTrade *) a.Specialized );
132 return *this;
134 private:
135 // Common part of CTrade for serial management
136 struct CTradeUnserial
138 uint32 Price;
139 uint8 Type;
140 NLMISC::CSheetId Sheet;
143 void init( CTradeUnserial& s )
145 Price = s.Price;
146 Type = s.Type;
147 Sheet = s.Sheet;
148 if ( Type == item || Type == plan )
150 Specialized = new SItemTrade();
155 typedef std::vector< RYZOM_TRADE::CTradeBase * > TTradeList;
159 #endif