[Add] Documented weapons. [Fix] Input dialogues.

This commit is contained in:
Allanis 2013-10-20 18:24:03 +01:00
parent d4b945aca7
commit e70bfacdcd
3 changed files with 148 additions and 44 deletions

View File

@ -15,21 +15,21 @@
</pilots>
</fleet>
<fleet name="Trader Llama">
<ai>Trader</ai>
<ai>merchant</ai>
<faction>Trader</faction>
<pilots>
<pilot chance="100">Llama</pilot>
</pilots>
</fleet>
<fleet name="Trader Mule">
<ai>Trader</ai>
<ai>merchant</ai>
<faction>Trader</faction>
<pilots>
<pilot chance="100">Mule</pilot>
</pilots>
</fleet>
<fleet name="Sml Trader Convoy">
<ai>Trader</ai>
<ai>merchant</ai>
<faction>Trader</faction>
<pilots>
<pilot chance="80">Llama</pilot>

View File

@ -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);

View File

@ -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 <math.h>
#include <malloc.h>
#include <string.h>
@ -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 */
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)<h/2.) || \
(shape == RADAR_CIRCLE && (((x)*(x)+(y)*(y))<rc))) \
glVertex2i((x),(y)) /**< Set a pixel if within range. */
/**
* @fn void weapon_minimap(const double res, const double w,
* const double h, const RadarShape shape)
@ -106,6 +114,10 @@ void weapon_minimap(const double res, const double w,
* @param h Height of minimap.
* @param shape Shape of the minimap.
*/
#define PIXEL(x,y) \
if((shape == RADAR_RECT && ABS(x) < w/2. && ABS(y)<h/2.) || \
(shape == RADAR_CIRCLE && (((x)*(x)+(y)*(y))<rc))) \
glVertex2i((x),(y)) /**< Set a pixel if within range. */
void weapon_minimap(const double res, const double w,
const double h, const RadarShape shape) {
int i, rc;
@ -127,7 +139,13 @@ void weapon_minimap(const double res, const double w,
}
#undef PIXEL
/* Seeker brain, You get what you pay for. :) */
/**
* @fn static void think_seeker(Weapon* w, const double dt)
*
* @brief The AI of seeker missiles.
* @param w Weapon to do the thinking.
* @param dt Current delta tick.
*/
static void think_seeker(Weapon* w, const double dt) {
double diff;
double vel;
@ -263,13 +281,24 @@ static void think_beam(Weapon* w, const double dt) {
}
}
/* Update all the weapon layers. */
/**
* @fn void weapons_update(const double dt)
*
* @brief Update all the weapon layers.
* @param dt Current delta tick.
*/
void weapons_update(const double dt) {
weapons_updateLayer(dt, WEAPON_LAYER_BG);
weapons_updateLayer(dt, WEAPON_LAYER_FG);
}
/* Update all weapons in the layer. */
/**
* @fn static void weapons_updateLayer(const double dt, const WeaponLayer layer)
*
* @brief Update all the weapons in the layer.
* @param dt Current delta tick.
* @param layer Layer to update.
*/
static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
Weapon** wlayer;
int* nlayer;
@ -336,7 +365,12 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
}
}
/* Render all the weapons. */
/**
* @fn void weapons_render(const WeaponLayer layer)
*
* @brief Render all the weapons in a layer.
* @param layer Layer to render.
*/
void weapons_render(const WeaponLayer layer) {
Weapon** wlayer;
int* nlayer;
@ -356,7 +390,12 @@ void weapons_render(const WeaponLayer layer) {
weapon_render(wlayer[i]);
}
/* Render the weapons. */
/**
* @fn static void weapon_render(const Weapon* w)
*
* @brief Render an individual weapon.
* @param w Weapon to render.
*/
static void weapon_render(const Weapon* w) {
int sx, sy;
double x, y;
@ -445,7 +484,14 @@ static void weapon_render(const Weapon* w) {
}
}
/* Update the weapon. */
/**
* @fn static void weapon_update(Weapon* w, const double dt, WeaponLayer layer)
*
* @brief Updates an individual weapon.
* @param w Weapon to update.
* @param dt Current delta tick.
* @param layer Layer to which the weapon belongs.
*/
static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
int i, wsx, wsy, psx, psy;
glTexture* gfx;
@ -591,6 +637,19 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
outfit_damageType(w->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();
if(wbackLayer != NULL) {
free(wbackLayer);
wbackLayer = NULL;
mwbackLayer = 0;
}
if(wfrontLayer != NULL) {
free(wfrontLayer);
wfrontLayer = NULL;
mwfrontLayer = 0;
}
}