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

Last change on this file was 80, checked in by Sam Hocevar, 12 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.3 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 "sound_man.hh"
10#include "objs/model_id.hh"
11#include "objs/model_draw.hh"
12#include "objs/rocktank.hh"
13#include "objs/verybiggun.hh"
14#include "input.hh"
15#include "math/pi.hh"
16#include "math/trig.hh"
17#include "math/angle.hh"
18#include "objs/bullet.hh"
19#include "resources.hh"
20#include "saver.hh"
21#include "map_cell.hh"
22#include "map.hh"
23#include "cell_id.hh"
24#include "sfx_id.hh"
25#include "object_definer.hh"
26
27static g1_object_type bullet;
28
29void g1_very_big_gun_init()
30{
31  bullet = g1_get_object_type("bullet");
32}
33
34g1_object_definer<g1_very_big_gun_class>
35g1_very_big_gun_def("verybiggun", SELECTABLE, g1_very_big_gun_init);
36
37g1_fire_range_type g1_very_big_gun_class::range()
38{
39  return (g1_fire_range_type)g1_very_big_gun_def.defaults->fire_range;
40}
41
42g1_very_big_gun_class::g1_very_big_gun_class(g1_object_type id,
43                                             g1_loader_class *fp)
44  : g1_map_piece_class(id,fp)
45
46  draw_params.setup("turret");
47  defaults = g1_very_big_gun_def.defaults;
48 
49  w16 ver,data_size;
50  if (fp)
51  { 
52    fp->get_version(ver,data_size);
53    if (ver==DATA_VERSION)
54    {
55    }
56    else
57    {
58      fp->seek(fp->tell() + data_size);
59      fire_delay = 15;
60      health     = 20;
61    }
62
63    fp->end_version(I4_LF);
64  }
65  else
66  {
67    fire_delay = 15;
68    health     = 20;
69  }
70
71  health = 200;
72
73  //no sound for now
74  //init_rumble_sound(g1_moving_engineering_vehicle_wav); 
75 
76  maxspeed   = 0; //doesnt move
77  turn_speed = defaults->turn_speed;
78
79  radar_type=G1_RADAR_BUILDING;
80  set_flag(BLOCKING      |
81           SELECTABLE    |
82           TARGETABLE    |
83           GROUND        |
84           HIT_GROUND    |
85           SHADOWED, 1);
86
87}
88
89void g1_very_big_gun_class::save(g1_saver_class *fp)
90{
91  g1_map_piece_class::save(fp);
92
93 
94  fp->start_version(DATA_VERSION);
95   
96  fp->end_version();
97 
98}
99
100
101void g1_very_big_gun_class::fire()
102{
103  if (attack_target.valid())
104  {   
105    i4_float tmp_x,tmp_y,tmp_z;
106 
107    fire_delay = defaults->fire_delay;
108
109    tmp_x = 0.4;
110    tmp_y = 0;   
111    tmp_z = 0.2;
112
113    i4_transform_class btrans,tmp1; 
114
115    i4_angle ang = theta;
116 
117    btrans.translate(0,0,0);
118
119    tmp1.rotate_z(ang);
120    btrans.multiply(tmp1);
121
122    tmp1.rotate_y(pitch);
123    btrans.multiply(tmp1);
124
125    tmp1.rotate_x(roll);
126    btrans.multiply(tmp1);
127
128    i4_3d_point_class tpoint;
129 
130    btrans.transform(i4_3d_point_class(tmp_x,tmp_y,tmp_z),tpoint);
131    i4_float bx,by,bz;
132
133    bx = tpoint.x + x;
134    by = tpoint.y + y;
135    bz = tpoint.z + h;   
136
137    i4_float b_dx,b_dy,b_dz;
138
139    btrans.transform(i4_3d_point_class(g1_resources.bullet_speed,0,0),tpoint);
140
141    b_dx = tpoint.x;
142    b_dy = tpoint.y;
143    b_dz = tpoint.z;   
144
145    g1_bullet_class *b = (g1_bullet_class *)g1_create_object(bullet);
146    if (b)
147    {
148      b->setup(bx, by, bz, b_dx, b_dy, b_dz, ang,pitch,roll,player_num,
149               i4_F,
150               defaults->damage,
151               defaults->fire_range
152               );
153
154      b->set_owner(this);   
155    }
156  }
157}
158
159
160void g1_very_big_gun_class::think()
161
162  check_life();
163
164  if (find_new_target)
165    find_target();
166
167  if (health < 200)
168    health++;
169
170  pitch = groundpitch*cos(theta) - groundroll *sin(theta);
171  roll  = groundroll *cos(theta) + groundpitch*sin(theta);
172
173  if (fire_delay>0)
174    fire_delay--;
175
176  //aim the turet
177  if (attack_target.valid())
178  {
179    request_think();
180
181    i4_float dx,dy,angle;
182
183    //this will obviously only be true if attack_target.ref != NULL   
184    dx = (attack_target->x - x);
185    dy = (attack_target->y - y);
186
187    //aim the turet
188   
189    angle = i4_atan2(dy,dx);
190   
191    //snap it
192    i4_normalize_angle(angle);   
193   
194    if (!i4_rotate_to(theta,angle,turn_speed))
195      if (!fire_delay)
196        fire();
197  } 
198}
Note: See TracBrowser for help on using the repository browser.