source: golgotha/src/golg/objs/super_mortar.cc @ 80

Last change on this file since 80 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 "objs/model_draw.hh"
11#include "math/num_type.hh"
12#include "math/pi.hh"
13#include "math/angle.hh"
14#include "math/trig.hh"
15#include "math/random.hh"
16#include "objs/super_mortar.hh"
17#include "tile.hh"
18#include "objs/shockwave.hh"
19#include "saver.hh"
20#include "objs/map_piece.hh"
21#include "objs/smoke_trail.hh"
22#include "map.hh"
23#include "map_man.hh"
24#include "resources.hh"
25#include "object_definer.hh"
26#include "sound/sfx_id.hh"
27
28
29
30static g1_object_type smoke_trail_type, shockwave;
31void g1_super_mortar_init()
32{
33  smoke_trail_type = g1_get_object_type("smoke_trail");
34  shockwave = g1_get_object_type("shockwave");
35}
36
37g1_object_definer<g1_super_mortar_class>
38g1_super_mortar_def("super_mortar", 0, g1_super_mortar_init);
39
40
41void g1_super_mortar_class::draw(g1_draw_context_class *context)
42{
43  g1_model_draw(this, draw_params, context);
44  if (smoke_trail.valid())
45    smoke_trail->draw(context);
46}
47
48g1_super_mortar_class::g1_super_mortar_class(g1_object_type id,
49                                             g1_loader_class *fp)
50  : g1_object_class(id, fp)
51{
52  draw_params.setup("jetbomb");
53
54  w32 i;
55
56  if (fp && fp->check_version(DATA_VERSION))
57  {   
58    fp->read_reference(who_fired_me);   
59    fp->read_reference(smoke_trail);
60    fp->read_16();                   // old damage amount
61    fp->end_version(I4_LF);
62  }
63
64  radar_type=G1_RADAR_WEAPON; 
65  set_flag(AERIAL        |
66           HIT_GROUND    |
67           SHADOWED, 1);
68 
69  //  rumble_sound = g1_sound_man.alloc_dynamic_3d_sound(g1_sfx_misc_turbine1);
70}
71
72void g1_super_mortar_class::save(g1_saver_class *fp)
73{
74  // save data associated with base classes
75  g1_object_class::save(fp);
76
77  fp->start_version(DATA_VERSION);
78 
79  fp->write_reference(who_fired_me);
80  fp->write_reference(smoke_trail);
81  fp->write_16(0);                     // old damage_amount
82
83  fp->end_version();
84}
85
86void g1_super_mortar_class::think()
87{   
88  i4_rotate_to(pitch,i4_pi(),0.2);
89
90
91  if (move(vel))
92  {
93    request_think();
94    vel.z -= g1_resources.gravity;
95//     if (rumble_sound)
96//       g1_sound_man.update_dynamic_3d_sound(rumble_sound, i4_3d_vector(x,y,h), vel,1.0);
97  }
98  else
99  {   
100    who_fired_me=0;
101    delete_smoke();
102    unoccupy_location();
103    request_remove();
104//     if (rumble_sound)
105//     {
106//       g1_sound_man.free_dynamic_3d_sound(rumble_sound);
107//       rumble_sound = 0;
108//     }
109  }
110}
111
112void g1_super_mortar_class::setup(const i4_3d_vector &pos,
113                                  const i4_3d_vector &dir,
114                                  g1_object_class *this_guy_fired_me)
115{
116  w32 i;
117  x=lx=pos.x;
118  y=ly=pos.y;
119  h=lh=pos.z;
120 
121  vel = dir;
122
123  who_fired_me = this_guy_fired_me;
124  player_num = this_guy_fired_me->player_num;
125
126  ltheta=theta = i4_atan2(dir.y, dir.x);   
127  pitch=lpitch = i4_atan2(-dir.z, sqrt(dir.x * dir.x +
128                                       dir.y * dir.y));
129  lroll=roll   = 0;
130 
131
132  occupy_location();
133  request_think();
134}
135
136void g1_super_mortar_class::delete_smoke()
137{
138  if (smoke_trail.valid())
139  {
140    g1_object_class *s=smoke_trail.get();
141    s->unoccupy_location();
142    s->request_remove();
143    smoke_trail=0;
144  }
145}
146
147
148i4_bool g1_super_mortar_class::move(i4_3d_vector &vel)
149{
150  g1_smoke_trail_class *s;
151  if (!smoke_trail.valid())
152  {
153    s=(g1_smoke_trail_class *)g1_create_object(smoke_trail_type);
154    if (s)
155    {
156      s->setup(x, y, h, 0.02, 0.05, 0x0000ff, 0xffffff);   // blue to white
157      s->occupy_location();
158      smoke_trail=s;
159    }
160  } else s=(g1_smoke_trail_class *)smoke_trail.get();
161
162  i4_3d_vector pos(x,y,h);
163  g1_object_class *tmp_hit;
164  int hit;
165 
166  hit = g1_get_map()->check_non_player_collision(player_num, pos, vel, tmp_hit);
167  pos += vel;
168
169  if (hit<0)
170    // off the map
171    return i4_F;
172  else if (hit>0 && !tmp_hit)
173  {
174    // hit ground
175    g1_shockwave_class *shock = NULL;
176    shock = (g1_shockwave_class *)g1_create_object(shockwave);
177    if (shock)
178      shock->setup(pos, 0.5);
179
180    g1_apply_damage(this, who_fired_me.get(), tmp_hit, vel);
181
182    return i4_F;   
183  }
184
185  unoccupy_location();
186  x = pos.x;
187  y = pos.y;
188  h = pos.z;
189  occupy_location();
190
191  if (s)
192    s->update_head(x,y,h);
193
194  return i4_T; 
195}
196
Note: See TracBrowser for help on using the repository browser.