1 /*! \file 2 * \brief Fighter file handling. 3 * \details Functions and structs for reading, writing and modifying OMF:2097 fighter (AF) files. 4 * \copyright MIT license. 5 * \date 2013-2014 6 * \author Andrew Thompson 7 * \author Tuomas Virtanen 8 */ 9 10 #ifndef _SD_AF_H 11 #define _SD_AF_H 12 13 #include <stdint.h> 14 #include "shadowdive/move.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #define MAX_AF_MOVES 70 ///< Maximum amount of moves for a HAR 21 22 /*! \brief HAR data container 23 * 24 * Contains information about a single HAR (combat robot). 25 */ 26 typedef struct { 27 uint16_t file_id; ///< File ID 28 uint16_t exec_window; ///< Move execution window (?) 29 float endurance; ///< HAR Endurance 30 uint8_t unknown_b; ///< Unknown value 31 uint16_t health; ///< HAR Health 32 float forward_speed; ///< HAR fwd speed 33 float reverse_speed; ///< HAR bwd speed 34 float jump_speed; ///< HAR jump speed 35 float fall_speed; ///< HAR fall speed 36 uint8_t unknown_c; ///< Unknown value 37 uint8_t unknown_d; ///< Unknown value 38 39 sd_move *moves[MAX_AF_MOVES]; ///< All HAR moves. 40 char soundtable[30]; ///< All sounds used by the animations in this HAR file. 41 } sd_af_file; 42 43 /*! \brief Initialize AF file structure 44 * 45 * Initializes the AF file structure with empty values. 46 * 47 * \retval SD_INVALID_INPUT AF struct value was NULL. 48 * \retval SD_SUCCESS Success. 49 * 50 * \param af Allocated AF struct pointer. 51 */ 52 int sd_af_create(sd_af_file *af); 53 54 /*! \brief Copy AF structure 55 * 56 * Copies the contents of an AF file structure. _ALL_ internals will be copied. 57 * The copied structure must be freed using sd_af_free(). 58 * 59 * Destination buffer does not need to be cleared. Source buffer must be a valid 60 * AF file structure, or problems are likely to appear. 61 * 62 * \retval SD_OUT_OF_MEMORY Memory ran out. Destination struct should now be considered invalid and freed. 63 * \retval SD_INVALID_INPUT Either input value was NULL. 64 * \retval SD_SUCCESS Success. 65 * 66 * \param dst Destination AF struct pointer. 67 * \param src Source AF struct pointer. 68 */ 69 int sd_af_copy(sd_af_file *dst, const sd_af_file *src); 70 71 /*! \brief Set move 72 * 73 * Sets a HAR move to a given index in a AF file structure. Move will be copied, 74 * so remember to free your local copy yourself. 75 * 76 * Index should be between 0 and 69 (inclusive); any other values will result in error. 77 * 78 * A NULL value for move will result in the old move at index getting freed. 79 * 80 * \retval SD_OUT_OF_MEMORY Memory ran out. This struct should now be considered invalid and freed. 81 * \retval SD_INVALID_INPUT Index was invalid or a pointer was NULL. 82 * \retval SD_SUCCESS Success. 83 * 84 * \param af AF struct pointer. 85 * \param index Index of the move. Must be 0 <= index <= 69. 86 * \param move sd_move struct. This will be copied. 87 */ 88 int sd_af_set_move(sd_af_file *af, int index, const sd_move *move); 89 90 /*! \brief Get move 91 * 92 * Gets a HAR move from an index in AF file structure. Index must be 93 * between values 0 and 69 (inclusive); any other value will result in error. 94 * 95 * \retval NULL Wrong index or move does not exist. 96 * \retval sd_move* Success. 97 * 98 * \param af AF struct pointer. 99 * \param index Index of the move. Must be 0 <= index <= 69. 100 */ 101 sd_move* sd_af_get_move(sd_af_file *af, int index); 102 103 /*! \brief Load AF file 104 * 105 * Loads the given AF file to memory. The structure must be initialized with sd_af_create() 106 * before using this function.´Loading to a previously loaded or filled sd_bk_file structure 107 * will result in old data and pointers getting lost. This is very likely to cause a memory leak. 108 * 109 * \retval SD_FILE_OPEN_ERROR File could not be opened. 110 * \retval SD_FILE_PARSE_ERROR File does not contain valid data or has syntax problems. 111 * \retval SD_OUT_OF_MEMORY Memory ran out. This struct should now be considered invalid and freed. 112 * \retval SD_SUCCESS Success. 113 * 114 * \param af AF struct pointer. 115 * \param filename Name of the AF file. 116 */ 117 int sd_af_load(sd_af_file *af, const char *filename); 118 119 /*! \brief Save AF file 120 * 121 * Saves the given AF file from memory to a file on disk. The structure must be 122 * at least initialized by using sd_af_create before running this. 123 * 124 * \retval SD_FILE_OPEN_ERROR File could not be opened. 125 * \retval SD_SUCCESS Success. 126 * 127 * \param af AF struct pointer. 128 * \param filename Name of the AF file 129 */ 130 int sd_af_save(const sd_af_file *af, const char* filename); 131 132 /*! \brief Free AF file structure 133 * 134 * Frees up all memory reserved by the AF file structure. 135 * All contents will be freed, all pointers to contents will be invalid. 136 * 137 * \param af AF struct pointer. 138 */ 139 void sd_af_free(sd_af_file *af); 140 141 #ifdef __cplusplus 142 } 143 #endif 144 145 #endif // _SD_AF_H 146