1 #ifndef _ARMS_DEALERS_INIT__H_
2 #define _ARMS_DEALERS_INIT__H_
3 
4 #include "Arms_Dealer.h"
5 #include "Item_Types.h"
6 #include "JA2Types.h"
7 
8 #include <vector>
9 
10 
11 //The following defines indicate what items can be sold by the arms dealer
12 #define ARMS_DEALER_HANDGUNCLASS	0x00000001
13 #define ARMS_DEALER_SMGCLASS		0x00000002
14 #define ARMS_DEALER_RIFLECLASS		0x00000004
15 #define ARMS_DEALER_MGCLASS		0x00000008
16 #define ARMS_DEALER_SHOTGUNCLASS	0x00000010
17 
18 #define ARMS_DEALER_KNIFECLASS		0x00000020
19 
20 #define ARMS_DEALER_BLADE		0x00000040
21 #define ARMS_DEALER_LAUNCHER		0x00000080
22 
23 #define ARMS_DEALER_ARMOUR		0x00000100
24 #define ARMS_DEALER_MEDKIT		0x00000200
25 #define ARMS_DEALER_MISC		0x00000400
26 #define ARMS_DEALER_AMMO		0x00000800
27 
28 #define ARMS_DEALER_GRENADE		0x00001000
29 #define ARMS_DEALER_BOMB		0x00002000
30 #define ARMS_DEALER_EXPLOSV		0x00004000
31 
32 #define ARMS_DEALER_KIT		0x00008000
33 
34 #define ARMS_DEALER_FACE		0x00010000
35 //#define ARMS_DEALER_THROWN		0x00020000
36 //#define ARMS_DEALER_KEY		0x00040000
37 
38 //#define ARMS_DEALER_VIDEO_CAMERA	0x00020000
39 
40 #define ARMS_DEALER_DETONATORS		0x00040000
41 
42 #define ARMS_DEALER_ATTACHMENTS	0x00080000
43 
44 
45 #define ARMS_DEALER_ALCOHOL		0x00100000
46 #define ARMS_DEALER_ELECTRONICS	0x00200000
47 #define ARMS_DEALER_HARDWARE		0x00400000 | ARMS_DEALER_KIT
48 
49 #define ARMS_DEALER_MEDICAL		0x00800000 | ARMS_DEALER_MEDKIT
50 
51 //#define ARMS_DEALER_EMPTY_JAR	0x01000000
52 #define ARMS_DEALER_CREATURE_PARTS	0x02000000
53 #define ARMS_DEALER_ROCKET_RIFLE	0x04000000
54 
55 
56 #define ARMS_DEALER_ALL_GUNS		ARMS_DEALER_HANDGUNCLASS | ARMS_DEALER_SMGCLASS | ARMS_DEALER_RIFLECLASS | ARMS_DEALER_MGCLASS | ARMS_DEALER_SHOTGUNCLASS
57 
58 #define ARMS_DEALER_BIG_GUNS		ARMS_DEALER_SMGCLASS | ARMS_DEALER_RIFLECLASS | ARMS_DEALER_MGCLASS | ARMS_DEALER_SHOTGUNCLASS
59 
60 #define ARMS_DEALER_ALL_WEAPONS	ARMS_DEALER_ALL_GUNS | ARMS_DEALER_BLADE | ARMS_DEALER_LAUNCHER | ARMS_DEALER_KNIFECLASS
61 
62 
63 
64 
65 
66 
67 //
68 // Specific Dealer Flags
69 // NOTE: Each dealer has 8 flags, but different dealers can and SHOULD share the same flag #s!
70 //
71 
72 // Alex Fredo
73 #define ARMS_DEALER_FLAG__FREDO_HAS_SAID_ROCKET_RIFLE_QUOTE 0x00000001 // Alex Fredo has already repaired the Rocket Rifle
74 // Franz Hinkle
75 #define ARMS_DEALER_FLAG__FRANZ_HAS_SOLD_VIDEO_CAMERA_TO_PLAYER 0x00000001 // Franz Hinkle has sold the video camera to the player
76 
77 
78 
79 class DealerModel;
80 
81 // THIS STRUCTURE GETS SAVED/RESTORED/RESET
82 struct ARMS_DEALER_STATUS
83 {
84 	UINT32  uiArmsDealersCash; // How much money the arms dealer currently has
85 
86 	UINT8   ubSpecificDealerFlags; // Misc state flags for specific dealers
87 	BOOLEAN fOutOfBusiness; // Set when a dealer has been killed, etc.
88 	BOOLEAN fRepairDelayBeenUsed; // Set when a repairman has missed his repair time estimate & given his excuse for it
89 	BOOLEAN fUnusedKnowsPlayer; // Set if the shopkeeper has met with the player before [UNUSED] // XXX HACK000B
90 
91 	UINT32  uiTimePlayerLastInSKI; // game time (in total world minutes) when player last talked to this dealer in SKI
92 
93 	UINT8   ubPadding[ 8 ]; // XXX HACK000B
94 };
95 
96 
97 struct SPECIAL_ITEM_INFO
98 {
99 	UINT16 usAttachment[MAX_ATTACHMENTS]; // item index of any attachments on the item
100 
101 	INT8   bItemCondition;	// if 0, no item is stored
102 				// from 1 to 100 indicates an item with that status
103 				// -1 to -100 means the item is in for repairs, flip sign for the actual status
104 
105 	UINT8  ubImprintID; // imprint ID for imprinted items (during repair!)
106 
107 	INT8   bAttachmentStatus[MAX_ATTACHMENTS]; // status of any attachments on the item
108 
109 	UINT8  ubPadding[2]; // filler // XXX HACK000B
110 };
111 
112 
113 struct DEALER_SPECIAL_ITEM
114 {
115 	// Individual "special" items are stored here as needed, *one* per slot
116 	// An item is special if it is used (status < 100), has been imprinted, or has a permanent attachment
117 
118 	SPECIAL_ITEM_INFO Info;
119 
120 	UINT32  uiRepairDoneTime; // If the item is in for repairs, this holds the time when it will be repaired (in min)
121 
122 	BOOLEAN fActive; // TRUE means an item is stored here (empty elements may not always be freed immediately)
123 
124 	UINT8   ubOwnerProfileId; // stores which merc previously owned an item being repaired
125 
126 	UINT8   ubPadding[6]; // filler // XXX HACK000B
127 };
128 
129 
130 struct DEALER_ITEM_HEADER
131 {
132 	// Non-special items are all the identical and are totaled inside ubPerfectItems.
133 	// Items being repaired are also stored here, with a negative condition.
134 	// NOTE: special item elements may remain allocated long after item has been removed, to reduce memory fragmentation!!!
135 
136 	UINT8   ubTotalItems; // sum of all the items (all perfect ones + all special ones)
137 	UINT8   ubPerfectItems; // non-special (perfect) items held by dealer
138 	UINT8   ubStrayAmmo; // partially-depleted ammo mags are stored here as #bullets, and can be converted to full packs
139 
140 	std::vector<DEALER_SPECIAL_ITEM> SpecialItem; // dynamic array of special items with this same item index
141 
142 	UINT32  uiOrderArrivalTime; // Day the items ordered will arrive on.  It's UINT32 in case we change this to minutes.
143 	UINT8   ubQtyOnOrder; // The number of items currently on order
144 	BOOLEAN fPreviouslyEligible; // whether or not dealer has been eligible to sell this item in days prior to today
145 };
146 
147 extern ARMS_DEALER_STATUS gArmsDealerStatus[ NUM_ARMS_DEALERS ];
148 extern DEALER_ITEM_HEADER gArmsDealersInventory[ NUM_ARMS_DEALERS ][ MAXITEMS ];
149 
150 
151 
152 
153 
154 
155 void InitAllArmsDealers(void);
156 void ShutDownArmsDealers(void);
157 
158 //Count only the # of "distinct" item types (for shopkeeper purposes)
159 UINT32 CountDistinctItemsInArmsDealersInventory(ArmsDealerID);
160 UINT16 CountTotalItemsRepairDealerHasInForRepairs(ArmsDealerID);
161 
162 void AddObjectToArmsDealerInventory(ArmsDealerID, OBJECTTYPE*);
163 
164 void RemoveItemFromArmsDealerInventory(ArmsDealerID, UINT16 usItemIndex, SPECIAL_ITEM_INFO* pSpclItemInfo, UINT8 ubHowMany);
165 void RemoveSpecialItemFromArmsDealerInventoryAtElement(ArmsDealerID, UINT16 usItemIndex, UINT8 ubElement);
166 
167 BOOLEAN      IsMercADealer( UINT8 ubMercID );
168 ArmsDealerID GetArmsDealerIDFromMercID(UINT8 ubMercID);
169 
170 void SaveArmsDealerInventoryToSaveGameFile(HWFILE);
171 void LoadArmsDealerInventoryFromSavedGameFile(HWFILE, UINT32 savegame_version);
172 
173 void DailyUpdateOfArmsDealersInventory(void);
174 
175 const DealerModel* GetDealer(UINT8);
176 ArmsDealerType GetTypeOfArmsDealer( UINT8 ubDealerID );
177 
178 BOOLEAN	DoesDealerDoRepairs(ArmsDealerID);
179 BOOLEAN RepairmanIsFixingItemsButNoneAreDoneYet( UINT8 ubProfileID );
180 
181 BOOLEAN CanDealerTransactItem(ArmsDealerID, UINT16 usItemIndex, BOOLEAN fPurchaseFromPlayer);
182 BOOLEAN CanDealerRepairItem(ArmsDealerID, UINT16 usItemIndex);
183 
184 BOOLEAN AddDeadArmsDealerItemsToWorld(SOLDIERTYPE const*);
185 
186 void		MakeObjectOutOfDealerItems( UINT16 usItemIndex, SPECIAL_ITEM_INFO *pSpclItemInfo, OBJECTTYPE *pObject, UINT8 ubHowMany );
187 
188 void GiveObjectToArmsDealerForRepair(ArmsDealerID, OBJECTTYPE const* pObject, UINT8 ubOwnerProfileId);
189 
190 UINT32 CalculateObjectItemRepairTime(ArmsDealerID, OBJECTTYPE const* pItemObject);
191 
192 UINT32 CalculateObjectItemRepairCost(ArmsDealerID, OBJECTTYPE const* pItemObject);
193 
194 
195 void SetSpecialItemInfoToDefaults( SPECIAL_ITEM_INFO *pSpclItemInfo );
196 void SetSpecialItemInfoFromObject(SPECIAL_ITEM_INFO* pSpclItemInfo, const OBJECTTYPE* pObject);
197 
198 UINT16 CalcValueOfItemToDealer(ArmsDealerID, UINT16 usItemIndex, BOOLEAN fDealerSelling);
199 
200 BOOLEAN DealerItemIsSafeToStack( UINT16 usItemIndex );
201 
202 UINT32 CalculateOvernightRepairDelay(ArmsDealerID, UINT32 uiTimeWhenFreeToStartIt, UINT32 uiMinutesToFix);
203 UINT32 CalculateMinutesClosedBetween(ArmsDealerID, UINT32 uiStartTime, UINT32 uiEndTime);
204 
205 void    GuaranteeAtLeastXItemsOfIndex(ArmsDealerID, UINT16 usItemIndex, UINT8 ubHowMany);
206 BOOLEAN ItemIsARocketRifle(INT16 sItemIndex);
207 
208 extern UINT8 gubLastSpecialItemAddedAtElement;
209 
210 #endif
211