source: golgotha/src/golg/objs/dropped_bomb.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.5 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/dropped_bomb.hh"
17#include "tile.hh"
18#include "objs/explosion1.hh"
19#include "objs/shockwave.hh"
20#include "saver.hh"
21#include "objs/map_piece.hh"
22#include "objs/smoke_trail.hh"
23#include "map.hh"
24#include "map_man.hh"
25#include "resources.hh"
26#include "object_definer.hh"
27
28static g1_object_type smoke_trail_type, explosion_type, shockwave;
29void g1_dropped_bomb_init()
30{
31  smoke_trail_type = g1_get_object_type("smoke_trail");
32  explosion_type = g1_get_object_type("explosion1");
33  shockwave = g1_get_object_type("shockwave");
34}
35
36g1_object_definer<g1_dropped_bomb_class>
37g1_dropped_bomb_def("dropped_bomb",
38                    g1_object_definition_class::MOVABLE,
39                    g1_dropped_bomb_init);
40
41S1_SFX(mo_money, "explosion/ariplane_bomb_explosion_one_22khz.wav", S1_STREAMED | S1_3D, 70);
42
43void g1_dropped_bomb_class::draw(g1_draw_context_class *context)
44{
45  g1_model_draw(this, draw_params, context);
46  if (smoke_trail.valid())
47    smoke_trail->draw(context);
48}
49
50g1_dropped_bomb_class::g1_dropped_bomb_class(g1_object_type id,
51                                             g1_loader_class *fp)
52  : g1_object_class(id, fp)
53{
54  draw_params.setup("jetbomb");
55
56  w32 i;
57
58  if (fp && fp->check_version(DATA_VERSION))
59  {   
60    fp->read_reference(who_fired_me);   
61    fp->read_reference(smoke_trail);
62    fp->read_16();                        // old damage amount
63    fp->end_version(I4_LF);
64  }
65
66  radar_type=G1_RADAR_WEAPON; 
67  set_flag(AERIAL        |
68           HIT_GROUND    |
69           SHADOWED, 1);
70}
71
72void g1_dropped_bomb_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_dropped_bomb_class::think()
87{   
88  z_velocity -= g1_resources.gravity*0.5;
89  speed *= 0.7;
90  i4_rotate_to(pitch,i4_pi(),0.2);
91 
92  if (move(i4_3d_vector(cos(theta)*speed, sin(theta)*speed, z_velocity)))
93    request_think();
94}
95
96void g1_dropped_bomb_class::setup(const i4_3d_vector &pos,
97                                  g1_object_class *this_guy_fired_me)
98{
99  w32 i;
100
101  x=lx=pos.x;
102  y=ly=pos.y;
103  h=lh=pos.z;
104  theta = this_guy_fired_me->theta;
105 
106  z_velocity = 0;
107  speed = get_type()->get_damage_map()->speed;
108
109  who_fired_me = this_guy_fired_me;
110  player_num = this_guy_fired_me->player_num;
111  request_think();
112  occupy_location();
113}
114
115void g1_dropped_bomb_class::delete_smoke()
116{
117  if (smoke_trail.valid())
118  {
119    g1_object_class *s=smoke_trail.get();
120    s->unoccupy_location();
121    s->request_remove();
122    smoke_trail=0;
123  }
124}
125
126
127i4_bool g1_dropped_bomb_class::move(const i4_3d_vector &vel)
128{
129//   g1_smoke_trail_class *s;
130   
131//   if (!smoke_trail.valid())
132//   {
133//     s=(g1_smoke_trail_class *)g1_create_object(smoke_trail_type);
134//     if (s)
135//     {
136//       s->setup(x, y, h, 0.02, 0.05, 0x0000ff, 0xffffff);   // blue to white
137//       s->occupy_location();
138//       smoke_trail=s;
139//     }
140//   } else s=(g1_smoke_trail_class *)smoke_trail.get();
141
142
143  unoccupy_location();
144     
145  i4_3d_vector pos(x,y,h),ray(vel);
146  g1_object_class *tmphit;
147  int hit = g1_get_map()->check_non_player_collision(player_num,pos,ray,tmphit);
148  pos += ray;
149  if (hit)
150  {
151    if (hit>0)
152    {
153      g1_explosion1_class *exp = (g1_explosion1_class *)g1_create_object(explosion_type);
154      if (exp)
155        exp->setup(pos.x,pos.y,pos.z);
156      g1_apply_damage(this, who_fired_me.get(), 0, vel);
157    }
158    delete_smoke();
159    request_remove();
160    return i4_F;
161  }
162
163  x = pos.x;
164  y = pos.y;
165  h = pos.z;
166  occupy_location();
167//   if (s)
168//     s->update_head(x,y,h);
169
170  return i4_T; 
171}
172
Note: See TracBrowser for help on using the repository browser.