[Add] Merchant vessels are now able to go to hyperspace.

[Change] Overpowered merchant ship a little for testing purposes.
This commit is contained in:
Allanis 2013-02-24 15:40:34 +00:00
parent 14735a362d
commit 34a6be43df
8 changed files with 42 additions and 26 deletions

View File

@ -25,7 +25,7 @@
<cap_cargo>25</cap_cargo> <cap_cargo>25</cap_cargo>
</characteristics> </characteristics>
<outfits> <outfits>
<outfit quantity='1'>Laser</outfit> <outfit quantity='3'>Laser</outfit>
</outfits> </outfits>
</ship> </ship>
<ship name = "Leapard"> <ship name = "Leapard">

View File

@ -1,7 +1,7 @@
<Start> <Start>
<name>Dark Tides</name> <name>Dark Tides</name>
<player> <player>
<ship>Lancer</ship> <ship>Merchant Ship</ship>
<credits> <credits>
<low>500</low> <low>500</low>
<high>1500</high> <high>1500</high>

View File

@ -3,7 +3,10 @@ control_rate = 2
-- Required "control" function. -- Required "control" function.
function control() function control()
if ai.taskname() == "none" then task = ai.taskname()
if task == "hyperspace" then
ai.hyperspace() -- Try to go to hyperspace.
elseif task == "none" then
planet = ai.rndplanet() planet = ai.rndplanet()
ai.pushtask(0, "go", planet) ai.pushtask(0, "go", planet)
end end
@ -62,7 +65,15 @@ end
--Waits. --Waits.
function land() function land()
if ai.timeup(0) then if ai.timeup(0) then
ai.pushtask(0, "runaway", player) ai.pushtask(0, "hyperspace")
end
end
-- Go to hyperspace YEAAAHHH!!
function hyperspace()
dir = ai.face(-1) -- Face away from (0,0)
if(dir < 10) then
ai.accel()
end end
end end

View File

@ -588,22 +588,25 @@ static int ai_face(lua_State* L) {
MIN_ARGS(1); MIN_ARGS(1);
Vec2* v; // Grab the position to face. Vec2* v; // Grab the position to face.
Pilot* p; Pilot* p;
double mod, diff;
int invert = 0;
int n = -2;
if(lua_isnumber(L,1)) { if(lua_isnumber(L, 1))
p = pilot_get((unsigned int)lua_tonumber(L,1)); n = (int)lua_tonumber(L, 1);
if(n >= 0) {
p = pilot_get(n);
if(p == NULL) return 0; // Make sure pilot is valid. if(p == NULL) return 0; // Make sure pilot is valid.
v = &p->solid->pos; v = &p->solid->pos;
} }
else if(lua_islightuserdata(L,1)) v = (Vec2*)lua_topointer(L,1); else if(lua_islightuserdata(L,1)) v = (Vec2*)lua_topointer(L,1);
double mod = -10; mod = -10;
if(lua_gettop(L) > 1 && lua_isnumber(L,2)) if(lua_gettop(L) > 1 && lua_isnumber(L,2)) invert = (int)lua_tonumber(L,2);
switch((int)lua_tonumber(L,2)) { if(invert) mod *= -1;
case 0: break; diff = angle_diff(cur_pilot->solid->dir,
case 1: mod *= -1; break; (n==-1) ? VANGLE(cur_pilot->solid->pos) : vect_angle(&cur_pilot->solid->pos, v));
case 2: break;
}
double diff = angle_diff(cur_pilot->solid->dir, vect_angle(&cur_pilot->solid->pos, v));
pilot_turn = mod*diff; pilot_turn = mod*diff;

View File

@ -1,7 +1,6 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> // We don't need this?
#include "lephisto.h" #include "lephisto.h"
#include "log.h" #include "log.h"
@ -280,13 +279,13 @@ static void pilot_hyperspace(Pilot* p) {
double diff; double diff;
if(VMOD(p->solid->vel) > MIN_VEL_ERR) { if(VMOD(p->solid->vel) > MIN_VEL_ERR) {
diff = pilot_face(p, VANGLE(player->solid->vel) + M_PI); diff = pilot_face(p, VANGLE(p->solid->vel) + M_PI);
if(ABS(diff) < MAX_DIR_ERR) // Brake. if(ABS(diff) < MAX_DIR_ERR) // Brake.
vect_pset(&p->solid->force, p->ship->thrust, p->solid->dir); vect_pset(&p->solid->force, p->ship->thrust, p->solid->dir);
} else { } else {
vectnull(&p->solid->force); // Stop accelerating. vectnull(&p->solid->force); // Stop accelerating.
diff = pilot_face(p, VANGLE(player->solid->pos)); diff = pilot_face(p, VANGLE(p->solid->pos));
if(ABS(diff) < MAX_DIR_ERR) { if(ABS(diff) < MAX_DIR_ERR) {
// We should prepare for the jump now. // We should prepare for the jump now.
@ -419,6 +418,9 @@ void pilot_destroy(Pilot* p) {
for(i = 0; i < pilots; i++) for(i = 0; i < pilots; i++)
if(pilot_stack[i] == p) if(pilot_stack[i] == p)
break; break;
pilots--;
while(i < pilots) { while(i < pilots) {
pilot_stack[i] = pilot_stack[i+1]; pilot_stack[i] = pilot_stack[i+1];
i++; i++;

View File

@ -250,9 +250,11 @@ void player_render(void) {
glFont* f; glFont* f;
// Render the player target graphics. // Render the player target graphics.
if(player_target != PLAYER_ID) { if(player_target != PLAYER_ID) p = pilot_get(player_target);
p = pilot_get(player_target); else p = NULL;
if(p == NULL) player_target = PLAYER_ID; // No more pilot target.
else {
// There is still a pilot target.
if(pilot_isDisabled(p)) c = &cInert; if(pilot_isDisabled(p)) c = &cInert;
else if(pilot_isFlag(p, PILOT_HOSTILE)) c = &cHostile; else if(pilot_isFlag(p, PILOT_HOSTILE)) c = &cHostile;
else c = &cNeutral; else c = &cNeutral;

View File

@ -52,7 +52,7 @@ static int nvoice_stack = 0;
static int mvoice_stack = 0; static int mvoice_stack = 0;
// Volume. // Volume.
static ALfloat svolume = 0.5; static ALfloat svolume = 0.3;
static int sound_makeList(void); static int sound_makeList(void);
static int sound_load(ALuint* buffer, char* filename); static int sound_load(ALuint* buffer, char* filename);

View File

@ -167,8 +167,6 @@ int space_canHyperspace(Pilot* p) {
// Hyperspace, returns 0 if entering hyperspace, or the distance if not. // Hyperspace, returns 0 if entering hyperspace, or the distance if not.
int space_hyperspace(Pilot* p) { int space_hyperspace(Pilot* p) {
if(!space_canHyperspace(p)) return -1; if(!space_canHyperspace(p)) return -1;
// Too fast.
//if(VMOD(p->solid->vel) > MAX_HYPERSPACE_VEL) return -2;
// Pilot is now going to get automatically ready for hyperspace. // Pilot is now going to get automatically ready for hyperspace.
pilot_setFlag(p, PILOT_HYP_PREP); pilot_setFlag(p, PILOT_HYP_PREP);