source: golgotha/src/golg/objs/fire.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: 5.9 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 "lisp/lisp.hh"
11#include "sound_man.hh"
12#include "objs/bullet.hh"
13#include "objs/buster_rocket.hh"
14#include "objs/beam_weapon.hh"
15#include "objs/guided_missile.hh"
16#include "objs/super_mortar.hh"
17#include "objs/dropped_bomb.hh"
18#include "objs/bolt.hh"
19#include "resources.hh"
20#include "objs/defaults.hh"
21#include "g1_rand.hh"
22#include "sound/sfx_id.hh"
23#include "player.hh"
24
25static li_symbol_ref b90mm("b90mm"), b120mm("b120mm"),
26  buster_rocket("buster_rocket"), heavy_rocket("heavy_rocket"),
27  chain_gun("chain_gun"), plasma("plasma"), beam("beam"),
28  napalm("napalm"), acid("acid"),
29  vortex("vortex_missile"), nuke("nuke_missile"),
30  guided_missile("guided_missile"),
31  dropped_bomb("dropped_bomb"),
32  super_mortar("super_mortar"),
33  bolt("bolt"),
34  light_type("lightbulb");
35
36
37S1_SFX(small_fire_sfx, "fire/peon_tank.wav", S1_3D, 30);
38S1_SFX(missile_fire_sfx, "fire/missile_truck.wav", S1_3D, 30);
39S1_SFX(chain_fire_sfx, "fire/machine_gun_fire_22khz_lp.wav", S1_3D, 50);
40S1_SFX(b120mm_sfx, "fire/supertank/main1.wav", S1_3D, 50);
41S1_SFX(napalm_sfx, "fire/supertank_plazma_fireball_22khz.wav", S1_3D, 50);
42
43S1_SFX(supergun_fire, "fire/big_begrtha_gun_fire_22khz.wav", S1_STREAMED, 200);
44S1_SFX(acid_sfx, "fire/supertank_acid_main_barrel_interrior_22khz.wav", S1_3D, 200);
45S1_SFX(stank_missile_sfx, "fire/supertank_fires_rocket_22khz.wav", S1_3D, 200);
46
47static r1_texture_ref chain_gun_texture("auto1");
48
49g1_object_class *g1_fire(li_symbol *fire_type,
50                         g1_object_class *who_is_firing,
51                         g1_object_class *who_firing_at,
52                         const i4_3d_vector &start_pos,
53                         const i4_3d_vector &direction,
54                         g1_object_class *last_object_fired)
55{
56  int otype=g1_get_object_type(fire_type);
57  if (!otype)
58    return 0;
59
60  g1_object_class *o=0; 
61  if (fire_type==bolt.get() && last_object_fired)
62    o=last_object_fired;
63 
64  if (!o)
65  {
66    o=g1_create_object(otype);
67    if (who_is_firing && o)
68      o->player_num=who_is_firing->player_num;
69  }
70 
71  if (!o)
72    return 0;
73
74  g1_damage_map_struct *dmap=o->get_type()->get_damage_map(); 
75  float range=dmap->range;
76
77
78  if (fire_type==b90mm.get() ||
79      fire_type==b120mm.get() ||
80      fire_type==napalm.get() ||
81      fire_type==acid.get())
82  {
83    if (fire_type==acid.get())
84      acid_sfx.play(start_pos.x, start_pos.y, start_pos.z);
85    else if (fire_type==b120mm.get())
86      b120mm_sfx.play(start_pos.x, start_pos.y, start_pos.z);
87    else if (fire_type==napalm.get())
88      napalm_sfx.play(start_pos.x, start_pos.y, start_pos.z);
89    else
90      small_fire_sfx.play(start_pos.x, start_pos.y, start_pos.z);
91
92    i4_3d_vector vel=direction;
93    vel.normalize();             
94    vel*=dmap->speed;
95
96
97    float r,g,bl;
98    if (fire_type==b90mm.get() || fire_type==b120mm.get())
99      r=g=bl=1;
100    else  if (fire_type==napalm.get())
101    { r=1; g=0.5; bl=0; }
102    else if (fire_type==acid.get())
103    { r=0; g=1; bl=0; }
104       
105
106
107    g1_light_object_class *light;
108    light = (g1_light_object_class *)g1_create_object(g1_get_object_type(light_type.get()));
109
110    light->setup(start_pos.x, start_pos.y, start_pos.z, r,g,bl, 1);
111    light->occupy_location();
112
113
114    g1_bullet_class *b=((g1_bullet_class *)o);
115    b->setup(start_pos, vel, who_is_firing, range, g1_bullet_class::SPINS, 0, light);
116
117  }
118  else if (fire_type==buster_rocket.get())
119  {
120    ((g1_buster_rocket_class *)o)->setup(start_pos, direction, who_is_firing, who_firing_at);
121   
122  } else if (
123           fire_type==heavy_rocket.get() ||
124           fire_type==vortex.get() ||
125           fire_type==nuke.get())
126  {
127    stank_missile_sfx.play(start_pos.x, start_pos.y, start_pos.z);
128    ((g1_buster_rocket_class *)o)->setup(start_pos, direction, who_is_firing, who_firing_at);
129  }
130
131  else if (fire_type==beam.get() ||
132           fire_type==plasma.get())
133    ((g1_beam_weapon_class *)o)->setup(start_pos, direction, who_is_firing, 6.0);
134  else if (fire_type==chain_gun.get())
135  {
136    i4_3d_vector pos=start_pos;
137
138    float spread=0.1, spread_sub=0.05;
139   
140    pos.x+=g1_float_rand(2)*spread - spread_sub;
141    pos.y+=g1_float_rand(3)*spread - spread_sub;
142    pos.z+=g1_float_rand(8)*spread - spread_sub;
143   
144    i4_3d_vector vel=direction;
145    vel.normalize();             
146    vel*=dmap->speed;
147
148 
149    ((g1_bullet_class *)o)->setup(pos, vel, who_is_firing, range,
150                                  g1_bullet_class::IS_SPRITE, chain_gun_texture.get());
151    chain_fire_sfx.play(start_pos.x, start_pos.y, start_pos.z);
152  }
153  else if (fire_type==guided_missile.get())   
154  {
155    missile_fire_sfx.play(start_pos.x, start_pos.y, start_pos.z);
156    //    g1_sound_man.play(STATIC_3D_SOUND,g1_sfx_fire_missile_truck, start_pos);
157    ((g1_guided_missile_class *)o)->setup(start_pos, direction,
158                                          who_is_firing, who_firing_at);
159  }
160  else if (fire_type==dropped_bomb.get())
161  {
162    ((g1_dropped_bomb_class *)o)->setup(start_pos, who_is_firing);
163  }
164  else if (fire_type==super_mortar.get())
165  {
166    ((g1_super_mortar_class *)o)->setup(start_pos, direction, who_is_firing); 
167    supergun_fire.play();
168  }
169  else if (fire_type==bolt.get())
170  {
171    if (who_firing_at)
172      ((g1_bolt_class *)o)->setup(start_pos, i4_3d_vector(0,0,0), who_is_firing, who_firing_at);
173  }
174  else
175  {
176    delete o;
177    o=0;
178  }
179 
180  return o;
181
Note: See TracBrowser for help on using the repository browser.