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  *  This file is part of Freedroid
8  *
9  *  Freedroid is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  Freedroid is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with Freedroid; see the file COPYING. If not, write to the
21  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  *  MA  02111-1307  USA
23  *
24  */
25 #ifndef _proto_h
26 #define _proto_h
27 
28 #include "struct.h"
29 #include "lua.h"
30 #include "BFont.h"
31 
32 #ifdef __GNUC__
33 #define PRINTF_FMT_ATTRIBUTE(fmt,firstarg) __attribute__ ((format(printf,fmt,firstarg)));
34 #else
35 #define PRINTF_FMT_ATTRIBUTE(fmt,firstarg)
36 #endif
37 
38 // main.c
39 void Game(void);
40 
41 // automap.c
42 void display_automap(void);
43 void toggle_automap(void);
44 void CollectAutomapData(void);
45 void update_obstacle_automap(int z, obstacle *our_obstacle);
46 
47 // init.c
48 void prepare_execution(int, char **);
49 void ResetGameConfigToDefaultValues(void);
50 void clear_out_arrays_for_fresh_game(void);
51 void next_startup_percentage(int Percentage);
52 void ParseCommandLine(int argc, char *const argv[]);
53 void ClearAutomapData(void);
54 void InitFreedroid(int, char **);
55 void PrepareStartOfNewCharacter(char *startpos);
56 void prepare_level_editor(void);
57 void ThouArtDefeated(void);
58 void ThouHastWon(void);
59 void PlayATitleFile(char *Filename);
60 
61 // event.c
62 void GetEventTriggers(const char *EventsAndEventTriggersFilename);
63 void event_position_changed(gps pos, int teleport);
64 void event_level_changed(int past_lvl, int cur_lvl);
65 void event_enemy_died(enemy *dead);
66 void event_enemy_hacked(enemy *hacked);
67 void event_obstacle_action(obstacle *o);
68 const char *teleporter_square_below_mouse_cursor(void);
69 struct event_trigger * visible_event_at_location(int x, int y, int z);
70 void delete_events(void);
71 int validate_events(void);
72 
73 // lua.c
74 void init_lua(void);
75 void close_lua(void);
76 int lua_to_int(lua_Integer);
77 short lua_to_short(lua_Integer);
78 lua_State *get_lua_state(enum lua_target);
79 struct lua_coroutine *prepare_lua_coroutine(enum lua_target, const char *, const char *, const char *, ...);
80 struct lua_coroutine *load_lua_coroutine(enum lua_target, const char *);
81 int resume_lua_coroutine(struct lua_coroutine *);
82 int run_lua(enum lua_target, const char *);
83 void run_lua_file(enum lua_target, const char *);
84 void set_lua_ctor_upvalue(enum lua_target, const char *, void *);
85 int call_lua_func(enum lua_target, const char *, const char *, const char *, const char *, ...);
86 void reset_lua_state(void);
87 void write_lua_variables(struct auto_string *);
88 
89 // luaconfig.c
90 void init_luaconfig(void);
91 void lua_end_skill_init(void);
92 
93 // influ.c
94 float calc_distance(float pos1_x, float pos1_y, float pos2_x, float pos2_y);
95 float vect_len(moderately_finepoint our_vector);
96 enemy *GetLivingDroidBelowMouseCursor(void);
97 void tux_wants_to_attack_now(int use_mouse_cursor_for_targeting);
98 int perform_tux_attack(int use_mouse_cursor_for_targeting);
99 void TuxReloadWeapon(void);
100 void correct_tux_position_according_to_jump(void);
101 void InitInfluPositionHistory(void);
102 float GetInfluPositionHistoryX(int Index);
103 float GetInfluPositionHistoryY(int Index);
104 float GetInfluPositionHistoryZ(int Index);
105 void bullet_init(bullet *, int, short int);
106 void perform_tux_ranged_attack(short int, bullet *, moderately_finepoint);
107 void move_tux(void);
108 void hit_tux(float);
109 void animate_tux(void);
110 void check_tux_enemy_collision(void);
111 void start_tux_death_explosions(void);
112 void init_tux(void);
113 void set_movement_with_keys(int move_x, int move_y);
114 void do_death_menu(void);
115 void free_tux();
116 
117 // action.c
118 void chest_open_action(level *chest_lvl, int chest_index);
119 void barrel_action(level *barrel_lvl, int barrel_index);
120 void terminal_connect_action(level *, int);
121 void sign_read_action(level *sign_lvl, int sign_index);
122 int clickable_obstacle_below_mouse_cursor(level **, int);
123 int check_for_items_to_pickup(level *item_lvl, int item_index);
124 action_fptr get_action_by_name(const char *action_name);
125 
126 // pathfinder.c
127 int set_up_intermediate_course_between_positions(gps * curpos, moderately_finepoint * move_target, moderately_finepoint * waypoints,
128 						 int maxwp, pathfinder_context * ctx);
129 void clear_out_intermediate_points(gps *, moderately_finepoint *, int);
130 
131 // bullet.c
132 void RotateVectorByAngle(moderately_finepoint * vector, float rot_angle);
133 void MoveBullets(void);
134 void DoMeleeDamage(void);
135 void DeleteBullet(int num, int StartBlast);
136 void StartBlast(float, float, int, int, int, int, char *);
137 void animate_blasts(void);
138 void DeleteBlast(int num);
139 int get_blast_type_by_name(const char *name);
140 void MoveActiveSpells(void);
141 void DeleteSpell(int num);
142 void clear_active_spells(void);
143 void clear_active_bullets(void);
144 void CheckBulletCollisions(int num);
145 void CheckBlastCollisions(int num);
146 int find_free_bullet_index(void);
147 void bullet_init_for_player(struct bullet *, int, short int);
148 void bullet_init_for_enemy(struct bullet *, int, short int, struct enemy*);
149 int find_free_melee_shot_index(void);
150 void delete_melee_shot(melee_shot *);
151 int GetBulletByName(const char *bullet_name);
152 
153 // view.c
154 void get_floor_boundaries(int, int *, int *, int *, int *);
155 void gps_transform_map_init(void);
156 void update_virtual_position(gps * target_pos, gps * source_pos, int level_num);
157 int resolve_virtual_position(gps * actual_pos, gps * virtual_pos);
158 int pos_inside_level(float x, float y, level * lvl);
159 int pos_near_level(float x, float y, level * lvl, float dist);
160 void set_up_ordered_blitting_list(int mask);
161 void blit_preput_objects_according_to_blitting_list(int mask);
162 void blit_nonpreput_objects_according_to_blitting_list(int mask);
163 void draw_grid_on_the_floor(int mask);
164 void blit_leveleditor_point(int x, int y);
165 void update_item_text_slot_positions(void);
166 void AssembleCombatPicture(int);
167 void blit_tux(int x, int y);
168 struct tux_part_render_data *tux_get_part_render_data(char *part_name);
169 void tux_rendering_load_specs(const char *config_filename);
170 void PutBullet(int Bullet_number, int mask);
171 void PutItem(item *CurItem, int mask, int put_thrown_items_flag, int highlight_item);
172 void PutBlast(int);
173 void PutEnemy(enemy * e, int x, int y, int mask, int highlight);
174 void PutMouseMoveCursor(void);
175 int set_rotation_index_for_this_robot(enemy * ThisRobot);
176 int set_rotation_model_for_this_robot(enemy * ThisRobot);
177 int level_is_visible(int level_num);
178 void get_visible_levels(void);
179 void reset_visible_levels(void);
180 void PutIndividuallyShapedDroidBody(enemy *, SDL_Rect, int, int);
181 void object_vtx_color(void *, float *, float *, float *);
182 int get_motion_class_id_by_name(char *);
183 char *get_motion_class_name_by_id(int);
184 int get_motion_class_id(void);
185 void show_inventory_screen(void);
186 
187 // The BROWSE_VISIBLE_LEVELS macro will loop on each valid visible levels.
188 // It is based on the list_for_each_entry_safe() macro.
189 // However, some entries in the visible_level_list are marked as not "valid",
190 // and such levels have to be ignored during the call to the macro.
191 // So, in the 'update part' of the 'for' statement we have to advance the ptr
192 // *until* a valid entry is found. Thus, a loop (i.e. a compound-statement) is
193 // needed.
194 // However, the 'update part' of a 'for' statement has to be an 'expression'.
195 // Thanks to gcc (this is not part of the C99 standard), it is possible to
196 // transform a compound statement into an expression, with the
197 // "({compound-statement;})" construct.
198 // To ease readiness, the loop is defined in a next_valid_visible_level() macro.
199 // This loop is also used in the 'initialization part' of the 'for' statement,
200 // to reach the first valid entry.
201 
202 #define next_valid_visible_level(pos, start) ({ \
203 	pos = start; \
204 	while (&pos->node != &visible_level_list && !pos->valid) \
205 		pos = list_entry(pos->node.next, typeof(*pos), node); \
206 	})
207 
208 #define BROWSE_VISIBLE_LEVELS(pos, n) \
209 	for (next_valid_visible_level(pos, list_entry(visible_level_list.next, typeof(*pos), node)), \
210 		n = list_entry(pos->node.next, typeof(*pos), node) ; \
211 		&pos->node != (&visible_level_list) ; \
212 		next_valid_visible_level(pos, n), n = list_entry(pos->node.next, typeof(*pos), node))
213 
214 // The BROWSE_NEARBY_VISIBLE_LEVELS macro will loop on each valid visible levels,
215 // if one of their boundary is at a distance less than 'd'.
216 // It uses the same trick than the BROWSE_VISIBLE_LEVELS() macro.
217 
218 #define next_valid_nearby_visible_level(pos, start, d) ({ \
219 	pos = start; \
220 	while (&pos->node != &visible_level_list && (!pos->valid || pos->boundary_squared_dist>=d)) \
221 		pos = list_entry(pos->node.next, typeof(*pos), node); \
222 	})
223 
224 #define BROWSE_NEARBY_VISIBLE_LEVELS(pos, n, d) \
225 	for (next_valid_nearby_visible_level(pos, list_entry(visible_level_list.next, typeof(*pos), node), d), \
226 		n = list_entry(pos->node.next, typeof(*pos), node) ; \
227 		&pos->node != (&visible_level_list) ; \
228 		next_valid_nearby_visible_level(pos, n, d), n = list_entry(pos->node.next, typeof(*pos), node))
229 
230 // The BROWSE_LEVELS loops on all levels, skipping missing one.
231 // Same trick than the two macros just above, plus an other one:
232 // An index is needed to loop on the curShip.ALLLevels array.
233 // That index (an integer) has to be declared by the macro, but has to be
234 // unique for each use of the macro.
235 // We use the __COUNTER__ cpp macro to get a unique value, and concatenate it
236 // to create '_CRYPTIC_0_NAME_0', '_CRYPTIC_1_NAME_1', '_CRYPTIC_2_NAME_2'...
237 // (those cryptic names are used to minimize the chance of a name collision)
238 // Due to the way cpp works, this has to be done in 3 steps:
239 // BROWSE_LEVELS() creates a COUNTER value, used several times by BROWSE_LEVELS_IMPL()
240 // to create a unique name through the call to CRYPTICNAME().
241 // CRYPTICNAME() is needed because cpp applies concatenation before to resolves __COUNTER__
242 
243 #define next_valid_level(i, start) ({ \
244 	i = start; \
245 	while (i < curShip.num_levels && curShip.AllLevels[i] == NULL) \
246 		i++; \
247 	})
248 
249 #define CRYPTICNAME(counter) _CRYPTIC_ ## counter ## _NAME_ ## counter
250 
251 #define BROWSE_LEVELS_IMPL(lvl, counter) \
252 	int CRYPTICNAME(counter); \
253 	for (next_valid_level(CRYPTICNAME(counter), 0), lvl = curShip.AllLevels[CRYPTICNAME(counter)] ; \
254 	     CRYPTICNAME(counter) < curShip.num_levels ; \
255 	     next_valid_level(CRYPTICNAME(counter), CRYPTICNAME(counter)+1), lvl = curShip.AllLevels[CRYPTICNAME(counter)])
256 
257 #define BROWSE_LEVELS(lvl) BROWSE_LEVELS_IMPL(lvl, __COUNTER__)
258 
259 // light.c
260 void LightRadiusInit(void);
261 void LightRadiusClean(void);
262 int get_light_strength_screen(int x, int y);
263 int get_light_strength_cell(uint32_t x, uint32_t y);
264 void update_light_list(void);
265 void blit_light_radius(void);
266 
267 // open_gl.c
268 int our_SDL_flip_wrapper(void);
269 void our_SDL_update_rect_wrapper(SDL_Surface * screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h);
270 void drawIsoEnergyBar(int x, int y, int z, int w, int d, int length, float fill, myColor * c1, myColor * c2);
271 
272 SDL_Surface *our_IMG_load_wrapper(const char *file);
273 void flip_image_vertically(SDL_Surface * tmp1);
274 void make_texture_out_of_surface(struct image *our_image);
275 void blit_open_gl_stretched_texture_light_radius(int decay_x, int decay_y);
276 void gl_draw_rectangle(SDL_Rect *, int, int, int, int);
277 int safely_initialize_our_default_open_gl_parameters(void);
278 void blit_background(const char *background);
279 void set_gl_clip_rect(const SDL_Rect *clip);
280 void unset_gl_clip_rect(void);
281 
282 // open_gl_debug.c
283 int init_opengl_debug();
284 void open_gl_check_error_status(const char *name_of_calling_function);
285 
286 // blocks.c
287 void iso_load_bullet_surfaces(void);
288 void Load_Mouse_Move_Cursor_Surfaces(void);
289 void LoadAndPrepareEnemyRotationModelNr(int RotationModel);
290 void free_enemy_graphics(void);
291 void Load_Enemy_Surfaces(void);
292 void Load_Blast_Surfaces(void);
293 void load_floor_tiles(void);
294 void free_floor_tiles(void);
295 struct image *get_obstacle_image(int, int);
296 struct image *get_obstacle_shadow_image(int, int);
297 struct image *get_map_label_image(void);
298 struct image *get_droid_portrait_image(int);
299 void load_all_obstacles(int with_startup_bar);
300 void free_obstacle_graphics(void);
301 struct image *get_item_shop_image(int type);
302 struct image *get_item_ingame_image(int type);
303 struct image *get_item_inventory_image(int type);
304 void load_all_items(void);
305 void free_item_graphics(void);
306 void load_tux_graphics(int motion_class, int tux_part_group, const char *part_string);
307 void reload_tux_graphics(void);
308 void get_offset_for_iso_image_from_file_and_path(const char *fpath, struct image * our_iso_image);
309 
310 // graphics.c
311 void blit_mouse_cursor(void);
312 void fade_out_screen(void);
313 void fade_in_screen(void);
314 void InitPictures(void);
315 void init_timer(void);
316 void InitVideo(void);
317 void HighlightRectangle(SDL_Surface * Surface, SDL_Rect Area);
318 void ShadowingRectangle(SDL_Surface * Surface, SDL_Rect Area);
319 int do_graphical_number_selection_in_range(int lower_range, int upper_range, int default_value, int unit_price);
320 void draw_line(float x1, float y1, float x2, float y2, uint8_t r, uint8_t g, uint8_t b, int glwidth);
321 void draw_line_on_map(float x1, float y1, float x2, float y2, uint8_t r, uint8_t g, uint8_t b, int width);
322 void sdl_draw_rectangle(SDL_Rect *rect, int r, int g, int b, int a);
323 SDL_Surface *sdl_create_colored_surface(SDL_Surface *surf, float r, float g, float b, float a, int highlight);
324 void draw_rectangle(SDL_Rect *rect, int r, int g, int b, int a);
325 void draw_quad(const int16_t vx[4], const int16_t vy[4], int r, int g, int b, int a);
326 uint32_t sdl_get_pixel(SDL_Surface *surf, int x, int y);
327 void sdl_put_pixel(SDL_Surface *surf, int x, int y, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
328 void save_screenshot(const char *filename, int width);
329 void reload_graphics(void);
330 void clear_screen(void);
331 
332 // saveloadgame.c
333 int find_saved_games(struct dirent ***);
334 void LoadAndShowThumbnail(char *CoreFilename);
335 int SaveGame(void);
336 int load_backup_game(void);
337 int load_game(void);
338 int DeleteGame(void);
339 void LoadAndShowStats(char *CoreFilename);
340 
341 // mission.c
342 void CompleteMission(const char *);
343 void AssignMission(const char *);
344 void GetQuestList(char *QuestListFilename);
345 void clear_tux_mission_info(void);
346 void CheckIfMissionIsComplete(void);
347 void mission_diary_add(const char *, const char *);
348 int GetMissionIndexByName(const char *);
349 
350 // quest_browser_ui.c
351 void toggle_quest_browser(void);
352 struct widget_group *create_quest_browser(void);
353 
354 // map.c
355 void init_map_tile(struct map_tile*);
356 void respawn_level(int level_num);
357 gps get_map_label_center(const char *);
358 int smash_obstacle(float, float, int);
359 Uint16 get_map_brick(level *, float, float, int);
360 void CountNumberOfDroidsOnShip(void);
361 void free_current_ship();
362 void free_ship_level(level*);
363 int LoadShip(char *filename, int);
364 int SaveShip(const char *filename, int reset_random_levels, int);
365 int save_special_forces(const char *filename);
366 int GetCrew(char *shipname);
367 moderately_finepoint translate_point_to_map_location(float axis_x, float axis_y, int zoom_is_on);
368 
369 int IsVisible(gps *objpos);
370 #define translate_map_point_to_screen_pixel translate_map_point_to_screen_pixel_func
371 #define translate_map_point_to_screen_pixel_x(X,Y)  ( UserCenter_x + ceilf((X)*iso_floor_tile_width_over_two) - ceilf((Y)*iso_floor_tile_width_over_two) \
372 		                                                           + ceilf(Me.pos.y*iso_floor_tile_width_over_two) - ceilf(Me.pos.x*iso_floor_tile_width_over_two) )
373 #define translate_map_point_to_screen_pixel_y(X,Y)  ( UserCenter_y + ceilf((X)*iso_floor_tile_height_over_two) + ceilf((Y)*iso_floor_tile_height_over_two) \
374 		                                                           - ceilf(Me.pos.x*iso_floor_tile_height_over_two) - ceilf(Me.pos.y*iso_floor_tile_height_over_two) )
375 void translate_map_point_to_screen_pixel_func(float x_map_pos, float y_map_pos, int *x_res, int *y_res);
376 float translate_pixel_to_map_location(float axis_x, float axis_y, int give_x);
377 float translate_pixel_to_zoomed_map_location(float axis_x, float axis_y, int give_x);
378 
379 //floor_tiles.c
380 int next_pathfinder_timestamp(void);
381 int next_glue_timestamp(void);
382 void free_glued_obstacles(level *lvl);
383 struct image *get_floor_tile_image(int floor_value);
384 
385 //colldet.c
386 int WalkablePassFilterCallback(colldet_filter * this, obstacle * obs, int obs_idx);
387 int FlyablePassFilterCallback(colldet_filter * this, obstacle * obs, int obs_idx);
388 int VisiblePassFilterCallback(colldet_filter * this, obstacle * obs, int obs_idx);
389 int ObstacleByIdPassFilterCallback(colldet_filter * this, obstacle * obs, int obs_idx);
390 int location_free_of_droids(float x, float y, int levelnum, freeway_context *ctx);
391 int way_free_of_droids(float x1, float y1, float x2, float y2, int OurLevel, freeway_context * ctx);
392 int EscapeFromObstacle(float *posX, float *posY, int posZ, colldet_filter * filter);
393 int SinglePointColldet(float x, float y, int z, colldet_filter * filter);
394 int DirectLineColldet(float x1, float y1, float x2, float y2, int z, colldet_filter * filter);
395 int normalize_vect(float, float, float *, float *);
396 
397 // sound.c
398 void init_audio(void);
399 void close_audio(void);
400 void set_music_volume(float);
401 void set_SFX_volume(float);
402 void switch_background_music(char *);
403 int play_sound(const char *);
404 void play_sound_v(const char *, float);
405 void play_sound_at_position(const char *, struct gps *, struct gps *);
406 
407 // sound_effects.c
408 void tux_scream_sound(void);
409 void No_Ammo_Sound(void);
410 void Not_Enough_Power_Sound(void);
411 void Not_Enough_Dist_Sound(void);
412 void CantCarrySound(void);
413 void MenuItemSelectedSound(void);
414 void MenuItemDeselectedSound(void);
415 void MoveMenuPositionSound(void);
416 void teleport_arrival_sound(void);
417 void fire_bullet_sound(int BulletType, struct gps *shooter_pos);
418 void play_blast_sound(char *blast_sound, struct gps *blast_pos);
419 void ThouArtDefeatedSound(void);
420 void Takeover_Set_Capsule_Sound(void);
421 void Takeover_Game_Won_Sound(void);
422 void Takeover_Game_Deadlock_Sound(void);
423 void Takeover_Game_Lost_Sound(void);
424 void play_greeting_sound(enemy *ThisRobot);
425 void play_enter_attack_run_state_sound(enemy *ThisRobot);
426 void play_death_sound_for_bot(enemy * ThisRobot);
427 void play_item_sound(int item_type, struct gps *item_pos);
428 void BulletReflectedSound(void);
429 void Play_Spell_ForceToEnergy_Sound(void);
430 void play_melee_weapon_hit_something_sound(void);
431 void play_melee_weapon_missed_sound(struct gps *attacker_pos);
432 void play_open_chest_sound(void);
433 
434 // items.c
435 void init_item(item *);
436 item create_item_with_id(const char *item_id, int full_durability, int multiplicity);
437 void equip_item(item *new_item);
438 item *get_equipped_item_in_slot_for(int item_type);
439 void MoveItem(item * SourceItem, item * DestItem);
440 int CountItemtypeInInventory(int Itemtype);
441 void DeleteInventoryItemsOfType(int Itemtype, int amount);
442 void DeleteOneInventoryItemsOfType(int Itemtype);
443 void DamageItem(item * CurItem);
444 void DamageWeapon(item * CurItem);
445 int GetFreeInventoryIndex(void);
446 int ItemCanBeDroppedInInv(int ItemType, int InvPos_x, int InvPos_y);
447 unsigned long calculate_item_buy_price(item * BuyItem);
448 unsigned long calculate_item_repair_price(item * repair_item);
449 unsigned long calculate_item_sell_price(item * BuyItem);
450 void FillInItemProperties(item *it, int full_durability, int multiplicity);
451 void DamageProtectiveEquipment(void);
452 void append_item_name(item *ShowItem, struct auto_string *str);
453 item *DropItemAt(int, int, float, float, int);
454 void Quick_ApplyItem(int ItemKey);
455 int item_spec_eq_id(int type, const char *id);
456 int get_item_type_by_id(const char *id);
457 void apply_item(item * CurItem);
458 int Inv_Pos_Is_Free(int x, int y);
459 int GetInventoryItemAt(int x, int y);
460 int ItemUsageRequirementsMet(item * UseItem, int MakeSound);
461 int MouseCursorIsInInventoryGrid(int x, int y);
462 int MouseCursorIsInUserRect(int x, int y);
463 int MouseCursorIsInInvRect(int x, int y);
464 int MouseCursorIsInChaRect(int x, int y);
465 int MouseCursorIsInSkiRect(int x, int y);
466 int GetInventorySquare_x(int x);
467 int GetInventorySquare_y(int x);
468 void DropHeldItemToInventory(void);
469 item *drop_item(item *, float, float, int);
470 void HandleInventoryScreen(void);
471 int try_give_item(item *it);
472 int give_item(item *);
473 void CopyItem(item * SourceItem, item * DestItem);
474 void DeleteItem(item * Item);
475 void DropRandomItem(int level_num, float x, float y, int class, int ForceMagical);
476 int get_floor_item_index_under_mouse_cursor(level **item_lvl);
477 int item_is_currently_equipped(item * Item);
478 enum slot_type get_slot_type_by_name(char *name);
479 const char *item_specs_get_name(int type);
480 enum _busytype get_busy_type_by_name(char *name);
481 
482 // item_upgrades.c
483 void create_upgrade_socket(item *, int, const char *);
484 void delete_upgrade_sockets(item *);
485 void copy_upgrade_sockets(item *, item *);
486 int item_can_be_customized(item *);
487 int item_can_be_installed_to_socket(item *, item *, int);
488 struct addon_spec *get_addon_spec(int);
489 struct dynarray *get_addon_specs(void);
490 void add_addon_spec(struct addon_spec *);
491 void get_item_bonus_string(item *, const char *, struct auto_string *);
492 void print_addon_description(struct addon_spec *, struct auto_string *);
493 void calculate_item_bonuses(item *);
494 int count_used_sockets(item *);
495 int item_upgrade_ui_visible(void);
496 
497 // character.c
498 unsigned int get_experience_required(int);
499 void UpdateAllCharacterStats(void);
500 void ShowCharacterScreen(void);
501 void HandleCharacterScreen(void);
502 void update_all_primary_stats(void);
503 
504 // armor.c
505 void update_player_armor_class(void);
506 float get_player_damage_factor(void);
507 
508 // leveleditor.c
509 void LevelEditor(void);
510 
511 // skills.c
512 void ShowSkillsScreen(void);
513 void HandleCurrentlyActivatedSkill(void);
514 int DoSkill(int skill_index, int SpellCost);
515 void do_radial_skill(int skill_index, int pos_x, int pos_y, int from_tux);
516 void activate_nth_skill(int skill_num);
517 void set_nth_quick_skill(int quick_skill);
518 void ImproveSkill(int *skill);
519 int improve_program(int);
520 void downgrade_program(int program_id);
521 int get_program_index_with_name(const char *);
522 int calculate_program_heat_cost(int program_id);
523 int CursorIsOnWhichSkillButton(int x, int y);
524 void load_skill_icon_if_needed(spell_skill_spec *spec);
525 int TeleportHome(void);
526 
527 // input.c
528 int input_handle(void);
529 void save_mouse_state(void);
530 void init_keyboard_input_array(void);
531 
532 int MouseWheelUpPressed(void);
533 int MouseWheelDownPressed(void);
534 int GetMousePos_x(void);
535 int GetMousePos_y(void);
536 int MouseRightPressed(void);
537 int MouseLeftPressed(void);
538 int MouseLeftClicked(void);
539 int MouseRightClicked(void);
540 int LeftPressed(void);
541 int RightPressed(void);
542 int UpPressed(void);
543 int DownPressed(void);
544 int SpacePressed(void);
545 int EnterPressed(void);
546 int EscapePressed(void);
547 int LeftCtrlPressed(void);
548 int CtrlPressed(void);
549 int ShiftPressed(void);
550 int APressed(void);
551 int QPressed(void);
552 int XPressed(void);
553 void WaitNoEvent(void);
554 
555 int input_key_press(SDL_Event *);
556 void keychart(void);
557 void input_keyboard_init(void);
558 void input_hold_keyboard(void);
559 void input_release_keyboard(void);
560 int getchar_raw(int *);
561 void input_get_keybind(const char *cmdname, SDLKey * key, SDLMod * mod);
562 void input_get_keybind_string(const keybind_t *kb, char *out);
563 void input_set_keybind(char *keybind, SDLKey key, SDLMod mod);
564 
565 // menu.c
566 void StoreMenuBackground(int backup_slot);
567 void RestoreMenuBackground(int backup_slot);
568 int DoMenuSelection(char *InitialText, char *MenuTexts[], int FirstItem, const char *background_name, void *MenuFont);
569 void StartupMenu(void);
570 void InitiateMenu(const char *background_name);
571 void Cheatmenu(void);
572 void EscapeMenu(void);
573 int load_named_game(const char *name);
574 
575 // misc.c
576 #define CURLEVEL() (curShip.AllLevels[Me.pos.z])
577 void print_trace(int signum);
578 void adapt_button_positions_to_screen_resolution(void);
579 void ShowGenericButtonFromList(int ButtonIndex);
580 int mouse_cursor_is_on_that_image(float pos_x, float pos_y, struct image *our_iso_image);
581 int MouseCursorIsInRect(const SDL_Rect *, int, int);
582 int MouseCursorIsOnButton(int ButtonIndex, int x, int y);
583 void *MyMemmem(char *haystack, size_t haystacklen, char *needle, size_t needlelen);
584 int init_data_dirs_path();
585 int find_file(const char *, int, char *, int);
586 int find_suffixed_file(const char *, const char *, int, char *, int);
587 int find_localized_file(const char *, int, char *, int);
588 int find_encoded_file(const char *, int, char *, int);
589 void Pause(void);
590 void ComputeFPSForThisFrame(void);
591 void StartTakingTimeForFPSCalculation(void);
592 float Frame_Time(void);
593 void Activate_Conservative_Frame_Computation(void);
594 void update_frames_displayed(void);
595 int MyRandom(int);
596 void Teleport(int LNum, float X, float Y, int WithSound, int with_animation_reset);
597 void teleport_to_level_center(int);
598 int SaveGameConfig(void);
599 int LoadGameConfig(void);
600 void Terminate(int);
601 uint32_t pot_gte(uint32_t v);
602 obstacle *give_pointer_to_obstacle_with_label(const char *, int *);
603 int level_exists(int);
604 void freeze_world(void);
605 void unfreeze_world(void);
606 int world_frozen(void);
607 int fd_setenv(const char *, const char *, int);
608 int fd_unsetenv(const char *);
609 
610 // enemy.c
611 void SetRestOfGroupToState(Enemy ThisRobot, short NewState);
612 int MakeSureEnemyIsInsideHisLevel(Enemy ThisRobot);
613 int CheckEnemyEnemyCollision(enemy *);
614 void move_enemies(void);
615 void clear_enemies(void);
616 void enemy_set_state(enemy *, const char *);
617 int enemy_set_destination(enemy *, const char *);
618 void enemy_reset(enemy *this_bot);
619 void enemy_reset_fabric(void);
620 enemy *enemy_new(int type);
621 void enemy_free(enemy *);
622 void enemy_insert_into_lists(enemy *this_enemy, int is_living);
623 void animate_enemy(enemy * our_bot);
624 void hit_enemy(enemy * target, float hit, char givexp, short int killertype, char mine);
625 enemy *enemy_resolve_address(short int enemy_number, enemy ** enemy_addr);
626 void enemy_set_reference(short int *enemy_number, enemy ** enemy_addr, enemy * addr);
627 int teleport_to_closest_waypoint(enemy *ThisRobot);
628 int teleport_to_random_waypoint(enemy *, level *, char *);
629 void teleport_enemy(enemy *, int, float, float);
630 int get_droid_type(const char *);
631 enemy *get_enemy_with_dialog(const char *dialog);
632 int get_sensor_id_by_name(const char *);
633 const char *get_sensor_name_by_id(int);
634 
635 #define BROWSE_ALIVE_BOTS_SAFE(X,Y) list_for_each_entry_safe(X, Y, &alive_bots_head, global_list)
636 #define BROWSE_ALIVE_BOTS(X) list_for_each_entry(X, &alive_bots_head, global_list)
637 #define BROWSE_DEAD_BOTS_SAFE(X,Y) list_for_each_entry_safe(X, Y, &dead_bots_head, global_list)
638 #define BROWSE_DEAD_BOTS(X) list_for_each_entry(X, &dead_bots_head, global_list)
639 #define BROWSE_LEVEL_BOTS_SAFE(X,Y,L) list_for_each_entry_safe(X,Y, &level_bots_head[(L)], level_list)
640 #define BROWSE_LEVEL_BOTS(T,L) list_for_each_entry(T, &level_bots_head[(L)], level_list)
641 
642 // text.c
643 int get_lines_needed(const char *text, SDL_Rect t_rect, float line_height_factor);
644 void show_backgrounded_label_at_map_position(char *LabelText, float fill_status, float pos_x, float pos_y, int zoom_is_on);
645 char *GetEditableStringInPopupWindow(int MaxLen, const char *PopupWindowTitle, const char *DefaultString);
646 int show_backgrounded_text_rectangle(const char *, struct font *, int, int, int, int);
647 int CutDownStringToMaximalSize(char *StringToCut, int LengthInPixels);
648 void SetNewBigScreenMessage(const char *ScreenMessageText);
649 void DisplayBigScreenMessage(void);
650 void display_effect_countdowns(void);
651 int chat_with_droid(Enemy ChatDroid);
652 
653 int display_text(const char *, int, int, const SDL_Rect*, float);
654 
655 int ScrollText(char *text, const char *background_name);
656 
657 int ImprovedCheckLineBreak(char *, const SDL_Rect*, float);
658 char *get_string(int max_len, const char *background_name, const char *text_for_overhead_promt);
659 void printf_SDL(SDL_Surface * screen, int x, int y, const char *fmt, ...) PRINTF_FMT_ATTRIBUTE(4,5);
660 int longest_line_width(char *text);
661 
662 // text_public.c
663 char *ReadAndMallocStringFromData(char *SearchString, const char *StartIndicationString, const char *EndIndicationString);
664 char *ReadAndMallocStringFromDataOptional(char *SearchString, const char *StartIndicationString, const char *EndIndicationString);
665 int CountStringOccurences(char *SearchString, const char *TargetString);
666 void ReadValueFromStringWithDefault(char *SearchBeginPointer, const char *ValuePreceedText, const char *FormatString,
667 				    const char *DefaultValueString, void *TargetValue, char *EndOfSearchSectionPointer);
668 void ReadValueFromString(char *SearchBeginPointer, const char *ValuePreceedText, const char *FormatString, void *TargetValue,
669 			 char *EndOfSearchSectionPointer);
670 int ReadRangeFromString(char *SearchString, const char *StartIndicationString, const char *EndIndicationString, int *min, int *max, int default_val);
671 int get_range_from_string(const char *str, int *min, int *max, int default_value);
672 char *ReadAndMallocAndTerminateFile(const char *filename, const char *File_End_String);
673 char *LocateStringInData(char *SearchBeginPointer, const char *SearchTextPointer);
674 void DebugPrintf(int db_level, const char *fmt, ...) PRINTF_FMT_ATTRIBUTE(2,3);
675 void clean_error_msg_store();
676 void free_error_msg_store();
677 void error_message(const char *, const char *, int, ...) PRINTF_FMT_ATTRIBUTE(2,4);
678 void error_once_message(int, const char *, const char *, int, ...) PRINTF_FMT_ATTRIBUTE(3,5);
679 void alert_window(const char *text, ...) PRINTF_FMT_ATTRIBUTE(1,2);
680 void alert_once_window(int, const char *text, ...) PRINTF_FMT_ATTRIBUTE(2,3);
681 void *MyMalloc(long);
682 char *my_strdup(const char *);
683 int FS_filelength(FILE * f);
684 int inflate_stream(FILE *, unsigned char **, int *);
685 int deflate_to_stream(unsigned char *, int, FILE *);
686 
687 // hud.c
688 void append_item_description(struct auto_string *str, item *);
689 void show_texts_and_banner(void);
690 int get_days_of_game_duration(float current_game_date);
691 int get_hours_of_game_duration(float current_game_date);
692 int get_minutes_of_game_duration(float current_game_date);
693 void append_new_game_message(const char *fmt, ...) PRINTF_FMT_ATTRIBUTE(1,2);
694 void init_message_log(void);
695 void toggle_game_config_screen_visibility(int screen_visible);
696 int get_current_fps(void);
697 void display_tooltip(const char *, int, SDL_Rect);
698 void blit_vertical_status_bar(float, float, Uint32, Uint32, int, int, int, int);
699 
700 // game_ui.c
701 struct widget_group *get_game_ui(void);
702 void free_game_ui();
703 
704 // item_upgrades_ui.c
705 int append_item_upgrade_ui_tooltip(const point *, struct auto_string *str);
706 void show_item_upgrade_ui(void);
707 void item_upgrade_ui(void);
708 
709 // addon_crafting_ui.c
710 int cursor_is_on_addon_crafting_ui(const point *);
711 void show_addon_crafting_ui(void);
712 void addon_crafting_ui(void);
713 int addon_crafting_ui_visible(void);
714 
715 // shop.c
716 void ShowItemPicture(int, int, int);
717 void ShowRescaledItem(int position, int TuxItemRow, item * ShowItem);
718 int AssemblePointerListForItemShow(item ** ItemPointerListPointer, int IncludeWornItems);
719 void InitTradeWithCharacter(struct npc *);
720 int GreatShopInterface(int, item * ShowPointerList[MAX_ITEMS_IN_INVENTORY], int, item * TuxItemsList[MAX_ITEMS_IN_INVENTORY],
721 		       shop_decision *);
722 
723 // takeover.c
724 
725 int droid_takeover(enemy *, float *);
726 int do_takeover(int, int, int, enemy *);
727 
728 void InventPlayground(void);
729 
730 void ProcessPlayground(void);
731 void ProcessDisplayColumn(void);
732 void ProcessCapsules(void);
733 void AnimateCurrents(void);
734 
735 void ClearPlayground(void);
736 int IsActive(int color, int row);
737 
738 void list_add(list_head_t * new, list_head_t * head);
739 void list_add_tail(list_head_t * new, list_head_t * head);
740 void list_del(list_head_t * entry);
741 void list_del_init(list_head_t * entry);
742 void list_move(list_head_t * list, list_head_t * head);
743 void list_move_tail(list_head_t * list, list_head_t * head);
744 int list_empty(const list_head_t * head);
745 void list_splice(list_head_t * list, list_head_t * head);
746 void list_splice_init(list_head_t * list, list_head_t * head);
747 
748 int load_texture_atlas(const char *, const char *, struct image *(*get_storage_for_key)(const char *key));
749 
750 // chat.c
751 struct widget_group *create_chat_dialog(void);
752 struct chat_context *chat_create_context(struct enemy *, struct npc *, const char *);
753 int chat_push_context(struct chat_context *);
754 void chat_delete_context(struct chat_context *);
755 void chat_push_topic(const char *topic);
756 void chat_pop_topic(void);
757 void chat_add_response(const char *);
758 int validate_dialogs(void);
759 struct chat_context *chat_get_current_context();
760 void chat_run();
761 void free_chat_widgets();
762 
763 // leveleditor_input.c
764 void leveleditor_process_input(void);
765 
766 // mapgen/mapgen.c
767 int generate_dungeon(int, int, int, int);
768 
769 // mapgen/fd_hooks.c
770 void set_dungeon_output(level *);
771 
772 // string.c
773 struct auto_string *alloc_autostr(int);
774 void free_autostr(struct auto_string *);
775 int autostr_printf(struct auto_string *, const char *, ...) PRINTF_FMT_ATTRIBUTE(2,3);
776 int autostr_vappend(struct auto_string *str, const char *fmt, va_list args);
777 int autostr_append(struct auto_string *, const char *, ...) PRINTF_FMT_ATTRIBUTE(2,3);
778 
779 // dynarray.c
780 struct dynarray *dynarray_alloc(int, size_t);
781 void dynarray_init(struct dynarray *, int, size_t);
782 void dynarray_resize(struct dynarray *, int, size_t);
783 void dynarray_free(struct dynarray *);
784 void dynarray_add(struct dynarray *, void *, size_t);
785 void dynarray_del(struct dynarray *, int, size_t);
786 void *dynarray_member(struct dynarray *, int, size_t);
787 
788 // animate.c
789 void dirty_animated_obstacle_list(int lvl_num);
790 void clear_animated_obstacle_list(struct visible_level *vis_lvl);
791 void dirty_animated_floor_tile_list(void);
792 void clear_animated_floor_tile_list();
793 animation_fptr get_animation_by_name(const char *animation_name);
794 void animation_timeline_reset(void);
795 void animation_timeline_advance(void);
796 void animate_scenery(void);
797 
798 // benchmark.c
799 int benchmark(void);
800 
801 // npc.c
802 struct npc *npc_get(const char *);
803 void npc_insert(struct npc *);
804 void npc_add(const char *);
805 int npc_add_shoplist(const char *, const char *, int);
806 void init_npcs(void);
807 void clear_npcs(void);
808 item_dynarray *npc_get_inventory(struct npc *);
809 void npc_inventory_delete_item(struct npc *, int);
810 
811 // faction.c
812 enum faction_id get_faction_id(const char *);
813 const char *get_faction_from_id(int);
814 void set_faction_state(enum faction_id, enum faction_id, enum faction_state);
815 int is_friendly(enum faction_id, enum faction_id);
816 void init_factions(void);
817 
818 // obstacle_extension.c
819 void *get_obstacle_extension(level *, obstacle *, enum obstacle_extension_type);
820 int get_obstacle_index(level *, obstacle *);
821 void add_obstacle_extension(level *, obstacle *, enum obstacle_extension_type, void *);
822 void del_obstacle_extension(level *, obstacle *, enum obstacle_extension_type);
823 void del_obstacle_extensions(level *, obstacle *);
824 void defrag_obstacle_array(level *);
825 void free_obstacle_extensions(level *lvl);
826 
827 // map_label.c
828 void add_map_label(level *, int, int, char *);
829 void del_map_label(level *, const char *);
830 void free_map_labels(level *lvl);
831 struct map_label *get_map_label(level *, const char *);
832 struct map_label *get_map_label_from_coords(level *, float, float);
833 struct map_label *map_label_exists(const char *);
834 
835 // lvledit_display.c
836 float lvledit_zoomfact_inv(void);
837 
838 // lvledit_widgets.c
839 struct widget_group *get_lvledit_ui(void);
840 void free_lvledit_ui();
841 
842 // waypoint.c
843 int add_waypoint(level *, int, int, int);
844 void del_waypoint(level *, int, int);
845 int get_waypoint(level *, int, int);
846 void move_waypoint(level *, waypoint *, int, int);
847 
848 // image.c
849 void start_image_batch(void);
850 void end_image_batch(void);
851 void display_image_on_screen(struct image *img, int x, int y, struct image_transformation t);
852 void display_image_on_map(struct image *img, float X, float Y, struct image_transformation t);
853 void create_subimage(struct image *source, struct image *new_img, SDL_Rect *rect);
854 void load_image(struct image *, const char *, int);
855 void load_image_surface(struct image *img, const char *filepath, int use_offset_file);
856 void free_image_surface(struct image *img);
857 void delete_image(struct image *img);
858 int image_loaded(struct image *);
859 struct image_transformation set_image_transformation(float scale_x, float scale_y, float r, float g, float b, float a, int highlight);
860 
861 // obstacle.c
862 struct obstacle *add_obstacle(struct level *, float , float, int);
863 struct obstacle *add_obstacle_nocheck(struct level *, float , float, int);
864 void del_obstacle(obstacle *o);
865 obstacle_spec *get_obstacle_spec(int index);
866 void glue_obstacle(level *lvl, obstacle *o);
867 void unglue_obstacle(level *lvl, obstacle *o);
868 void move_obstacle(obstacle *o, float x, float y);
869 struct obstacle_group *get_obstacle_group_by_name(const char *group_name);
870 void add_obstacle_to_group(const char *group_name, int type);
871 struct obstacle_group *find_obstacle_group(int type);
872 int change_obstacle_type(const char *obslabel, int type);
873 int get_obstacle_type_by_name(char *name);
874 struct volatile_obstacle *add_volatile_obstacle(struct level *, float, float, int, float);
875 void remove_volatile_obstacles(int);
876 void clear_volatile_obstacles(void);
877 
878 int luaFD_init(lua_State *);
879 
880 #ifdef WITH_RTPROF
881 // rtprof.c
882 void rtprof_switch_activation();
883 void rtprof_clear_probes();
884 void rtprof_display();
885 #endif
886 
887 // lang.c
888 void lang_set(const char *, int *);
889 char *lang_get();
890 char *lang_get_encoding();
891 void lang_init();
892 
893 // font.c
894 void init_fonts(void);
895 void free_fonts(void);
896 void set_current_font(struct font *);
897 struct font *get_current_font(void);
898 int get_letter_spacing(struct font *);
899 int get_font_height(struct font *);
900 int handle_switch_font_char(char **);
901 void put_string_left(struct font *, int, const char *);
902 void put_string_centered(struct font *, int, const char *);
903 void put_string_right(struct font *, int, const char *);
904 
905 #endif
906