]> icculus.org git repositories - taylor/freespace2.git/blob - src/jumpnode/jumpnode.cpp
Initial revision
[taylor/freespace2.git] / src / jumpnode / jumpnode.cpp
1 /*
2  * $Logfile: /Freespace2/code/JumpNode/JumpNode.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Module for everything to do with jump nodes
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:09  root
11  * Initial revision
12  *
13  * 
14  * 2     10/07/98 10:53a Dave
15  * Initial checkin.
16  * 
17  * 1     10/07/98 10:49a Dave
18  * 
19  * 9     6/13/98 6:01p Hoffoss
20  * Externalized all new (or forgot to be added) strings to all the code.
21  * 
22  * 8     5/12/98 2:03p Adam
23  * make jumpnode less bright
24  * 
25  * 7     4/01/98 8:38p Lawrance
26  * Add support for jump node icons in the briefings.
27  * 
28  * 6     3/24/98 4:27p Lawrance
29  * Use new method for dimming lines
30  * 
31  * 5     3/24/98 12:05p Lawrance
32  * Don't set alpha color for jumpnode
33  * 
34  * 4     3/23/98 11:05a Lawrance
35  * Dim jump node as it get farther away
36  * 
37  * 3     3/21/98 7:43p Lawrance
38  * Disable jump node dimming until bug with alpha colors is fixed
39  * 
40  * 2     3/21/98 7:36p Lawrance
41  * Move jump nodes to own lib.
42  * 
43  * 1     3/21/98 3:53p Lawrance
44  *
45  * $NoKeywords: $
46  */
47
48 int Num_jump_nodes = 0;
49
50 #include "object.h"
51 #include "jumpnode.h"
52 #include "model.h"
53 #include "hud.h"
54
55 jump_node_struct Jump_nodes[MAX_JUMP_NODES];
56
57 void jumpnode_render(object *jumpnode_objp, vector *pos, vector *view_pos)
58 {
59         jump_node_struct        *node;
60         matrix                          node_orient = IDENTITY_MATRIX;
61
62         node = &Jump_nodes[jumpnode_objp->instance];
63
64         if ( Fred_running ) {
65                 model_set_outline_color(0, 255, 0);             
66                 model_render(node->modelnum, &node_orient, pos, MR_NO_LIGHTING | MR_LOCK_DETAIL | MR_NO_POLYS | MR_SHOW_OUTLINE );
67         } else {
68                 if ( view_pos ) {
69                         int alpha_index = HUD_color_alpha;
70
71                         // generate alpha index based on distance to jump node
72                         float dist;
73
74                         dist = vm_vec_dist_quick(view_pos, pos);
75
76                         // linearly interpolate alpha.  At 1000m or less, full intensity.  At 10000m or more 1/2 intensity.
77                         if ( dist < 1000 ) {
78                                 alpha_index = HUD_COLOR_ALPHA_USER_MAX - 2;
79                         } else if ( dist > 10000 ) {
80                                 alpha_index = HUD_COLOR_ALPHA_USER_MIN;
81                         } else {
82                                 alpha_index = fl2i( HUD_COLOR_ALPHA_USER_MAX - 2 + (dist-1000) * (HUD_COLOR_ALPHA_USER_MIN-HUD_COLOR_ALPHA_USER_MAX-2) / (9000) + 0.5f);
83                                 if ( alpha_index < HUD_COLOR_ALPHA_USER_MIN ) {
84                                         alpha_index = HUD_COLOR_ALPHA_USER_MIN;
85                                 }
86                         }
87
88         //              nprintf(("Alan","alpha index is: %d\n", alpha_index));
89                         gr_set_color_fast(&HUD_color_defaults[alpha_index]);
90 //                      model_set_outline_color(HUD_color_red, HUD_color_green, HUD_color_blue);
91
92                 } else {
93                         gr_set_color(HUD_color_red, HUD_color_green, HUD_color_blue);
94                 }
95                 model_render(node->modelnum, &node_orient, pos, MR_NO_LIGHTING | MR_LOCK_DETAIL | MR_NO_POLYS | MR_SHOW_OUTLINE_PRESET );
96         }
97
98 }
99
100 // create a jump node object and return index to it.
101 int jumpnode_create(vector *pos)
102 {
103         int obj;
104
105         Assert(Num_jump_nodes < MAX_JUMP_NODES);
106
107         Jump_nodes[Num_jump_nodes].modelnum = model_load(NOX("subspacenode.pof"), NULL, NULL);
108         if ( Jump_nodes[Num_jump_nodes].modelnum < 0 ) {
109                 Int3();
110                 return -1;
111         }
112
113         obj = obj_create(OBJ_JUMP_NODE, -1, Num_jump_nodes, NULL, pos, model_get_radius(Jump_nodes[Num_jump_nodes].modelnum), OF_RENDERS);
114         sprintf(Jump_nodes[Num_jump_nodes].name, XSTR( "Jump Node %d", 632), Num_jump_nodes);
115         if (obj >= 0) {
116                 Jump_nodes[Num_jump_nodes].objnum = obj;
117                 Num_jump_nodes++;
118         }
119         return obj;
120 }
121
122 // only called by FRED
123 void jumpnode_render_all()
124 {
125         int             i;
126         object  *jumpnode_objp;
127
128         for ( i = 0; i < Num_jump_nodes; i++ ) {        
129                 jumpnode_objp = &Objects[Jump_nodes[i].objnum];
130                 jumpnode_render(jumpnode_objp, &jumpnode_objp->pos);
131         }
132 }