1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 //Filename    : OU_CARA.H
22 //Description : Header file of Unit Caravan
23 //Owner		  : Alex
24 
25 #ifndef __OU_CARA_H
26 #define __OU_CARA_H
27 
28 #ifndef __ODYNARR_H
29 #include <ODYNARR.h>
30 #endif
31 
32 #ifndef __OSPATH_H
33 #include <OSPATH.h>
34 #endif
35 
36 #ifndef __OUNIT_H
37 #include <OUNIT.h>
38 #endif
39 
40 #ifndef __ORAWRES_H
41 #include <ORAWRES.h>
42 #endif
43 
44 #ifndef __F_MARK_H
45 #include <OF_MARK.h>
46 #endif
47 
48 //------------- Define constant -----------//
49 
50 #define MAX_STOP_FOR_CARAVAN		3		// Maximum no. of destination stations per train
51 #define MAX_CARAVAN_CARRY_QTY 	100	// Maximum qty of goods a caravan can carry
52 #define MAX_CARAVAN_WAIT_TERM		8		// no. of term the caravan is in the market to upload/download cargo
53 #define POPULATION_PER_CARAVAN   10		// the population size for supporting one caravan
54 
55 //-------- define pick up type --------//
56 
57 enum	{	AUTO_PICK_UP = 0,
58 			PICK_UP_RAW_FIRST = 1,
59 			PICK_UP_RAW_LAST=PICK_UP_RAW_FIRST+MAX_RAW-1,
60 			PICK_UP_PRODUCT_FIRST,
61 			PICK_UP_PRODUCT_LAST=PICK_UP_PRODUCT_FIRST+MAX_PRODUCT-1,
62 			MAX_PICK_UP_GOODS = PICK_UP_PRODUCT_LAST,
63 			NO_PICK_UP = MAX_PICK_UP_GOODS+1,
64 
65 			MAX_GOODS_SELECT_BUTTON = MAX_PICK_UP_GOODS+2,
66 		};
67 
68 enum { PICK_UP_TYPE_COUNT = NO_PICK_UP };
69 
70 enum { NO_STOP_DEFINED = 0,	// used for journey_status
71 		 ON_WAY_TO_FIRM = 1,
72 		 SURROUND_FIRM,
73 		 INSIDE_FIRM,
74 	  };
75 
76 #define CARAVAN_UNLOAD_TO_MARKET_QTY	100
77 #define MIN_FIRM_STOCK_QTY					100
78 
79 //-------- Define struct TradeStop ----------//
80 #pragma pack(1)
81 struct TradeStop
82 {
83 public:
84 	short firm_recno;							// firm recno of the station
85 	short	firm_loc_x1;						//-******* used temporarily
86 	short firm_loc_y1;
87 	char  pick_up_type;			// auto, selective, none
88 	char	pick_up_array[MAX_PICK_UP_GOODS]; // useful for selective mode
89 
90 public:
91 	int			num_of_pick_up_goods(char *enableTable);
92 
93 	void			pick_up_set_auto();
94 	void			pick_up_set_none();
95 	void			pick_up_toggle(int pos);
96 };
97 #pragma pack()
98 
99 //-------- Define struct CaravanStop ----------//
100 #pragma pack(1)
101 struct CaravanStop : public TradeStop
102 {
103 public:
104 	char	firm_id;
105 
106 public:
107 	int	update_pick_up(char *enableFlag=NULL);
108 };
109 #pragma pack()
110 
111 struct UnitCaravanCrc;
112 
113 //----------- Define class Caravan -----------//
114 
115 #pragma pack(1)
116 class UnitCaravan : public Unit
117 {
118 public:
119 	short			caravan_id;						// id. of the caravan, for name display
120 
121 	char			journey_status;				// 1 for not unload but can up load, 2 for unload but not up load
122 	char		 	dest_stop_id;					// destination stop id. the stop which the train currently is moving towards
123 	char			stop_defined_num;				// num of stop defined
124 	char			wait_count;						// set to -1 to indicate only one stop is specified
125 
126 	short			stop_x_loc;						// the x location the unit entering the stop
127 	short			stop_y_loc;						// the y location the unit entering the stop
128 
129 	CaravanStop stop_array[MAX_STOP_FOR_CARAVAN];	// an array of firm_recno telling train stop stations
130 
131 	int			last_set_stop_date;			// the date when stops were last set.
132    int			last_load_goods_date;		// the last date when the caravan load goods from a firm
133 
134 	//------ goods that the caravan carries -------//
135 
136 	short			raw_qty_array[MAX_RAW];
137 	short			product_raw_qty_array[MAX_PRODUCT];
138 
139    int			carrying_qty(int pickupType);
140 
141 public:
142 	UnitCaravan();
143 
144 	void	init_derived();
145 
146 	void 	disp_info(int refreshFlag);
147 	void  detect_info();
148 	bool  is_in_build_menu();
149 
150 	void 	set_stop(int stopId, int stopXLoc, int stopYLoc, char remoteAction);
151 	void	del_stop(int stopId, char remoteAction);
152 	void	update_stop_list();
153 	void 	set_stop_pick_up(int stopId, int newPIckUpType, int remoteAction);
154 	int 	can_set_stop(int firmRecno);
155 	int	has_pick_up_type(int stopId, int pickUpType);
156 
157 	void	caravan_in_firm();
158 	void	caravan_on_way();
159 	void  pre_process();
160 
161 	void    copy_route(short copyUnitRecno, int remoteAction);
162 
163 	//------- ai functions --------//
164 
165 	void 	process_ai();
166 	int	think_resign();
167 	int  	think_del_stop();
168 	void	think_set_pick_up_type();
169 	void	think_set_pick_up_type2(int fromStopId, int toStopId);
170 
171 	//-------------- multiplayer checking codes ---------------//
172 	virtual	uint8_t crc8();
173 	virtual	void	clear_ptr();
174 	virtual	void	init_crc(UnitCaravanCrc *c);
175 
176 private:
177 	void 	disp_stop(int dispY1, int refreshFlag);
178 	void	detect_stop();
179 	void	disp_goods(int dispY1, int refreshFlag);
180 	void	disp_goods_select_button(int stopNum, int dispY1, int refreshFlag);
181 
182 	int 	get_next_stop_id(int curStopId=MAX_STOP_FOR_CARAVAN);
183 
184 	//-------- for mine ----------//
185 	void	mine_load_goods(char pickUpType);
186 
187 	//-------- for factory ---------//
188 	void	factory_unload_goods();
189 	void	factory_load_goods(char pickupType);
190 
191 	//-------- for market ---------//
192 	void 	market_unload_goods();
193 	int	market_unload_goods_in_empty_slot(FirmMarket *curMarket, int position);
194 	void 	market_load_goods();
195 	void 	market_auto_load_goods();
196 	void 	market_load_goods_now(MarketGoods* marketGoods, float loadQty);
197 
198 	int	appear_in_firm_surround(int& xLoc, int& yLoc, Firm* firmPtr);	// select a suitable location to leave the stop
199 };
200 #pragma pack()
201 
202 //------------------------------------------//
203 
204 #endif
205