source: golgotha/src/golg/objs/miracle.cc

Last change on this file was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 4.7 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "g1_object.hh"
10#include "math/num_type.hh"
11#include "math/random.hh"
12#include "object_definer.hh"
13#include "map.hh"
14#include "map_man.hh"
15#include "g1_render.hh"
16#include "r1_api.hh"
17#include "g1_texture_id.hh"
18#include "r1_clip.hh"
19#include "objs/miracle.hh"
20#include "sound_man.hh"
21#include "sfx_id.hh"
22
23g1_object_definer<g1_miracle_class>
24g1_miracle_def("miracle", g1_object_definition_class::EDITOR_SELECTABLE);
25
26g1_miracle_class::g1_miracle_class(g1_object_type id,
27                                   g1_loader_class *fp)
28  : g1_object_class(id,fp)
29{   
30 
31  miracle_sound = g1_sound_man.alloc_dynamic_3d_sound(g1_sfx_misc_electric_car_charged);
32  electric_arcs = new i4_array<arc_point_list_struct>(4,4);
33}
34
35void g1_miracle_class::save(g1_saver_class *fp)
36{
37  g1_object_class::save(fp);
38
39  fp->start_version(DATA_VERSION);
40
41  fp->end_version();
42}
43
44g1_miracle_class::~g1_miracle_class()
45{
46  //make sure the sound gets deallocated
47  if (miracle_sound)
48  {
49    g1_sound_man.free_dynamic_3d_sound(miracle_sound);
50    miracle_sound = 0;
51  }   
52}
53
54void g1_miracle_class::draw(g1_draw_context_class *context)
55
56  sw32 i,j;
57
58  if (!electric_arcs)
59    return;
60
61  for (i=0; i<electric_arcs->size(); i++)
62  {
63    arc_point_struct *points = (*electric_arcs)[i].arc_points;
64   
65    i4_3d_point_class pts[NUM_ARC_POINTS];
66
67    for (j=0; j<NUM_ARC_POINTS; j++)
68    {
69      pts[j].interpolate(points[j].lposition, points[j].position, g1_render.frame_ratio);
70    }
71 
72    g1_render.add_translucent_trail(context->transform,
73                                    pts,
74                                    NUM_ARC_POINTS,
75                                    0.02f   , 0.02f,
76                                    1.f     , 1.f,
77                                    0xFFFFFF, 0xFFFFFF);
78
79  }
80}
81
82void g1_miracle_class::think()
83{
84}
85
86void g1_miracle_class::setup(g1_convoy_class *convoy_to_attack, w32 _miracle_type, i4_3d_vector pos)
87{
88  x = pos.x;
89  y = pos.y;
90  h = pos.z;
91 
92  grab_old();
93
94  occupy_location();
95
96  convoy       = convoy_to_attack;
97  miracle_type = _miracle_type;
98 
99  health       = 10;
100 
101  request_think();
102}
103
104void g1_miracle_class::post_think()
105{
106  if (health < 0 || !convoy.valid() || !electric_arcs)
107  {
108    if (electric_arcs)
109    {
110      delete electric_arcs;
111      electric_arcs = 0;
112    }
113
114    unoccupy_location();
115    request_remove();
116    return;
117  }
118 
119  request_think();
120
121  health--;
122
123  sw32 i;
124
125  sw32 num_needed = 0;
126  for (i=0; i<g1_convoy_class::CONVOY_SIZE; i++)
127  {
128    g1_map_piece_class *mp = convoy->get_member(i);
129    if (mp)
130    {
131      num_needed++;
132           
133      arc_point_list_struct *points;
134     
135      if (electric_arcs->size() < num_needed)
136      {
137        points = electric_arcs->add();
138        new_arc_points(i4_3d_vector(x,y,h+3),
139                       i4_3d_vector(mp->x,mp->y,mp->h),
140                       points->arc_points);
141        copy_old_points(points->arc_points);
142      }
143      else
144      {
145        points = &(*electric_arcs)[num_needed-1];
146       
147        copy_old_points(points->arc_points);
148        new_arc_points(i4_3d_vector(x,y,h+3),
149                       i4_3d_vector(mp->x,mp->y,mp->h),
150                       points->arc_points);
151      }
152    }
153  }
154}
155
156void g1_miracle_class::copy_old_points(arc_point_struct *points)
157{
158  sw32 i,j;
159 
160  for (j=0; j<NUM_ARC_POINTS; j++)
161  {
162    points[j].lposition = points[j].position;
163  }
164}
165
166void g1_miracle_class::new_arc_points(i4_3d_vector src, i4_3d_vector dest, arc_point_struct *points)
167{
168  i4_float rx,ry,rz,px,py,pz;
169  i4_float map_point_height;
170 
171  i4_3d_vector vec1;
172
173  vec1 = dest;
174  vec1 -= src;
175
176  sw32 i;
177
178  for (i=0; i<NUM_ARC_POINTS; i++)
179  {
180    //ARC #1
181    i4_float random_scale = (1 - (i/(NUM_ARC_POINTS-1)))*3;
182   
183    rx = (g1_float_rand(6) * 0.4 - 0.2) * random_scale;
184    ry = (g1_float_rand(4) * 0.4 - 0.2) * random_scale;
185    rz = (g1_float_rand(2) * 0.4 - 0.2) * random_scale;
186   
187    px = src.x + vec1.x*i/(NUM_ARC_POINTS-1) + rx;
188    py = src.y + vec1.y*i/(NUM_ARC_POINTS-1) + ry;
189    pz = src.z + vec1.z*i/(NUM_ARC_POINTS-1) + rz;
190   
191    points[i].position = i4_3d_vector(px,py,pz);
192  }
193}
Note: See TracBrowser for help on using the repository browser.