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