source: golgotha/src/golg/objs/base_launcher.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: 3.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 "sound_man.hh"
10#include "objs/model_id.hh"
11#include "objs/model_draw.hh"
12#include "objs/rocktank.hh"
13#include "objs/base_launcher.hh"
14#include "input.hh"
15#include "math/pi.hh"
16#include "math/angle.hh"
17#include "math/trig.hh"
18#include "objs/buster_rocket.hh"
19#include "resources.hh"
20#include "saver.hh"
21#include "object_definer.hh"
22#include "objs/fire.hh"
23#include "lisp/lisp.hh"
24
25static g1_object_type buster, stank;
26
27void g1_base_launcher_init()
28{
29  buster = g1_get_object_type("buster_rocket");
30  stank = g1_get_object_type("stank");
31}
32
33g1_object_definer<g1_base_launcher_class>
34g1_base_launcher_def("base_launcher",
35                     g1_object_definition_class::EDITOR_SELECTABLE,
36                     g1_base_launcher_init);
37
38
39g1_base_launcher_class::g1_base_launcher_class(g1_object_type id,
40                                             g1_loader_class *fp)
41  : g1_map_piece_class(id,fp)
42
43  defaults = g1_base_launcher_def.defaults;
44
45  draw_params.setup("rocket_truck_top","rocket_truck_shadow");
46 
47  w16 ver,data_size;
48  if (fp)
49  { 
50    fp->get_version(ver,data_size);
51    if (ver==DATA_VERSION)
52    {
53      fp->end_version(I4_LF);
54    }
55    else
56      fp->seek(fp->tell() + data_size);
57  }
58
59  fire_delay = 0;
60  health = 1000;
61
62  //no sound for now
63  radar_type=G1_RADAR_WEAPON;
64  set_flag(AERIAL        |
65           HIT_GROUND    |
66           SHADOWED, 1);
67}
68
69i4_bool g1_base_launcher_class::can_attack(g1_object_class *who) const
70{
71  return (who->id == stank);
72}
73
74void g1_base_launcher_class::save(g1_saver_class *fp)
75{
76  g1_map_piece_class::save(fp);
77
78  fp->start_version(DATA_VERSION);
79  fp->end_version();
80}
81
82   
83void g1_base_launcher_class::fire()
84{
85  if (attack_target.valid())
86  {
87    i4_transform_class o2w;   
88    calc_world_transform(1,&o2w);
89
90    i4_3d_vector local_fire_point;   
91    i4_3d_vector world_fire_point, world_fire_dir;
92    o2w.transform(i4_3d_vector(0.4, 0, 0.2), world_fire_point);
93    o2w.transform(i4_3d_vector(1,0,0.2), world_fire_dir);
94    world_fire_dir-=world_fire_point;
95   
96    g1_fire(li_get_symbol("buster_rocket"), this, attack_target.get(),
97                          world_fire_point, world_fire_dir);   
98  }
99}
100
101i4_bool g1_base_launcher_class::occupy_location()
102{
103  h += 0.9;
104  lh = h;
105
106  return g1_map_piece_class::occupy_location();
107}
108
109
110void g1_base_launcher_class::think()
111
112  find_target();
113
114  // can't hurt me.... I'm invincible!
115  health = 1000;
116
117  pitch = 0;//groundpitch;//*cos(theta) - groundroll *sin(theta);
118  roll  = 0;//groundroll;// *cos(theta) + groundpitch*sin(theta);
119
120  if (fire_delay)
121    fire_delay--;
122 
123  //aim the turet
124  if (attack_target.valid())
125  {
126    request_think();
127         
128    i4_float dx,dy,angle,dangle;
129
130    //this will obviously only be true if attack_target.ref != NULL   
131    dx = (attack_target->x - x);
132    dy = (attack_target->y - y);
133
134    //aim the turet
135   
136    angle = i4_atan2(dy,dx);
137   
138    //snap it
139    i4_normalize_angle(angle);   
140   
141    dangle = i4_rotate_to(theta,angle,defaults->turn_speed);
142    if (dangle<defaults->turn_speed && dangle>-defaults->turn_speed)
143      if (!fire_delay)
144        fire();
145  } 
146}
147
Note: See TracBrowser for help on using the repository browser.