From e70bfacdcd777c18190887829d19f3c619727c85 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sun, 20 Oct 2013 18:24:03 +0100 Subject: [PATCH] [Add] Documented weapons. [Fix] Input dialogues. --- dat/fleet.xml | 6 +- src/dialogue.c | 6 +- src/weapon.c | 180 ++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 148 insertions(+), 44 deletions(-) diff --git a/dat/fleet.xml b/dat/fleet.xml index 895b4e5..aac64d7 100644 --- a/dat/fleet.xml +++ b/dat/fleet.xml @@ -15,21 +15,21 @@ - Trader + merchant Trader Llama - Trader + merchant Trader Mule - Trader + merchant Trader Llama diff --git a/src/dialogue.c b/src/dialogue.c index 38b1865..213b9c5 100644 --- a/src/dialogue.c +++ b/src/dialogue.c @@ -210,9 +210,13 @@ char* dialogue_input(char* title, int min, int max, const char* fmt, ...) { window_setAccept(input_wid, dialogue_inputClose); window_setCancel(input_wid, dialogue_inputCancel); - /* Input. */ + /* Text. */ window_addText(input_wid, 30, -30, 200, h, 0, "txtInput", &gl_smallFont, &cDConsole, msg); + + /* Input. */ + window_addInput(input_wid, 20, -50-h, 200, 20, "inpInput", max, 1); + /* Button. */ window_addButton(input_wid, -20, 20, 80, 30, "btnClose", "Done", dialogue_inputClose); diff --git a/src/weapon.c b/src/weapon.c index d4bc2c0..42dfe4b 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -1,3 +1,12 @@ +/** + * @file weapon.c + * + * @brief Handle all the weapons in game. + * + * Weapons are what gets created when a pilot shoots. They are based on + * the outfit that created them. + */ + #include #include #include @@ -14,14 +23,14 @@ #include "opengl.h" #include "weapon.h" -#define weapon_isSmart(w) (w->think != NULL) +#define weapon_isSmart(w) (w->think != NULL) /**< Checks if the weapon w is smart. */ -#define WEAPON_CHUNK 128 /* Size to increment array with. */ +#define WEAPON_CHUNK 128 /**< Size to increment array with. */ /* Weapon status. */ -#define WEAPON_STATUS_OK 0 /* Weapon is fine. */ -#define WEAPON_STATUS_JAMMED 1 /* Got jammed. */ -#define WEAPON_STATUS_UNJAMMED 2 /* Surviving jaming. */ +#define WEAPON_STATUS_OK 0 /**< Weapon is fine. */ +#define WEAPON_STATUS_JAMMED 1 /**< Got jammed. */ +#define WEAPON_STATUS_UNJAMMED 2 /**< Surviving jaming. */ /* OpenGL stuff. */ extern Vec2* gl_camera; @@ -37,34 +46,39 @@ extern unsigned int player_target; /* Ai stuff. */ extern void ai_attacked(Pilot* attacked, const unsigned int attacker); +/** + * @struct Weapon + * + * @brief In-game representation of a weapon. + */ typedef struct Weapon_ { - Solid* solid; /* Actually has its own solid. :D */ - int ID; /**< Only used for beam weapons. */ + Solid* solid; /**< Actually has its own solid. :D */ + int ID; /**< Only used for beam weapons. */ - unsigned int faction; /* Faction of pilot that shot the weapon. */ - unsigned int parent; /* The pilot that just shot at you! */ - unsigned int target; /* Target to hit. Only used by seeking stuff. */ - const Outfit* outfit; /* Related outfit that fired. */ + unsigned int faction; /**< Faction of pilot that shot the weapon. */ + unsigned int parent; /**< The pilot that just shot at you! */ + unsigned int target; /**< Target to hit. Only used by seeking stuff. */ + const Outfit* outfit; /**< Related outfit that fired. */ int voice; /**< Weapons voice. */ - double lockon; /* Some weapons have a lockon delay. */ - double timer; /* Mainly used to see when the weapon was fired. */ + double lockon; /**< Some weapons have a lockon delay. */ + double timer; /**< Mainly used to see when the weapon was fired. */ /* Update position and render. */ - void(*update)(struct Weapon_*, const double, WeaponLayer); /* Position update and render. */ - void(*think)(struct Weapon_*, const double); /* Some missiles need to be inteligent.a */ + void(*update)(struct Weapon_*, const double, WeaponLayer); /**< Update the weapon. */ + void(*think)(struct Weapon_*, const double); /**< For the smart missiles. */ - char status; /* Weapon status - to check for jamming. */ + char status; /**< Weapon status - to check for jamming. */ } Weapon; /* Behind Pilot layer. */ -static Weapon** wbackLayer = NULL; /* Behind pilots. */ -static int nwbackLayer = 0; /* Number of elements. */ -static int mwbackLayer = 0; /* Allocated memory size. */ +static Weapon** wbackLayer = NULL; /**< Behind pilots. */ +static int nwbackLayer = 0; /**< Number of elements. */ +static int mwbackLayer = 0; /**< Allocated memory size. */ /* Behind player layer. */ -static Weapon** wfrontLayer = NULL; /* Behind pilots. */ -static int nwfrontLayer = 0; /* Number of elements. */ -static int mwfrontLayer = 0; /* Allocated memory size. */ +static Weapon** wfrontLayer = NULL; /**< Infront of pilots, behind player. */ +static int nwfrontLayer = 0; /**< Number of elements. */ +static int mwfrontLayer = 0; /**< Allocated memory size. */ /* Internal stuff. */ static int beam_idgen = 0; /**< Beam identifier generator. */ @@ -86,16 +100,10 @@ static void weapon_free(Weapon* w); /* Think. */ static void think_seeker(Weapon* w, const double dt); static void think_beam(Weapon* w, const double dt); -/*static void think_smart(Weapon* w, const double dt);*/ /* Extern. */ void weapon_minimap(const double res, const double w, const double h, const RadarShape shape); -/* Draw the minimap weapons (player.c). */ -#define PIXEL(x,y) \ - if((shape == RADAR_RECT && ABS(x) < w/2. && ABS(y)outfit), outfit_damage(w->outfit)*dt); } +/** + * @fn static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2* pos, + * const Vec2* vel, unsigned int parent, const unsigned int target) + * + * @brief Create a new weapon. + * @param outfit Outfit which spawned the weapon. + * @param dir Direction the shooter is facing. + * @param pos Position of the shooter. + * @param vel Velocity of the shooter. + * @param parent Shooter ID. + * @param target Target ID of the shooter. + * @return A pointer to the newly created weapon. + */ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2* pos, const Vec2* vel, unsigned int parent, const unsigned int target) { Vec2 v; @@ -715,7 +774,18 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2* return w; } -/* Add a new weapon. */ +/** + * @fn void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, + * const Vec2* vel, unsigned int parent, unsigned int target) + * + * @brief Create a new weapon. + * @param outfit Outfit which spawns the weapon. + * @param dir Direction of the shooter. + * @param pos Position of the shooter. + * @param vel Velocity of the shooter. + * @param parent Pilot ID of the shooter. + * @param target Target ID that is getting shot. + */ void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, const Vec2* vel, unsigned int parent, unsigned int target) { @@ -873,7 +943,13 @@ void beam_end(const unsigned int parent, int beam) { } } -/* Destroy the weapon. */ +/** + * @fn static void weapon_destroy(Weapon* w, WeaponLayer layer) + * + * @brief Destroys a weapon. + * @param w Weapon to destroy. + * @param layer Layer to which the weapon belongs. + */ static void weapon_destroy(Weapon* w, WeaponLayer layer) { int i; Weapon** wlayer; @@ -914,13 +990,22 @@ static void weapon_destroy(Weapon* w, WeaponLayer layer) { wlayer[i] = wlayer[i+1]; } -/* Clear the weapon. */ +/** + * @fn static void weapon_free(Weapon* w) + * + * @brief Free the weapon. + * @param w Weapon to free. + */ static void weapon_free(Weapon* w) { solid_free(w->solid); free(w); } -/* Clear all the weapons, do not free the layers. */ +/** + * @fn void weapon_clear(void) + * + * @brief Clear all the weapons, does *not* free the layers. + */ void weapon_clear(void) { int i; for(i = 0; i < nwbackLayer; i++) @@ -931,9 +1016,24 @@ void weapon_clear(void) { nwfrontLayer = 0; } +/** + * @fn void weapon_exit(void) + * + * @brief Destroy all the weapons and free it all. + */ void weapon_exit(void) { weapon_clear(); - free(wbackLayer); - free(wfrontLayer); + + if(wbackLayer != NULL) { + free(wbackLayer); + wbackLayer = NULL; + mwbackLayer = 0; + } + + if(wfrontLayer != NULL) { + free(wfrontLayer); + wfrontLayer = NULL; + mwfrontLayer = 0; + } }