1 /*
2  *
3  *   Copyright (c) 1994, 2002, 2003 Johannes Prix
4  *   Copyright (c) 1994, 2002 Reinhard Prix
5  *   Copyright (c) 2004-2010 Arthur Huillet
6  *
7  *
8  *  This file is part of Freedroid
9  *
10  *  Freedroid is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  Freedroid is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with Freedroid; see the file COPYING. If not, write to the
22  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  *  MA  02111-1307  USA
24  *
25  */
26 
27 #ifndef _struct_h
28 #define _struct_h
29 
30 #include "system.h"
31 #include "defs.h"
32 #include "lua.h"
33 
34 typedef struct {
35 	Uint8 r;
36 	Uint8 g;
37 	Uint8 b;
38 	Uint8 a;
39 } myColor;
40 
41 /**
42  * Simple doubly linked list implementation.
43  */
44 typedef struct list_head {
45 	struct list_head *next;
46 	struct list_head *prev;
47 } list_head_t;
48 
49 /**
50  * Dynamic arrays
51  */
52 struct dynarray {
53 	void *arr;
54 	int size;
55 	int capacity;
56 };
57 
58 typedef struct dynarray item_dynarray;
59 typedef struct dynarray string_dynarray;
60 
61 typedef struct upgrade_socket_dynarray {
62 	struct upgrade_socket *arr;
63 	int size;
64 	int capacity;
65 } upgrade_socket_dynarray;
66 
67 struct font {
68 	int height;
69 	int letter_spacing;
70 	struct BFont_Info *bfont;
71 };
72 
73 enum image_transformation_mode {
74 	HIGHLIGHTED = 1 << 1,
75 	REPEATED    = 1 << 2
76 };
77 
78 struct image_transformation {
79 	SDL_Surface *surface;
80 	float scale_x; /**< zoom factor or repeat factor, depending on transformation mode */
81 	float scale_y; /**< zoom factor or repeat factor, depending on transformation mode */
82 	float c[4];    /**< color transformation, r g b a in that order */
83 	enum image_transformation_mode mode;
84 };
85 
86 /**
87  * This structure defines an image in FreedroidRPG. It contains information
88  * that enables rendering using SDL or OpenGL.
89  */
90 struct image {
91 	SDL_Surface *surface;
92 	short offset_x;
93 	short offset_y;
94 	short w;
95 	short h;
96 	int texture_type;
97 #ifdef HAVE_LIBGL
98 	GLuint texture;
99 #else
100 	int texture;
101 #endif
102 	float tex_x0;
103 	float tex_x1;
104 	float tex_y0;
105 	float tex_y1;
106 	short tex_w;
107 	short tex_h;
108 
109 	struct image_transformation cached_transformation;
110 };
111 #define EMPTY_IMAGE { .surface = NULL , .offset_x = 0 , .offset_y = 0 , .texture_type = NO_TEXTURE , .cached_transformation = { NULL, 0.0, 0.0, { 0.0, 0.0, 0.0, 0.0}, 0 } }
112 
113 typedef struct mouse_press_button {
114 	struct image button_image;
115 	char *button_image_file_name;
116 	SDL_Rect button_rect;
117 	char scale_this_button;
118 } mouse_press_button, *Mouse_press_button;
119 
120 /* Type definitions needed to create specific save/load functions */
121 typedef char *string;
122 
123 typedef struct keybind {
124 	string name; /**< keybinding name, taken from keybindNames */
125 	int key;      /**< key/axis/button event number */
126 	int mod;      /**< Key modifiers */
127 } keybind_t;
128 
129 typedef struct configuration_for_freedroid {
130 	float WantedTextVisibleTime;
131 	int Draw_Framerate;
132 	int Draw_Position;
133 	int All_Texts_Switch;
134 	float Current_BG_Music_Volume;
135 	float Current_Sound_FX_Volume;
136 	int Current_Sound_Output_Fmt;
137 	float current_gamma_correction;
138 
139 	int Inventory_Visible;
140 	int CharacterScreen_Visible;
141 	int SkillScreen_Visible;
142 	int Automap_Visible;
143 	int spell_level_visible;
144 
145 	int autorun_activated;
146 
147 	string freedroid_version_string;
148 	int skip_light_radius;
149 	int skill_explanation_screen_visible;
150 	int enemy_energy_bars_visible;
151 	int effect_countdowns_visible;
152 	int limit_framerate;
153 	int omit_obstacles_in_level_editor;
154 	int omit_map_labels_in_level_editor;
155 	int omit_enemies_in_level_editor;
156 	int zoom_is_on;
157 	int show_blood;		// this can be used to make the game more friendly for children...
158 	int show_lvledit_tooltips;
159 	int show_grid;
160 	int show_wp_connections;
161 	int grid_mode;
162 	int number_of_big_screen_messages;
163 	float delay_for_big_screen_messages;
164 	int enable_cheatkeys;
165 	int transparency;
166 	int screen_width;
167 	int screen_height;
168 	int next_time_width_of_screen;
169 	int next_time_height_of_screen;
170 	int skip_shadow_blitting;
171 	int do_fadings;		// do the screen fadings
172 	int fullscreen_on;
173 	int talk_to_bots_after_takeover;
174 	int xray_vision_for_tux;
175 	int cheat_running_stamina;
176 	int cheat_double_speed;
177 	int lazyload;
178 	int show_item_labels;
179 	int last_edited_level;
180 	int show_all_floor_layers;
181 
182 	int difficulty_level;
183 
184 	string locale;
185 
186 	// This must be the last element of the structure, because the
187 	// input keybind parsing code uses strtok which messes with the
188 	// string.
189 	keybind_t input_keybinds[100];
190 } configuration_for_freedroid;
191 
192 typedef struct point {
193 	int x;
194 	int y;
195 } point;
196 
197 typedef struct moderately_finepoint {
198 	float x;
199 	float y;
200 } moderately_finepoint;
201 
202 typedef struct finepoint {
203 	double x;
204 	double y;
205 } finepoint;
206 
207 typedef struct gps {
208 	float x;
209 	float y;
210 	int z;
211 } gps;
212 
213 typedef struct map_label {
214 	char *label_name;
215 	point pos;		// how many blocks does this big map insert cover?
216 } map_label;
217 
218 typedef char *luacode;
219 typedef struct mission {
220 	string mission_name;
221 	int MissionWasAssigned;	// has be influencer been assigned to this mission? , currently uninitialized
222 	int MissionIsComplete;	// has the mission been completed?
223 	int MissionWasFailed;	// has the mission been failed?
224 	int MissionExistsAtAll;	// is this mission entry used at all, or is it just unused memory?
225 
226 	int KillMarker;
227 	int must_clear_level;
228 
229 	luacode completion_lua_code;
230 	luacode assignment_lua_code;
231 
232 	string mission_diary_texts[MAX_MISSION_DESCRIPTION_TEXTS];
233 	float mission_description_time[MAX_MISSION_DESCRIPTION_TEXTS];
234 	int expanded_display_for_this_mission;
235 } mission;
236 
237 struct addon_bonus {
238 	char *name;
239 	int value;
240 };
241 
242 struct addon_material {
243 	char *name;
244 	int value;
245 };
246 
247 struct addon_spec {
248 	int type;
249 	int upgrade_cost;
250 	char *requires_socket;
251 	char *requires_item;
252 	struct dynarray bonuses;
253 	struct dynarray materials;
254 };
255 
256 typedef struct itemspec {
257 	char *id;
258 	char *name;
259 	char *item_rotation_series_prefix;
260 	char *item_description;
261 	char *item_drop_sound_file_name;
262 	char *item_inv_file_name;
263 
264 	enum slot_type slot;
265 
266 	char *tux_part_instance;
267 
268 	char item_group_together_in_inventory;
269 
270 	// General characteristics of a weapon item (ranged or melee)
271 	char weapon_is_melee;                           // 1: melee weapon - 0: ranged weapon
272 	char weapon_needs_two_hands;	                // 1: this a (strictly) 2-handed weapon
273 	short int weapon_motion_class;                  // Tux's motion class to use
274 	float weapon_attack_time;                       // duration of an attack: time until the next attack can be made, measured in seconds
275 	float weapon_reloading_time;                    // time needed to put a new charger (if needed), added to attack_time on last ammunition
276 	char* weapon_reloading_sound;                   // sound to play when reloading weapon
277 	int weapon_base_damage;                         // damage done by this weapon
278 	int weapon_damage_modifier;                     // modifier to the damage done by this weapon
279 	char *weapon_ammo_type;                         // ammunition needed by the weapon (it can be anything that needs to be loaded in the weapon)
280 	short weapon_ammo_clip_size;                    // max. number of ammunition in the charger
281 
282 	// Characteristics of a weapon using bullets (ranged weapon)
283 	short weapon_bullet_type;                       // bullet's type used by this weapon (index into bullet_specs), to get bullet's image and sound
284 	float weapon_bullet_speed;                      // how fast should a bullet move straightforward?
285 	float weapon_bullet_lifetime;	                // how long does a 'bullet' from this gun type live?
286 	char weapon_bullet_pass_through_hit_bodies;     // does this bullet go through hit bodies (e.g. like a laser sword)
287 
288 	// how good is the item as armour or shield or other protection???
289 	int base_armor_class;
290 	int armor_class_modifier;
291 
292 	// which requirement for strength, dexterity and cooling does the item have?
293 	short int item_require_strength;
294 	short int item_require_dexterity;
295 	short int item_require_cooling;
296 
297 	// what durability does the item have?
298 	int base_item_durability;
299 	int item_durability_modifier;
300 
301 	struct {
302 		char *tooltip;
303 		char *skill;
304 		char *add_skill;
305 		enum _busytype busy_type;
306 		int busy_time;
307 	} right_use;
308 
309 	point inv_size;
310 	struct image inventory_image;
311 	struct image ingame_image;
312 	struct image shop_image;
313 
314 	short int base_list_price;	// the base price of this item at the shop
315 
316 	int min_drop_class;
317 	int max_drop_class;
318 	int drop_amount;		// minimum number of items to drop at once
319 	int drop_amount_max;	// maximum of items to drop at once
320 
321 } itemspec;
322 
323 typedef struct upgrade_socket {
324 	int type;
325 	string addon;
326 } upgrade_socket;
327 
328 typedef struct item {
329 	// Here are the rather short-lived properties of the item
330 	gps pos;
331 	gps virt_pos;
332 	SDL_Rect text_slot_rectangle;
333 	int type;
334 	int max_durability;	// the maximum item durability reachable for this item
335 	float current_durability;	// the currently remaining durability for this item
336 	float throw_time;	// has this item just jumped out from a chest maybe or is it jumping right now?
337 
338 	int bonus_to_dex;
339 	int bonus_to_str;
340 	int bonus_to_physique;
341 	int bonus_to_cooling;
342 	int bonus_to_health_points;
343 	float bonus_to_health_recovery;
344 	float bonus_to_cooling_rate;
345 	int bonus_to_attack;
346 	int bonus_to_all_attributes;
347 	int bonus_to_armor_class;
348 	int bonus_to_damage;
349 	int bonus_to_paralyze_enemy;
350 	int bonus_to_slow_enemy;
351 	int bonus_to_light_radius;
352 	int bonus_to_experience_gain;	// this is a percentage
353 
354 	int armor_class;
355 	int damage;		// how much damage does this item
356 	int damage_modifier;	// how much additional damage can add to the base damage
357 	int multiplicity;
358 	int ammo_clip;		// how much bullets in the clip, IN CASE OF WEAPON
359 	point inventory_position;
360 
361 	struct upgrade_socket_dynarray upgrade_sockets;
362 	int quality;
363 } item;
364 
365 typedef struct droidspec {
366 	char *droidname;
367 	char *default_short_description;
368 	char *droid_portrait_rotation_series_prefix;
369 	char *droid_death_sound_file_name;
370 	char *droid_attack_animation_sound_file_name;
371 	int class;
372 	float maxenergy;	// the maximum energy the batteries can carry
373 	int sensor_id;		// What sensor is the most common to this droid?
374 
375 	float healing_friendly; // the energy/second the droid heals as a friendly towards Tux
376 	float healing_hostile;  // the energy/second the droid heals as a hostile towards Tux
377 
378 	float maxspeed;
379 
380 	short experience_reward;	// experience_reward for the elimination of one droid of this type
381 
382 	float aggression_distance;
383 	float time_spent_eyeing_tux;
384 
385 	short int drop_class;
386 
387 	item weapon_item;
388 	int gun_muzzle_height;
389 
390 	short int amount_of_plasma_transistors;
391 	short int amount_of_superconductors;
392 	short int amount_of_antimatter_converters;
393 	short int amount_of_entropy_inverters;
394 	short int amount_of_tachyon_condensators;
395 
396 	short greeting_sound_type;	// which sample to play in order to 'greet' the influencer?
397 	short to_hit;		// chance that this droid hits an unarmoured target
398 	float recover_time_after_getting_hit;
399 	char *notes;		// notes on the droid of this type
400 	short int is_human;
401 	short individual_shape_nr;
402 } droidspec;
403 
404 typedef char s_char; // Used for pointer to static string which are not to be saved
405 
406 typedef struct enemy {
407 	// There are three sets of attributes, which are initialized and
408 	// possibly re-initialized by 3 different codes:
409 	//
410 	// 1) 'identity' attributes.
411 	//    The identity attributes define the basic information about a droid.
412 	//    They should not change during the game, apart in some very
413 	//    specific cases.
414 	// 2) global state' attributes.
415 	//    Those attributes define the global behavior of the enemy.
416 	//    The global state of a droid can possibly change during the game.
417 	// 3) 'transient state' attributes
418 	//    Their values are used by the animation and AI code.
419 	//    They change very frequently during the game.
420 	//
421 	// 1st and 2nd sets are initialized to default values in enemy_new().
422 	// The 3rd set is unconditionally reseted in enemy_reset().
423 	// The 2nd set contains attributes whose values depend on the
424 	// type of the droid. They are first positioned in GetThisLevelsDroids()
425 	// and GetThisLevelsSpecialForces(), and are conditionally reseted in
426 	// respawn_level().
427 
428 	//--------------------
429 	// 1st set (identity)
430 	//
431 	short int id;                       // unique id of the droid. start at 1.
432 	short int type;                     // the number of the droid specifications in Droidmap
433 	uint8_t SpecialForce;               // this flag will exclude the droid from initial shuffling of droids
434 	int marker;                         // this provides a marker for special mission targets
435 	short int max_distance_to_home;     // how far this robot will go before returning to it's home waypoint
436 	string dialog_section_name;
437 	string short_description_text;
438 	short int on_death_drop_item_code;  // drop a pre-determined item when dying
439 	int sensor_id;			// What is the sensor of this droid? Some droids have different sensors.
440 
441 
442 	//--------------------
443 	// 2nd set ('global state')
444 	//
445 	int faction;
446 	uint8_t will_respawn;		// will this robot be revived by respawn_level()?
447 	uint8_t will_rush_tux;          // will this robot approach the Tux on sight and open communication?
448 	int combat_state;               // current state of the bot
449 	float state_timeout;            // time spent in this state (used by "timeout" states such as STOP_AND_EYE_TARGET only)
450 	short int CompletelyFixed;      // set this flag to make the robot entirely immobile
451 	uint8_t has_been_taken_over;    // has the Tux made this a friendly bot via takeover subgame?
452 	uint8_t follow_tux;             // does this robot try to follow tux via it's random movements?
453 	uint8_t has_greeted_influencer; // has this robot issued his first-time-see-the-Tux message?
454 	short int nextwaypoint;         // the next waypoint target
455 	short int lastwaypoint;         // the waypoint from whence this robot just came from
456 	short int homewaypoint;         // the waypoint this robot started at
457 	gps pos;                        // coordinates of the current position in the level
458 
459 	//--------------------
460 	// 3rd set ('transient state')
461 	//
462 	finepoint speed;                   // current speed
463 	float energy;                      // current energy of this droid
464 	float animation_phase;             // the current animation frame for this enemy (starting at 0 of course...)
465 	short int animation_type;          // walk-animation, attack-animation, gethit animation, death animation
466 	float frozen;                      // is this droid currently frozen and for how long will it stay this way?
467 	float poison_duration_left;        // is this droid currently poisoned and for how long will it stay this way?
468 	float poison_damage_per_sec;       // is this droid currently poisoned and how much poison is at work?
469 	float paralysation_duration_left;  // is this droid currently paralyzed and for how long will it stay this way?
470 	float pure_wait;                   // time till the droid will start to move again
471 	float firewait;                    // time this robot still takes until its weapon will be fully reloaded
472 	short int ammo_left;               // ammunition left in the charger
473 	uint8_t attack_target_type;        // attack NOTHING, PLAYER, or BOT
474 	short int bot_target_n;
475 	struct enemy *bot_target_addr;
476 	float previous_angle;              // which angle has this robot been facing the frame before?
477 	float current_angle;               // which angle will the robot be facing now?
478 	float previous_phase;              // which (8-way) direction did the robot face before?
479 	float last_phase_change;           // when did the robot last change his (8-way-)direction of facing
480 	float last_combat_step;            // when did this robot last make a step to move in closer or farther away from Tux in combat?
481 	float TextVisibleTime;
482 	s_char *TextToBeDisplayed;         // WARNING!!! Only use static texts
483 	moderately_finepoint PrivatePathway[5];
484 	uint8_t bot_stuck_in_wall_at_previous_check;
485 	float time_since_previous_stuck_in_wall_check;
486 
487 	//--------------------
488 	// Misc attributes
489 	//
490 	gps virt_pos;             // the virtual position (position of the bot if he was on this level, differs from above when it is on a neighboring level)
491 	list_head_t global_list;  // entry of this bot in the global bot lists (alive or dead)
492 	list_head_t level_list;   // entry of this bot in the level bot list (alive only)
493 } enemy, *Enemy;
494 
495 typedef struct npc {
496 	string dialog_basename;
497 	uint8_t chat_character_initialized;
498 
499 	string_dynarray enabled_nodes;
500 
501 	string shoplist[MAX_ITEMS_IN_NPC_SHOPLIST]; //list of items that can be put in the inventory of the NPC
502 	int shoplistweight[MAX_ITEMS_IN_NPC_SHOPLIST]; //weight of each item: relative probability of appearance in inventory
503 	item_dynarray npc_inventory;
504 
505 	float last_trading_date; // when did we trade with this NPC the last time?
506 
507 	list_head_t node;
508 } npc;
509 
510 typedef char automap_data_t[100][100];
511 typedef struct tux {
512 	float current_game_date;	// seconds since game start, will be printed as a different 'date'
513 	// inside the game, like 14:23 is afternoon
514 	int current_power_bonus;
515 	float power_bonus_end_date;
516 	int current_dexterity_bonus;
517 	float dexterity_bonus_end_date;
518 	float light_bonus_end_date;
519 
520 	finepoint speed;	// the current speed of the droid
521 	gps pos;		// current position in the whole ship
522 	gps teleport_anchor;	// where from have you last teleported home
523 	gps mouse_move_target;	// where the tux is going automatically by virtue of mouse move
524 
525 	short int current_enemy_target_n;	//which enemy has been targeted
526 	uint8_t god_mode;
527 	enemy *current_enemy_target_addr;	// which enemy has been targeted, address
528 
529 	int mouse_move_target_combo_action_type;	// what extra action has to be done upon arrival?
530 	int mouse_move_target_combo_action_parameter;	// extra data to use for the combo action
531 
532 	int light_bonus_from_tux;
533 	int map_maker_is_present;
534 
535 	float maxenergy;	// current top limit for the influencers energy
536 	float energy;		// current energy level
537 	float max_temperature;	// current top limit for temperature (highest is better)
538 	float temperature;	// current temperature
539 	float old_temperature;	// current temperature
540 	float max_running_power;
541 	float running_power;
542 	int running_must_rest;
543 	int running_power_bonus;
544 
545 	float health_recovery_rate;	//points of health recovered each second
546 	float cooling_rate;	//temperature points recovered each second
547 
548 	double busy_time;	// time remaining, until the weapon is ready to fire again...
549 	int busy_type;		// reason why tux is busy (enum)
550 	double phase;		// the current phase of animation
551 	float angle;
552 	float walk_cycle_phase;	//
553 	float weapon_swing_time;	// How long is the current weapon swing in progress (in seconds of course)
554 	float MissionTimeElapsed;
555 	float got_hit_time;	// how long stunned now since the last time tux got hit
556 
557 	int base_cooling;
558 	int base_dexterity;
559 	int base_physique;
560 	int base_strength;
561 	int cooling;
562 	int dexterity;
563 	int physique;
564 	int strength;
565 	int points_to_distribute;	// these are the points that are available to distribute upon the character stats
566 	float base_damage;	// the current damage the influencer does
567 	float damage_modifier;	// the modifier to the damage the influencer currently does
568 	float armor_class;
569 	float to_hit;		// percentage chance, that Tux will hit a random lv 1 bot
570 
571 	int slowing_melee_targets;	// duration for how long hit enemies are slowed down
572 	int paralyzing_melee_targets;	// duration for how long hit enemies are paralyzed
573 	float experience_factor; // multiplier for the experience gained from bots
574 
575 	unsigned int Experience;
576 	int exp_level;
577 
578 	unsigned int Gold;
579 	string character_name;
580 	mission AllMissions[MAX_MISSIONS_IN_GAME];	// What must be done to fulfill this mission?
581 	int marker;		// In case you've taken over a marked droid, this will contain the marker
582 	float LastCrysoundTime;
583 	float TextVisibleTime;
584 	s_char *TextToBeDisplayed;                    // WARNING!!! Only use static texts
585 
586 	//--------------------
587 	// Here we note all the 'skill levels' of the Tux and also which skill is
588 	// currently readied and that...
589 	//
590 	int readied_skill;
591 	int skill_level[MAX_NUMBER_OF_PROGRAMS];
592 	int melee_weapon_skill;
593 	int ranged_weapon_skill;
594 	int spellcasting_skill;
595 	//--------------------
596 	// The inventory slots.  Some items are residing in general inventory,
597 	// other items might be equipped in some of the corresponding slots of
598 	// the inventory screen.
599 	//
600 	item Inventory[MAX_ITEMS_IN_INVENTORY];
601 	item weapon_item;
602 	item drive_item;
603 	item armour_item;
604 	item shield_item;
605 	item special_item;
606 
607 	//--------------------
608 	// A record of when and if the tux has been on some maps...
609 	//
610 	uint8_t HaveBeenToLevel[MAX_LEVELS];	            // record of the levels the player has visited yet.
611 	float time_since_last_visit_or_respawn[MAX_LEVELS];	// record of the levels the player has visited yet.
612 
613 	//--------------------
614 	// THE FOLLOWING ARE INFORMATION, THAT ARE HUGE AND THAT ALSO DO NOT NEED
615 	// TO BE COMMUNICATED FROM THE CLIENT TO THE SERVER OR VICE VERSA
616 	//
617 	moderately_finepoint next_intermediate_point[MAX_INTERMEDIATE_WAYPOINTS_FOR_TUX];	// waypoints for the tux, when target not directly reachable
618 	automap_data_t Automap[MAX_LEVELS];
619 	int current_zero_ring_index;
620 	gps Position_History_Ring_Buffer[MAX_INFLU_POSITION_HISTORY];
621 
622 	int BigScreenMessageIndex;
623 	string BigScreenMessage[MAX_BIG_SCREEN_MESSAGES];
624 	float BigScreenMessageDuration[MAX_BIG_SCREEN_MESSAGES];
625 
626 	float slowdown_duration;
627 	float paralyze_duration;
628 	float invisible_duration;
629 	float nmap_duration;
630 
631 	int quest_browser_changed;
632 
633 	int program_shortcuts[10];
634 
635 	// STATISTICS ABOUT TUX
636 	// Should warn if less than Number_Of_Droid_Types + 2
637 #define NB_DROID_TYPES 50
638 	int TakeoverSuccesses[NB_DROID_TYPES]; // how many did Tux takeover and make friendly?
639 	int TakeoverFailures[NB_DROID_TYPES];  // how many did Tux fail at a takeover attempt?
640 	int destroyed_bots[NB_DROID_TYPES];    // how many bots have been destroyed?
641 	int damage_dealt[NB_DROID_TYPES];      // how much damage dealt?
642 	float meters_traveled;     // how many meters has Tux traveled?
643 } tux_t;
644 
645 typedef struct bulletspec {
646 	char *name;		// what is the name of this bullet type
647 	char *sound;		// what sound to play
648 	int phases;		// how many phases in motion to show
649 	double phase_changes_per_second;	// how many different phases to display every second
650 	int blast_type;
651 	struct image image[BULLET_DIRECTIONS][MAX_PHASES_IN_A_BULLET];
652 } bulletspec;
653 
654 typedef struct bullet {
655 	short int type;
656 	int phase;
657 	uint8_t mine;
658 	gps pos;
659 	int height;
660 	moderately_finepoint speed;
661 	short int damage;	// damage done by this particular bullet
662 	float time_in_seconds;	// how long does the bullet exist in seconds
663 	float bullet_lifetime;	// how long can this bullet exist at most
664 	short int owner;
665 	float angle;
666 
667 	uint8_t pass_through_hit_bodies; // does this bullet go through hit bodies (e.g. like a laser sword strike)
668 	short int freezing_level;	// does this bullet freeze the target?
669 	float poison_duration;
670 	float poison_damage_per_sec;
671 	float paralysation_duration;
672 
673 	int faction;
674 	uint8_t hit_type;		//hit bots, humans, both?
675 } bullet, *Bullet;
676 
677 typedef struct melee_shot	// this is a melee shot
678 {
679 	uint8_t attack_target_type;	//type of attack
680 	uint8_t mine;		//is it mine?
681 	short int bot_target_n;	//which enemy has been targeted
682 	enemy *bot_target_addr;	// which enemy has been targeted, address
683 	short int to_hit;	//chance to hit, percent
684 	short int damage;
685 	short int owner;
686 	float time_to_hit;	//Time until the 'shot' makes contact
687 } melee_shot;
688 
689 typedef struct blastspec {
690 	int phases;
691 	float total_animation_time;
692 	int do_damage;
693 	struct image *images;
694 	char *name;
695 	string sound_file;
696 } blastspec;
697 
698 typedef struct blast {
699 	gps pos;
700 	int type;
701 	float phase;
702 	float damage_per_second;
703 	int faction;
704 } blast;
705 
706 typedef struct spell_active {
707 	int img_type;		// what type of spell is active?
708 	int damage;
709 	int poison_duration;
710 	int poison_dmg;
711 	int freeze_duration;
712 	int paralyze_duration;
713 	moderately_finepoint spell_center;
714 	float spell_radius;
715 	float spell_age;
716 	uint8_t active_directions[RADIAL_SPELL_DIRECTIONS];
717 	int mine;
718 	uint8_t hit_type;
719 } spell_active;
720 
721 typedef struct spell_skill_spec {
722 	char *name;
723 	char *icon_name;
724 	struct image icon_surface;
725 	short heat_cost;
726 	short heat_cost_per_level;
727 	int damage_base;
728 	int damage_mod;
729 	short damage_per_level;
730 	short hurt_bots;
731 	short hurt_humans;
732 	short form;
733 	char present_at_startup;
734 	char *description;
735 	char *effect;
736 	float effect_duration;
737 	float effect_duration_per_level;
738 	int graphics_code;
739 } spell_skill_spec;
740 
741 typedef struct waypoint {
742 	int x;
743 	int y;
744 	int suppress_random_spawn;
745 	struct dynarray connections;
746 } waypoint;
747 
748 typedef struct obstacle {
749 	int type;
750 	gps pos;
751 	int timestamp;
752 	int frame_index;
753 } obstacle;
754 
755 typedef struct volatile_obstacle {
756 	obstacle obstacle;
757 	float vanish_timeout;
758 	list_head_t volatile_list;
759 } volatile_obstacle;
760 
761 typedef struct map_tile {
762 	Uint16 floor_values[MAX_FLOOR_LAYERS];
763 	struct dynarray glued_obstacles;
764 	list_head_t volatile_obstacles;
765 	int timestamp;
766 } map_tile;
767 
768 struct obstacle_extension {
769 	obstacle *obs;
770 	enum obstacle_extension_type type;
771 	void *data;
772 }; /** This contains "extension data" for obstacles - labels, item lists, ... */
773 
774 typedef struct level {
775 	int levelnum;
776 	int xlen;
777 	int ylen;
778 	int light_bonus;
779 	int minimum_light_value;
780 	int infinite_running_on_this_level;
781 	int random_dungeon;
782 	int dungeon_generated;
783 	char *Levelname;
784 	char *Background_Song_Name;
785 
786 	short int drop_class;
787 
788 	int floor_layers;
789 	map_tile *map[MAX_MAP_LINES];	// this is a vector of pointers
790 	int jump_target_north;
791 	int jump_target_south;
792 	int jump_target_east;
793 	int jump_target_west;
794 
795 	obstacle obstacle_list[MAX_OBSTACLES_ON_MAP];
796 	item ItemList[MAX_ITEMS_PER_LEVEL];
797 
798 	struct dynarray obstacle_extensions;
799 	struct dynarray map_labels;
800 	struct dynarray waypoints;
801 	struct {
802 		int nr;
803 		int types[10];
804 		int types_size;
805 	} random_droids;
806 
807 	int teleport_pair;
808 	int flags;
809 } level, *Level;
810 
811 typedef void (*action_fptr) (level *obst_lvl, int obstacle_idx);
812 typedef int (*animation_fptr) (level *obst_lvl, void *);
813 
814 struct obstacle_graphics {
815 	int count;
816 	struct image *images;
817 	struct image *shadows;
818 };
819 
820 typedef struct obstacle_spec {
821 	char *name;
822 
823 	char *label;
824 
825 	//--------------------
826 	// Some obstacles will block the Tux from walking through them.
827 	// Currently only rectangles are supported block areas.  The width
828 	// (i.e. east-west=parm1) and height (i.e. north-south=parm2) of
829 	// the blocking rectangle can ge specified below.
830 	//
831 	float block_area_parm_1;
832 	float block_area_parm_2;
833 	float left_border;
834 	float right_border;
835 	float upper_border;
836 	float lower_border;
837 
838 	float diaglength;
839 
840 	char block_area_type;
841 	int result_type_after_smashing_once;
842 	int result_type_after_looting;
843 
844 	unsigned int flags;
845 
846 	//--------------------
847 	// Some obstacles will emit light.  Specify light strength here.
848 	// A value of 0 light will be sufficient in most cases...
849 	//
850 	struct dynarray emitted_light_strength;
851 	char transparent;
852 
853 	struct dynarray filenames;
854 	char *action;
855 	action_fptr action_fn;
856 
857 	//--------------------
858 	// Some obstacles have an associated animation.
859 	// This property defines the function to call to animate them
860 	animation_fptr animation_fn;
861 	float animation_fps;
862 
863 	//-----------------------
864 	// Some obstacles have a different sounds / blast animations
865 	// these properties allow us to define a specific sound or blast for
866 	// a given obstacle
867 	unsigned int blast_type;
868 	char *smashed_sound;
869 
870 	//-----------------------
871 	// Some obstacles are volatiles, and vanishes after some seconds
872 	float vanish_delay;     // Start to vanish after 'delay' seconds
873 	float vanish_duration;  // Number of seconds needed to disappear (after the 'delay')
874 } obstacle_spec;
875 
876 struct obstacle_group {
877 	const char *name;
878 	struct dynarray members;
879 };
880 
881 struct floor_tile_spec {
882 	int frames;	// More than 1 for animated floor tiles
883 	struct dynarray filenames;
884 	struct image *images;
885 	struct image *current_image;
886 
887 	// Properties for animated floor tiles
888 	animation_fptr animation_fn;
889 	float animation_fps;
890 };
891 
892 struct visible_level {
893 	int valid;
894 	level *lvl_pointer;
895 	float boundary_squared_dist;
896 	struct list_head animated_obstacles_list;
897 	int animated_obstacles_dirty_flag;
898 	struct list_head node;
899 };
900 
901 typedef struct ship {
902 	int num_levels;
903 	level *AllLevels[MAX_LEVELS];
904 } ship;
905 
906 typedef struct colldet_filter {
907 	int (*callback) (struct colldet_filter *filter, obstacle *obs, int obs_idx);
908 	void *data;
909 	float extra_margin;
910 	struct colldet_filter *next;
911 } colldet_filter;
912 
913 typedef struct light_radius_config {
914 	uint32_t cells_w;
915 	uint32_t cells_h;
916 	uint32_t texture_w;
917 	uint32_t texture_h;
918 	int translate_y;
919 	float scale_factor;
920 } light_radius_config;
921 
922 typedef struct screen_resolution {
923 	int xres;
924 	int yres;
925 	char *comment;
926 	int supported;
927 } screen_resolution;
928 
929 /*
930  * [way|location]_free_of_droids's execution context
931  *
932  * Note : '2' excepted bots are needed when the pathfinder is called
933  *         to let a bot reach an other one (used during attack, for example).
934  */
935 typedef struct freeway_context {
936 	int check_tux;		// Check if Tux is along the way
937 	Enemy except_bots[2];	// Do not check if those bots are along the way (see note below)
938 } freeway_context;
939 
940 /*
941  * Pathfinder's execution context
942  */
943 typedef struct pathfinder_context {
944 	colldet_filter *dlc_filter;	// DLC filter to use
945 	freeway_context *frw_ctx;	// [way|location]_free_of_droids's execution context to use
946 	int timestamp;
947 } pathfinder_context;
948 
949 typedef struct {
950 	int shop_command;
951 	int item_selected;
952 	int number_selected;
953 } shop_decision;
954 
955 struct auto_string {
956 	char *value;
957 	unsigned long length;
958 	unsigned long capacity;
959 };
960 
961 /*
962  * Specification of Animations
963  */
964 
965 struct timebased_animation {
966 	float duration;			// Duration of the animation
967 	int first_keyframe;
968 	int last_keyframe;
969 	int nb_keyframes;		// Set to (last - first). Avoid to compute it each time this information is needed
970 };
971 
972 struct distancebased_animation {
973 	float distance;			// Distance covered during the whole animation
974 	int first_keyframe;
975 	int last_keyframe;
976 	int nb_keyframes;		// Set to (last - first). Avoid to compute it each time this information is needed
977 };
978 
979 /**
980  * Specification of Tux's parts rendering data
981  * Pointers to data needed to render one given Tux' part
982  */
983 struct tux_part_render_data {
984 	char *name;                      // Name of the part (used as a key of the struct)
985 	char **default_part_instance;    // Pointer to one of the tuxrendering.default_instances
986 	item *wearable_item;             // Pointer to one of the Me.XXXX_item
987 	int part_group;                  // One of the PART_GROUP_XXXX values
988 };
989 
990 /**
991  * Specification of Tux's parts rendering order
992  * Defines how to order Tux's parts for a 'set' of animation phases.
993  * A linked list of sets is associated to a (motion_class, rotation) pair
994  * (see the definition of struct tux_rendering_s in global.h).
995  */
996 struct tux_part_render_set {
997 	int phase_start;	// First animation phase of the set
998 	int phase_end;		// Last animation phase of the set
999 	struct tux_part_render_data *part_render_data[ALL_PART_GROUPS];	// Ordered array of the data needed to render Tux parts
1000 	struct tux_part_render_set *next;
1001 };
1002 typedef struct tux_part_render_set *tux_part_render_motionclass[MAX_TUX_DIRECTIONS];
1003 
1004 /**
1005  * Contains the prefix of the animation archive files needed to render
1006  * each Tux's part.
1007  */
1008 struct tux_part_instances {
1009 	char *head;
1010 	char *torso;
1011 	char *weaponarm;
1012 	char *weapon;
1013 	char *shieldarm;
1014 	char *feet;
1015 };
1016 
1017 /**
1018  * Contains all the informations needed to render Tux
1019  */
1020 struct tux_rendering {
1021 	struct dynarray motion_class_names;             // All motion classes
1022 	struct tux_part_instances default_instances;    // Default part instances
1023 	tux_part_render_motionclass *render_order;      // The render_sets of each motion class
1024 	int gun_muzzle_height;							// Vertical offset to apply to bullets
1025 } tux_rendering;
1026 
1027 /**
1028  * Contains a set of Tux's parts images for a motion class.
1029  */
1030 struct tux_motion_class_images {
1031 	struct image part_images[ALL_PART_GROUPS][TUX_TOTAL_PHASES][MAX_TUX_DIRECTIONS];
1032 	char part_names[ALL_PART_GROUPS][64];
1033 };
1034 
1035 /**
1036  * Holds all variables needed to run a chat
1037  */
1038 struct lua_coroutine {
1039 	lua_State *thread;
1040 	int nargs;
1041 };
1042 
1043 struct chat_context {
1044 	enum chat_context_state state;  // current state of the chat engine.
1045 	int wait_user_click;            // TRUE if the chat engine is waiting for a user click.
1046 	enemy *partner;                 // The bot we are talking with.
1047 	struct npc *npc;                // The NPC containing the specifications of the dialog to run.
1048 	int partner_started;            // TRUE if the dialog was started by the partner.
1049 	int end_dialog;                 // TRUE if a dialog lua script asked to end the dialog.
1050 
1051 	int current_option;             // Current dialog node to run (-1 if none is selected)
1052 	struct lua_coroutine *script_coroutine;	// Handle to the lua co-routine running the current node script
1053 
1054 	struct list_head stack_node;    // Used to create a stack of chat_context.
1055 };
1056 
1057 struct langspec {
1058 	char *name;
1059 	char *locale;
1060 };
1061 
1062 struct codeset {
1063 	char *language;
1064 	char *encoding;
1065 };
1066 
1067 struct title_screen {
1068 	char *background;
1069 	char *song;
1070 	char *text;
1071 };
1072 
1073 struct data_dir {
1074 	const char *name;
1075 	char path[PATH_MAX];
1076 };
1077 
1078 struct difficulty {
1079 	float droid_max_speed;
1080 	float droid_hpmax;
1081 	float droid_hostile_healing;
1082 	float droid_friendly_healing;
1083 	float droid_experience_reward;
1084 	float droid_aggression_distance;
1085 };
1086 
1087 #endif
1088