[Change] Make ships appear to enter from hyperspace, I'm not completely satisfied yet.

This commit is contained in:
Allanis 2013-06-22 22:01:19 +01:00
parent 9cfb07eb59
commit 53f1da128c
2 changed files with 46 additions and 45 deletions

View File

@ -20,36 +20,36 @@
#include "lluadef.h" #include "lluadef.h"
#include "ai.h" #include "ai.h"
/* == AI ====================================================== */ /* == AI ======================================================
/* */ *
/* -- Goal (Task) based AI with additional optimization. */ * -- Goal (Task) based AI with additional optimization.
/* AI uses the goal (task) based AI approach with tasks scripted */ * AI uses the goal (task) based AI approach with tasks scripted
/* in lua. Additionally there is a task that is hardcoded and */ * in lua. Additionally there is a task that is hardcoded and
/* obligatory in any AI script. The 'control' task, whose only */ * obligatory in any AI script. The 'control' task, whose only
/* purpose is to assign tasks if there is none, and optimize */ * purpose is to assign tasks if there is none, and optimize
/* or change tasks if there are. */ * or change tasks if there are.
/* */ *
/* Eg.. Pilot A is attacking Pilot B. Pilot C then comes along */ * Eg.. Pilot A is attacking Pilot B. Pilot C then comes along
/* the same system and is of the same faction as Pilot B. and */ * the same system and is of the same faction as Pilot B. and
/* therefor attacks Pilot A. Pilot A would keep fighting pilot */ * therefor attacks Pilot A. Pilot A would keep fighting pilot
/* B and until the control task comes in. Then the pilot could */ * B and until the control task comes in. Then the pilot could
/* run if it deems fit that Pilot C and Pilot B together are */ * run if it deems fit that Pilot C and Pilot B together are
/* both too strong for A. Or.. Attack C as it is an easy target */ * both too strong for A. Or.. Attack C as it is an easy target
/* to finish. */ * to finish.
/* Basically, there is many possibilities, and it's down to the */ * Basically, there is many possibilities, and it's down to the
/* Lua fanatics to decide what to do. */ * Lua fanatics to decide what to do.
/* */ *
/* -- AI will follow basic tasks defined from Lua AI scripts. */ * -- AI will follow basic tasks defined from Lua AI scripts.
/* -- If task is NULL, AI will run "control" task. */ * -- If task is NULL, AI will run "control" task.
/* -- Task is continued every frame. */ * -- Task is continued every frame.
/* -- "control" task is a special task that *must* exist in */ * -- "control" task is a special task that *must* exist in
/* any given Pilot AI (missiles, and suck will use "seek". */ * any given Pilot AI (missiles, and suck will use "seek".
/* -- "control" task is not permanent, but transitory. */ * -- "control" task is not permanent, but transitory.
/* -- "control" task sets another task. */ * -- "control" task sets another task.
/* -- "control" task is also run at a set rate (depending on */ * -- "control" task is also run at a set rate (depending on
/* Lua global "control_rate") to choose optimal behaviour */ * Lua global "control_rate") to choose optimal behaviour
/* (task). */ * (task).
/* ============================================================ */ */
/* Register a number constant n to name s (syntax is just like lua_regfunc). */ /* Register a number constant n to name s (syntax is just like lua_regfunc). */
#define lua_regnumber(l,s,n) (lua_pushnumber(l,n), lua_setglobal(l,s)) #define lua_regnumber(l,s,n) (lua_pushnumber(l,n), lua_setglobal(l,s))
@ -553,23 +553,24 @@ static int ai_getpos(lua_State* L) {
return 1; return 1;
} }
/* ======================================================== */ /*
/* Get the minimum braking distance. */ * Get the minimum braking distance.
/* */ *
/* Braking vel ==> 0 = v - a*dt */ * Braking vel ==> 0 = v - a*dt
/* Add turn around time (to initial velocity) : */ * Add turn around time (to initial velocity) :
/* ==> 180.*360./cur_pilot->turn */ * ==> 180.*360./cur_pilot->turn
/* Add it to general euler equation x = v*t + 0.5 * a * t^2 */ * Add it to general euler equation x = v*t + 0.5 * a * t^2
/* Have fun. */ * Have fun.
/* */ *
/* I really hate this function. Why isn't it depricated yet? */ * I really hate this function. Why isn't it depricated yet?
/* ======================================================== */ */
static int ai_minbrakedist(lua_State* L) { static int ai_minbrakedist(lua_State* L) {
double time, dist; double time, dist, vel;
time = VMOD(cur_pilot->solid->vel) / time = VMOD(cur_pilot->solid->vel) /
(cur_pilot->thrust / cur_pilot->solid->mass); (cur_pilot->thrust / cur_pilot->solid->mass);
dist = VMOD(cur_pilot->solid->vel)*0.9*(time+180./cur_pilot->turn) - vel = MIN(cur_pilot->speed, VMOD(cur_pilot->solid->vel));
dist = vel*(time+1.1*180./cur_pilot->turn) -
0.5 * (cur_pilot->thrust / cur_pilot->solid->mass)*time*time; 0.5 * (cur_pilot->thrust / cur_pilot->solid->mass)*time*time;
lua_pushnumber(L, dist); /* return */ lua_pushnumber(L, dist); /* return */

View File

@ -551,7 +551,7 @@ static void space_addFleet(Fleet* fleet) {
Vec2 vv, vp, vn; Vec2 vv, vp, vn;
/* Simulate them coming from hyperspace. */ /* Simulate them coming from hyperspace. */
vect_pset(&vp, RNG(MIN_HYPERSPACE_DIST, MIN_HYPERSPACE_DIST*1.5), vect_pset(&vp, RNG(MIN_HYPERSPACE_DIST, MIN_HYPERSPACE_DIST*3),
RNG(0, 360)*M_PI/180.); RNG(0, 360)*M_PI/180.);
vectnull(&vn); vectnull(&vn);
@ -561,7 +561,7 @@ static void space_addFleet(Fleet* fleet) {
RNG(75, 150) * (RNG(0,1) ? 1 : -1)); RNG(75, 150) * (RNG(0,1) ? 1 : -1));
a = vect_angle(&vp, &vn); a = vect_angle(&vp, &vn);
vectnull(&vv); vect_pset(&vv, fleet->pilots[i].ship->speed * 2., a);
pilot_create(fleet->pilots[i].ship, pilot_create(fleet->pilots[i].ship,
fleet->pilots[i].name, fleet->pilots[i].name,