source: golgotha/src/golg/objs/trike.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.6 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 "input.hh"
13#include "math/pi.hh"
14#include "math/trig.hh"
15#include "math/angle.hh"
16#include "objs/bullet.hh"
17#include "resources.hh"
18#include "saver.hh"
19#include "map_cell.hh"
20#include "map.hh"
21#include "math/angle.hh"
22#include "objs/vehic_sounds.hh"
23#include "sound/sfx_id.hh"
24#include "objs/trike.hh"
25#include "objs/shrapnel.hh"
26#include "math/random.hh"
27#include "object_definer.hh"
28
29
30static g1_model_ref model_ref("trike_body"),
31  shadow_ref("trike_shadow"),
32  wheel_ref("trike_wheels"),
33  lod_ref("trike_lod");
34
35static g1_object_type shrapnel_type;
36static i4_3d_vector wheel_attach, wheel_offset;
37
38void g1_trike_init()
39{
40  shrapnel_type = g1_get_object_type("shrapnel");
41
42  wheel_attach.set(0.1,0,0.03);
43  model_ref()->get_mount_point("Wheel", wheel_attach);
44
45  wheel_offset.set(0.1,0,0.03);
46  wheel_ref()->get_mount_point("Wheel", wheel_offset);
47  wheel_offset.reverse();
48}
49
50g1_object_definer<g1_trike_class>
51g1_trike_def("trike",
52             g1_object_definition_class::TO_MAP_PIECE |
53             g1_object_definition_class::MOVABLE |
54             g1_object_definition_class::EDITOR_SELECTABLE,
55             g1_trike_init);
56
57
58//think and draw functions
59
60g1_trike_class::g1_trike_class(g1_object_type id,
61                                     g1_loader_class *fp)
62  : g1_map_piece_class(id, fp)
63
64  radar_type=G1_RADAR_VEHICLE;
65  set_flag(BLOCKING      |
66           TARGETABLE    |
67           GROUND        |
68           HIT_GROUND    |
69           DANGEROUS, 1);
70
71  draw_params.setup(model_ref.id(), 0, lod_ref.id());
72       
73  allocate_mini_objects(2,"Trike Mini-Objects");
74
75  wheels = &mini_objects[0];
76  wheels->defmodeltype = wheel_ref.id();
77  wheels->position(wheel_attach);
78  wheels->offset = wheel_offset;
79
80  w16 ver,data_size;
81  if (fp)
82  {
83    fp->get_version(ver,data_size);
84    if (ver==DATA_VERSION)
85    {
86      wheels->rotation.x = fp->read_float();
87      wheels->rotation.y = fp->read_float();
88      wheels->rotation.z = fp->read_float();
89 
90      wheels->lrotation.x = fp->read_float();
91      wheels->lrotation.y = fp->read_float();
92      wheels->lrotation.z = fp->read_float(); 
93    }
94    else
95    {
96      fp->seek(fp->tell() + data_size);
97    }
98
99    fp->end_version(I4_LF);
100  }
101  else
102  {
103    wheels->rotation.x = 0;
104    wheels->rotation.y = 0;
105    wheels->rotation.z = 0; 
106    wheels->lrotation = wheels->rotation;
107  } 
108
109  init_rumble_sound(G1_RUMBLE_GROUND);
110}
111   
112void g1_trike_class::save(g1_saver_class *fp)
113{
114  g1_map_piece_class::save(fp);
115
116  fp->start_version(DATA_VERSION);
117
118  fp->write_float(wheels->rotation.x);
119  fp->write_float(wheels->rotation.y);
120  fp->write_float(wheels->rotation.z);
121
122  fp->write_float(wheels->lrotation.x);
123  fp->write_float(wheels->lrotation.y);
124  fp->write_float(wheels->lrotation.z);
125
126  fp->end_version();
127}
128
129void g1_trike_class::think()
130{
131  g1_map_piece_class::think();
132
133  if (!alive())
134    return;
135
136  if (attack_target.valid())
137  {   
138    request_think();
139
140    dest_x = attack_target->x;
141    dest_y = attack_target->y;
142
143    i4_float dist, dtheta, dx, dy;
144    suggest_move(dist, dtheta, dx, dy, 0);
145    move(dx,dy);
146
147    const i4_float KILL_RADIUS=0.5;
148
149    //if we've run into the guy
150    if (x > dest_x-KILL_RADIUS  &&  y > dest_y-KILL_RADIUS  &&
151        x < dest_x+KILL_RADIUS  &&  y < dest_y+KILL_RADIUS)
152    {
153      int damage=g1_trike_def.get_damage_map()->get_damage_for(attack_target.get()->id);
154
155      //hurt the dude
156      attack_target->damage(this,damage,i4_3d_vector(dx,dy,0));
157     
158      //throw some gibs
159      g1_shrapnel_class *shrapnel = NULL;
160      shrapnel = (g1_shrapnel_class *)g1_create_object(shrapnel_type);
161      if (shrapnel)
162      {
163        i4_float rx,ry,rh;
164        rx = (i4_rand()&0xFFFF)/((i4_float)0xFFFF) * 0.2;
165        ry = (i4_rand()&0xFFFF)/((i4_float)0xFFFF) * 0.2;
166        rh = (i4_rand()&0xFFFF)/((i4_float)0xFFFF) * 0.2;
167        shrapnel->setup(x+rx,y+ry,h + rh,6,i4_T);
168      }
169      unoccupy_location();
170      request_remove();
171    }     
172  }
173}
174
Note: See TracBrowser for help on using the repository browser.