[Add] Attempted to get modifications actually working. Everything is

brokened. Don't even attempt to play..
This commit is contained in:
Allanis 2013-03-17 19:28:45 +00:00
parent ee3c81b7ff
commit b66c6f7ecf
6 changed files with 81 additions and 26 deletions

View File

@ -49,7 +49,7 @@ function create()
elseif num == 1 then
cargo = "Ore"
end
ai.setCargo(cargo, ai.rnd(0, ai.cargofree()))
ai.setcargo(cargo, ai.rnd(0, ai.cargofree()))
end
-- Runs away.

View File

@ -350,8 +350,8 @@ void ai_think(Pilot* pilot) {
cur_pilot->solid->dir_vel = 0.;
if(pilot_turn) // Set the turning velocity.
cur_pilot->solid->dir_vel -= cur_pilot->ship->turn * pilot_turn;
vect_pset(&cur_pilot->solid->force, cur_pilot->ship->thrust * pilot_acc,
cur_pilot->solid->dir_vel -= cur_pilot->turn * pilot_turn;
vect_pset(&cur_pilot->solid->force, cur_pilot->thrust * pilot_acc,
cur_pilot->solid->dir);
// Fire weapons if needs be.
@ -553,16 +553,16 @@ static int ai_getpos(lua_State* L) {
//
// Braking vel ==> 0 = v - a*dt
// Add turn around time (to initial velocity) :
// ==> 180.*360./cur_pilot->ship->turn
// ==> 180.*360./cur_pilot->turn
// Add it to general euler equation x = v*t + 0.5 * a * t^2
// Have fun.
// ========================================================
static int ai_minbrakedist(lua_State* L) {
double time = VMOD(cur_pilot->solid->vel) /
(cur_pilot->ship->thrust / cur_pilot->solid->mass);
(cur_pilot->thrust / cur_pilot->solid->mass);
double dist = VMOD(cur_pilot->solid->vel)*(time + 180./cur_pilot->ship->turn)-
0.5 * (cur_pilot->ship->thrust / cur_pilot->solid->mass)*time*time;
double dist = VMOD(cur_pilot->solid->vel)*(time + 180./cur_pilot->turn)-
0.5 * (cur_pilot->thrust / cur_pilot->solid->mass)*time*time;
lua_pushnumber(L, dist); // return
return 1;
@ -585,7 +585,7 @@ static int ai_exists(lua_State* L) {
// Are we at max velocity?
static int ai_ismaxvel(lua_State* L) {
lua_pushboolean(L, VMOD(cur_pilot->solid->vel) == cur_pilot->ship->speed);
lua_pushboolean(L,(VMOD(cur_pilot->solid->vel)>cur_pilot->speed-MIN_VEL_ERR));
return 1;
}

View File

@ -90,6 +90,7 @@ int outfit_isTurret(const Outfit* o) {
(o->type == OUTFIT_TYPE_TURRET_BEAM));
}
// Return 1 if o is a modification.
int outfit_isMod(const Outfit* o) {
return (o->type == OUTFIT_TYPE_MODIFICATION);
}

View File

@ -44,6 +44,7 @@ static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t);
static void pilot_update(Pilot* pilot, const double dt);
static void pilot_hyperspace(Pilot* pilot);
void pilot_render(Pilot* pilot);
static void pilot_calcStats(Pilot* pilot);
static void pilot_free(Pilot* p);
static Fleet* fleet_parse(const xmlNodePtr parent);
static void pilot_dead(Pilot* p);
@ -128,7 +129,7 @@ double pilot_face(Pilot* p, const float dir) {
p->solid->dir_vel = 0.;
if(turn)
p->solid->dir_vel -= p->ship->turn * turn;
p->solid->dir_vel -= p->turn * turn;
return diff;
}
@ -358,11 +359,11 @@ static void pilot_update(Pilot* pilot, const double dt) {
}
// We are still alive.
else if(pilot->armour < pilot->armour_max) {
pilot->armour += pilot->ship->armour_regen*dt;
pilot->energy += pilot->ship->energy_regen*dt;
pilot->armour += pilot->armour_regen*dt;
pilot->energy += pilot->energy_regen*dt;
} else {
pilot->shield += pilot->ship->shield_regen*dt;
pilot->energy += pilot->ship->energy_regen*dt;
pilot->shield += pilot->shield_regen*dt;
pilot->energy += pilot->energy_regen*dt;
}
if(pilot->armour > pilot->armour_max) pilot->armour = pilot->armour_max;
@ -376,7 +377,7 @@ static void pilot_update(Pilot* pilot, const double dt) {
if(!pilot_isFlag(pilot, PILOT_HYPERSPACE))
// Should not go faster.
limit_speeddt(&pilot->solid->vel, pilot->ship->speed, dt);
limit_speeddt(&pilot->solid->vel, pilot->speed, dt);
}
// Pilot is getting ready or is in, hyperspace.
@ -392,7 +393,7 @@ static void pilot_hyperspace(Pilot* p) {
pilot_setFlag(p, PILOT_DELETE); // Set flag to delete pilot.
return;
}
vect_pset(&p->solid->force, p->ship->thrust * 3., p->solid->dir);
vect_pset(&p->solid->force, p->thrust * 3., p->solid->dir);
}
else if(pilot_isFlag(p, PILOT_HYP_BEGIN)) {
if(SDL_GetTicks() > p->ptimer) {
@ -407,7 +408,7 @@ static void pilot_hyperspace(Pilot* p) {
diff = pilot_face(p, VANGLE(p->solid->vel) + M_PI);
if(ABS(diff) < MAX_DIR_ERR) // Brake.
vect_pset(&p->solid->force, p->ship->thrust, p->solid->dir);
vect_pset(&p->solid->force, p->thrust, p->solid->dir);
} else {
vectnull(&p->solid->force); // Stop accelerating.
@ -439,6 +440,7 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
q -= pilot->outfits[i].quantity - outfit->max;
pilot->outfits[i].quantity = outfit->max;
}
//pilot_calcStats(pilot);
return q;
}
@ -460,6 +462,7 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
// Hack due to realloc possibility.
pilot_setSecondary(pilot, s);
pilot_calcStats(pilot);
return q;
}
@ -496,6 +499,55 @@ int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
return 0;
}
// Recalculate the pilot's stats based on her outfits.
static void pilot_calcStats(Pilot* pilot) {
int i;
double q;
Outfit* o;
double ac, sc, ec; // Temp health coeficients to set.
// -- Set up the basic stuff.
// Movement.
pilot->thrust = pilot->ship->thrust;
pilot->turn = pilot->ship->turn;
pilot->speed = pilot->ship->speed;
// Health.
ac = pilot->armour / pilot->armour_max;
sc = pilot->shield / pilot->shield_max;
ec = pilot->energy / pilot->energy_max;
pilot->armour_max = pilot->ship->armour;
pilot->shield_max = pilot->ship->shield;
pilot->energy_max = pilot->ship->energy;
pilot->armour_regen = pilot->ship->armour_regen;
pilot->shield_regen = pilot->ship->shield_regen;
pilot->energy_regen = pilot->ship->energy_regen;
// Now add outfit changes.
for(i = 0; i < pilot->noutfits; i++)
if(outfit_isMod(pilot->outfits[i].outfit)) {
q = (double) pilot->outfits[i].quantity;
o = pilot->outfits[i].outfit;
// Movement.
pilot->thrust += o->u.mod.thrust * q;
pilot->turn += o->u.mod.turn * q;
pilot->speed += o->u.mod.speed * q;
// Health.
pilot->armour_max += o->u.mod.armour * q;
pilot->armour_regen += o->u.mod.armour_regen * q;
pilot->shield_max += o->u.mod.shield * q;
pilot->shield_regen += o->u.mod.shield_regen * q;
pilot->energy_max += o->u.mod.energy * q;
pilot->energy_regen += o->u.mod.energy_regen * q;
}
// Give the pilot her health proportion back.
pilot->armour = ac * pilot->armour_max;
pilot->shield = sc * pilot->shield_max;
pilot->energy = ec * pilot->energy_max;
}
// Try to add quantity of cargo to pilot, return quantity actually added.
int pilot_addCargo(Pilot* pilot, Commodity* cargo, int quantity) {
int i, q;
@ -581,14 +633,6 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, Faction* faction,
// Solid.
pilot->solid = solid_create(ship->mass, dir, pos, vel);
// Max shields armour.
pilot->armour_max = ship->armour;
pilot->shield_max = ship->shield;
pilot->energy_max = ship->energy;
pilot->armour = pilot->armour_max;
pilot->shield = pilot->shield_max;
pilot->energy = pilot->energy_max;
// Initially idle.
pilot->task = NULL;
@ -610,6 +654,13 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, Faction* faction,
}
}
// Set the pilot stats based on her ship and outfits.
// Hack to have full armour/shield/energy.
pilot->armour = pilot->armour_max = 1.;
pilot->shield = pilot->shield_max = 1.;
pilot->energy = pilot->energy_max = 1.;
pilot_calcStats(pilot);
// Cargo.
pilot->credits = 0;
pilot->commodities = NULL;

View File

@ -66,9 +66,12 @@ typedef struct Pilot_ {
Solid* solid; // Associated solid (physics).
int tsx, tsy; // Current sprite, calculated on update.
double thrust, turn, speed;
// Current health.
double armour, shield, energy;
double armour_max, shield_max, energy_max;
double armour_regen, shield_regen, energy_regen;
double fuel; // Used only for jumps. TODO: make it do something.
void (*think)(struct Pilot_*); // AI thinking for the pilot.

View File

@ -900,14 +900,14 @@ void player_think(Pilot* player) {
else {
player->solid->dir_vel = 0.;
if(player_turn)
player->solid->dir_vel -= player->ship->turn * player_turn;
player->solid->dir_vel -= player->turn * player_turn;
}
if(player_isFlag(PLAYER_PRIMARY)) pilot_shoot(player, player_target, 0);
if(player_isFlag(PLAYER_SECONDARY)) // Needs a target.
pilot_shoot(player, player_target, 1);
vect_pset(&player->solid->force, player->ship->thrust * player_acc,
vect_pset(&player->solid->force, player->thrust * player_acc,
player->solid->dir);
// Set the listener stuff.