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	  : OTALKRES.H
22 //Description : Header file for class TalkRes
23 
24 #ifndef __OTALKRES_H
25 #define __OTALKRES_H
26 
27 #ifndef __OSTR_H
28 #include <OSTR.h>
29 #endif
30 
31 #ifndef __ODYNARRB_H
32 #include <ODYNARRB.h>
33 #endif
34 
35 #ifndef __OTALKMSG_H
36 #include <OTALKMSG.h>
37 #endif
38 
39 //-------- define constant ----------//
40 
41 enum { MAX_TALK_CHOICE = MAX_TALK_TYPE	};
42 
43 enum { MAX_WAIT_MSG_PER_NATION = 3 };	// you cannot send more than 3 messages to a nation until it processes some of them
44 
45 enum { TALK_MSG_KEEP_DAYS = 365 };		// keep TalkMsg for 365 days before deleting it.
46 
47 //-------- define reply answer ------//
48 
49 enum { REPLY_NOT_NEEDED,		// do not need a reply for this messge, it's an informative message only
50 		 REPLY_WAITING,
51 		 REPLY_ACCEPT,
52 		 REPLY_REJECT
53 	  };
54 
55 //------- Define struct TalkMsg -------//
56 
57 #pragma pack(1)
58 struct TalkMsg
59 {
60 public:
61 	short		talk_id;
62 	short		talk_para1;
63 	short 	talk_para2;
64 
65 	int		date;
66 
67 	char		from_nation_recno;
68 	char		to_nation_recno;
69 
70 	char		reply_type;		// whether this is a reply message.
71 	int		reply_date;
72 
73 	char		relation_status;    // the relation status of the two nations when the message is sent
74 
75    //-----------------------------------//
76 
77 	char* 	from_nation_name();
78 	char* 	to_nation_name();
79 	char* 	para1_nation_name();
80 
81 	char* 	from_king_name();
82 	char* 	to_king_name();
83 
84 	char* 	nation_color_code_str(int nationRecno);
85 	char* 	nation_color_code_str2(int nationRecno);
86 
87 	//-----------------------------------//
88 
89 public:
90 	TalkMsg();
91 
92 	char*		msg_str(int viewingNationRecno, int dispReply=1, int dispSecondLine=0);
93 
94 	int		is_reply_needed();		// whether a reply is needed for this message
95 	int		is_valid_to_disp(int invalid_nation_recno = 0); // can specify an additional nation recno that is to be considered invalid.
96 	int		is_valid_to_reply();
97 	int		can_accept();
98 
99 	void		process_accepted_reply();
100 
101 	void		propose_treaty(short treatyType);
102 	void     end_treaty(short treatyType);
103 	void		request_military_aid();
104 	void		request_trade_embargo();
105 	void     request_cease_war();
106 	void     request_declare_war();
107 	void     request_buy_food();
108 	void     declare_war();
109 	void     give_tribute(const char* tributeStr);
110 	void     demand_tribute(int isAid);
111 	void     give_tech();
112 	void		demand_tech();
113 	void		request_surrender();
114 	void		surrender();
115 
116 	// ###### begin Gilbert 10/10 #########//
117 	uint8_t		crc8();
118 	void		clear_ptr();
119 	// ###### end Gilbert 10/10 #########//
120 
121 };
122 #pragma pack()
123 
124 //------- Define struct TalkChoice -------//
125 
126 #pragma pack(1)
127 struct TalkChoice
128 {
129 	const char*	str;
130 	short		para;
131 };
132 #pragma pack()
133 
134 //------ Define class TalkRes --------//
135 
136 #pragma pack(1)
137 class TalkRes
138 {
139 public:
140 	char	   	init_flag;
141 
142 	short			reply_talk_msg_recno;
143 
144 	TalkMsg		cur_talk_msg;
145 	const char*		choice_question;
146 	char*			choice_question_second_line;
147 
148 	short			talk_choice_count;
149 	TalkChoice	talk_choice_array[MAX_TALK_CHOICE];
150 
151 	char			available_talk_id_array[MAX_TALK_TYPE];
152 
153 	short			cur_choice_id;
154 	char			save_view_mode;
155 
156 	char			msg_add_nation_color;
157 
158 	DynArrayB	talk_msg_array;
159 
160 public:
161 	TalkRes();
162 
163 	void			init();
164 	void			deinit();
165 
166 	void			init_conversion(int nationRecno);
167 
168 	void			disp_talk();
169 	int			detect_talk();
170 
171 	int  			ai_send_talk_msg(int toNationRecno, int fromNationRecno, int talkId, int talkPara1=0, int talkPara2=0, int forceSend=0);
172 	void 			send_talk_msg(TalkMsg*, char remoteAction);
173 	void 			send_talk_msg_now(TalkMsg*);
174 	void			reply_talk_msg(int talkMsgRecno, char replyType, char remoteAction);
175 	int  			can_send_msg(int toNationRecno, int fromNationRecno, int talkId);
176 	int			can_send_any_msg(int toNationRecno, int fromNationRecno);
177 
178 	int			set_talk_choices();
179 	void			player_reply(int talkMsgRecno);
180 
talk_msg_count()181 	int			talk_msg_count()			{ return talk_msg_array.size(); }
182 	int 			wait_msg_count(int toNationRecno, int fromNationRecno);
183 
184 	TalkMsg* 	get_talk_msg(int recNo);
185 	void 			del_talk_msg(int recNo);
186 	int			is_talk_msg_deleted(int recNo);
187 	void 			del_all_nation_msg(int nationRecno);
188 
189 	int 			is_talk_msg_exist(TalkMsg* thisTalkMsg, int checkPara);
190 
191 	void			next_day();
192 
193 	int 			write_file(File* filePtr);
194 	int			read_file(File* filePtr);
195 
196 private:
197 	void			add_talk_choice(const char* talkStr, int talkPara);
198 
199 	void			add_main_choices();
200 	int			add_trade_embargo_choices();
201 	int  			add_declare_war_choices();
202 	int  			add_buy_food_choices();
203 	int 			add_tribute_choices();
204 	int 			add_give_tech_choices();
205 	int			add_surrender_choices();
206 	int			add_request_surrender_choices();
207 
208 	int   		detect_talk_choices();
209 
210 	void			process_talk_msg();
211 
212 };
213 #pragma pack()
214 
215 extern TalkRes talk_res;
216 
217 //------------------------------------//
218 
219 #endif
220