Move reactor Gun_dir,Gun_pos into struct object

This commit is contained in:
Kp 2013-03-23 19:09:44 +00:00
parent ffe0fb239c
commit 2522c8f6f9
4 changed files with 27 additions and 22 deletions

View file

@ -41,16 +41,15 @@ int Control_center_player_been_seen;
int Control_center_next_fire_time;
int Control_center_present;
vms_vector Gun_pos[MAX_CONTROLCEN_GUNS], Gun_dir[MAX_CONTROLCEN_GUNS];
void do_countdown_frame();
// -----------------------------------------------------------------------------
//return the position & orientation of a gun on the control center object
void calc_controlcen_gun_point(vms_vector *gun_point,vms_vector *gun_dir,object *obj,int gun_num)
void calc_controlcen_gun_point(reactor *reactor, object *obj,int gun_num)
{
reactor *reactor = &Reactors[0];
vms_matrix m;
vms_vector *gun_point = &obj->ctype.reactor_info.gun_pos[gun_num];
vms_vector *gun_dir = &obj->ctype.reactor_info.gun_dir[gun_num];
Assert(obj->type == OBJ_CNTRLCEN);
Assert(obj->render_type==RT_POLYOBJ);
@ -70,11 +69,13 @@ void calc_controlcen_gun_point(vms_vector *gun_point,vms_vector *gun_dir,object
// Look at control center guns, find best one to fire at *objp.
// Return best gun number (one whose direction dotted with vector to player is largest).
// If best gun has negative dot, return -1, meaning no gun is good.
int calc_best_gun(int num_guns, vms_vector *gun_pos, vms_vector *gun_dir, vms_vector *objpos)
int calc_best_gun(int num_guns, const object *objreactor, const vms_vector *objpos)
{
int i;
fix best_dot;
int best_gun;
const vms_vector (*const gun_pos)[MAX_CONTROLCEN_GUNS] = &objreactor->ctype.reactor_info.gun_pos;
const vms_vector (*const gun_dir)[MAX_CONTROLCEN_GUNS] = &objreactor->ctype.reactor_info.gun_dir;
best_dot = -F1_0*2;
best_gun = -1;
@ -83,9 +84,9 @@ int calc_best_gun(int num_guns, vms_vector *gun_pos, vms_vector *gun_dir, vms_ve
fix dot;
vms_vector gun_vec;
vm_vec_sub(&gun_vec, objpos, &gun_pos[i]);
vm_vec_sub(&gun_vec, objpos, &((*gun_pos)[i]));
vm_vec_normalize_quick(&gun_vec);
dot = vm_vec_dot(&gun_dir[i], &gun_vec);
dot = vm_vec_dot(&((*gun_dir)[i]), &gun_vec);
if (dot > best_dot) {
best_dot = dot;
@ -102,6 +103,7 @@ int calc_best_gun(int num_guns, vms_vector *gun_pos, vms_vector *gun_dir, vms_ve
}
int Dead_controlcen_object_num=-1;
int Control_center_destroyed = 0;
@ -289,9 +291,9 @@ void do_controlcen_frame(object *obj)
if ((Control_center_next_fire_time < 0) && !(controlcen_death_silence > F1_0*2)) {
if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED)
best_gun_num = calc_best_gun(Reactors[0].n_guns, Gun_pos, Gun_dir, &Believed_player_pos);
best_gun_num = calc_best_gun(Reactors[0].n_guns, obj, &Believed_player_pos);
else
best_gun_num = calc_best_gun(Reactors[0].n_guns, Gun_pos, Gun_dir, &ConsoleObject->pos);
best_gun_num = calc_best_gun(Reactors[0].n_guns, obj, &ConsoleObject->pos);
if (best_gun_num != -1) {
vms_vector vec_to_goal;
@ -299,10 +301,10 @@ void do_controlcen_frame(object *obj)
fix delta_fire_time;
if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED) {
vm_vec_sub(&vec_to_goal, &Believed_player_pos, &Gun_pos[best_gun_num]);
vm_vec_sub(&vec_to_goal, &Believed_player_pos, &obj->ctype.reactor_info.gun_pos[best_gun_num]);
dist_to_player = vm_vec_normalize_quick(&vec_to_goal);
} else {
vm_vec_sub(&vec_to_goal, &ConsoleObject->pos, &Gun_pos[best_gun_num]);
vm_vec_sub(&vec_to_goal, &ConsoleObject->pos, &obj->ctype.reactor_info.gun_pos[best_gun_num]);
dist_to_player = vm_vec_normalize_quick(&vec_to_goal);
}
@ -317,7 +319,7 @@ void do_controlcen_frame(object *obj)
if (Game_mode & GM_MULTI)
multi_send_controlcen_fire(&vec_to_goal, best_gun_num, obj-Objects);
#endif
Laser_create_new_easy( &vec_to_goal, &Gun_pos[best_gun_num], obj-Objects, CONTROLCEN_WEAPON_NUM, 1);
Laser_create_new_easy( &vec_to_goal, &obj->ctype.reactor_info.gun_pos[best_gun_num], obj-Objects, CONTROLCEN_WEAPON_NUM, 1);
// 1/4 of time, fire another thing, not directly at player, so it might hit him if he's constantly moving.
if (d_rand() < 32767/4) {
@ -330,7 +332,7 @@ void do_controlcen_frame(object *obj)
if (Game_mode & GM_MULTI)
multi_send_controlcen_fire(&vec_to_goal, best_gun_num, obj-Objects);
#endif
Laser_create_new_easy( &vec_to_goal, &Gun_pos[best_gun_num], obj-Objects, CONTROLCEN_WEAPON_NUM, 1);
Laser_create_new_easy( &vec_to_goal, &obj->ctype.reactor_info.gun_pos[best_gun_num], obj-Objects, CONTROLCEN_WEAPON_NUM, 1);
}
delta_fire_time = (NDL - Difficulty_level) * F1_0/4;
@ -395,7 +397,7 @@ void init_controlcen_for_level(void)
// Compute all gun positions.
objp = &Objects[cntrlcen_objnum];
for (i=0; i<Reactors[0].n_guns; i++)
calc_controlcen_gun_point(&Gun_pos[i], &Gun_dir[i], objp, i);
calc_controlcen_gun_point(&Reactors[0], objp, i);
Control_center_present = 1;
// Boost control center strength at higher levels.

View file

@ -25,8 +25,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "wall.h"
#include "switch.h"
#define MAX_CONTROLCEN_GUNS 4
#define CONTROLCEN_WEAPON_NUM 6
#define MAX_CONTROLCEN_LINKS 10
@ -55,11 +53,6 @@ extern int Control_center_next_fire_time;
extern int Control_center_present;
extern int Dead_controlcen_object_num;
extern vms_vector Gun_pos[MAX_CONTROLCEN_GUNS];
//return the position & orientation of a gun on the control center object
extern void calc_controlcen_gun_point(vms_vector *gun_point,vms_vector *gun_dir,object *obj,int gun_num);
// do whatever this thing does in a frame
extern void do_controlcen_frame(object *obj);

View file

@ -2003,7 +2003,7 @@ multi_do_controlcen_fire(char *buf)
gun_num = buf[count]; count += 1;
objnum = GET_INTEL_SHORT(buf + count); count += 2;
Laser_create_new_easy(&to_target, &Gun_pos[gun_num], objnum, CONTROLCEN_WEAPON_NUM, 1);
Laser_create_new_easy(&to_target, &Objects[objnum].ctype.reactor_info.gun_pos[gun_num], objnum, CONTROLCEN_WEAPON_NUM, 1);
}
void

View file

@ -134,6 +134,15 @@ extern int Num_rendered_objects;
* STRUCTURES
*/
#define MAX_CONTROLCEN_GUNS 4
struct reactor_static {
/* Location of the gun on the reactor object */
vms_vector gun_pos[MAX_CONTROLCEN_GUNS];
/* Orientation of the gun on the reactor object */
vms_vector gun_dir[MAX_CONTROLCEN_GUNS];
};
// A compressed form for sending crucial data
typedef struct shortpos {
sbyte bytemat[9];
@ -267,6 +276,7 @@ typedef struct object {
struct ai_static ai_info;
struct light_info light_info; // why put this here? Didn't know what else to do with it.
struct powerup_info powerup_info;
struct reactor_static reactor_info;
} __pack__ ctype ;
// render info, determined by RENDER_TYPE