[Change] Make ships appear to enter from hyperspace, I'm not completely satisfied yet.
This commit is contained in:
parent
9cfb07eb59
commit
53f1da128c
87
src/ai.c
87
src/ai.c
@ -20,36 +20,36 @@
|
||||
#include "lluadef.h"
|
||||
#include "ai.h"
|
||||
|
||||
/* == AI ====================================================== */
|
||||
/* */
|
||||
/* -- Goal (Task) based AI with additional optimization. */
|
||||
/* AI uses the goal (task) based AI approach with tasks scripted */
|
||||
/* in lua. Additionally there is a task that is hardcoded and */
|
||||
/* obligatory in any AI script. The 'control' task, whose only */
|
||||
/* purpose is to assign tasks if there is none, and optimize */
|
||||
/* or change tasks if there are. */
|
||||
/* */
|
||||
/* 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 */
|
||||
/* therefor attacks Pilot A. Pilot A would keep fighting pilot */
|
||||
/* 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 */
|
||||
/* both too strong for A. Or.. Attack C as it is an easy target */
|
||||
/* to finish. */
|
||||
/* Basically, there is many possibilities, and it's down to the */
|
||||
/* Lua fanatics to decide what to do. */
|
||||
/* */
|
||||
/* -- AI will follow basic tasks defined from Lua AI scripts. */
|
||||
/* -- If task is NULL, AI will run "control" task. */
|
||||
/* -- Task is continued every frame. */
|
||||
/* -- "control" task is a special task that *must* exist in */
|
||||
/* any given Pilot AI (missiles, and suck will use "seek". */
|
||||
/* -- "control" task is not permanent, but transitory. */
|
||||
/* -- "control" task sets another task. */
|
||||
/* -- "control" task is also run at a set rate (depending on */
|
||||
/* Lua global "control_rate") to choose optimal behaviour */
|
||||
/* (task). */
|
||||
/* ============================================================ */
|
||||
/* == AI ======================================================
|
||||
*
|
||||
* -- Goal (Task) based AI with additional optimization.
|
||||
* AI uses the goal (task) based AI approach with tasks scripted
|
||||
* in lua. Additionally there is a task that is hardcoded and
|
||||
* obligatory in any AI script. The 'control' task, whose only
|
||||
* purpose is to assign tasks if there is none, and optimize
|
||||
* or change tasks if there are.
|
||||
*
|
||||
* 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
|
||||
* therefor attacks Pilot A. Pilot A would keep fighting pilot
|
||||
* 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
|
||||
* both too strong for A. Or.. Attack C as it is an easy target
|
||||
* to finish.
|
||||
* Basically, there is many possibilities, and it's down to the
|
||||
* Lua fanatics to decide what to do.
|
||||
*
|
||||
* -- AI will follow basic tasks defined from Lua AI scripts.
|
||||
* -- If task is NULL, AI will run "control" task.
|
||||
* -- Task is continued every frame.
|
||||
* -- "control" task is a special task that *must* exist in
|
||||
* any given Pilot AI (missiles, and suck will use "seek".
|
||||
* -- "control" task is not permanent, but transitory.
|
||||
* -- "control" task sets another task.
|
||||
* -- "control" task is also run at a set rate (depending on
|
||||
* Lua global "control_rate") to choose optimal behaviour
|
||||
* (task).
|
||||
*/
|
||||
|
||||
/* 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))
|
||||
@ -553,23 +553,24 @@ static int ai_getpos(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
/* Get the minimum braking distance. */
|
||||
/* */
|
||||
/* Braking vel ==> 0 = v - a*dt */
|
||||
/* Add turn around time (to initial velocity) : */
|
||||
/* ==> 180.*360./cur_pilot->turn */
|
||||
/* Add it to general euler equation x = v*t + 0.5 * a * t^2 */
|
||||
/* Have fun. */
|
||||
/* */
|
||||
/* I really hate this function. Why isn't it depricated yet? */
|
||||
/* ======================================================== */
|
||||
/*
|
||||
* Get the minimum braking distance.
|
||||
*
|
||||
* Braking vel ==> 0 = v - a*dt
|
||||
* Add turn around time (to initial velocity) :
|
||||
* ==> 180.*360./cur_pilot->turn
|
||||
* Add it to general euler equation x = v*t + 0.5 * a * t^2
|
||||
* Have fun.
|
||||
*
|
||||
* I really hate this function. Why isn't it depricated yet?
|
||||
*/
|
||||
static int ai_minbrakedist(lua_State* L) {
|
||||
double time, dist;
|
||||
double time, dist, vel;
|
||||
time = VMOD(cur_pilot->solid->vel) /
|
||||
(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;
|
||||
|
||||
lua_pushnumber(L, dist); /* return */
|
||||
|
@ -551,7 +551,7 @@ static void space_addFleet(Fleet* fleet) {
|
||||
Vec2 vv, vp, vn;
|
||||
|
||||
/* 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.);
|
||||
vectnull(&vn);
|
||||
|
||||
@ -561,7 +561,7 @@ static void space_addFleet(Fleet* fleet) {
|
||||
RNG(75, 150) * (RNG(0,1) ? 1 : -1));
|
||||
|
||||
a = vect_angle(&vp, &vn);
|
||||
vectnull(&vv);
|
||||
vect_pset(&vv, fleet->pilots[i].ship->speed * 2., a);
|
||||
|
||||
pilot_create(fleet->pilots[i].ship,
|
||||
fleet->pilots[i].name,
|
||||
|
Loading…
Reference in New Issue
Block a user