source: golgotha/src/golg/objs/bank.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.7 KB
RevLine 
[80]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 "player.hh"
10#include "objs/def_object.hh"
11#include "lisp/li_class.hh"
12#include "li_objref.hh"
13#include "controller.hh"
14#include "object_definer.hh"
15#include "objs/moneycrate.hh"
16#include "objs/bank.hh"
17#include "image_man.hh"
18
19static g1_team_icon_ref bank_radar_im("bitmaps/radar/bank.tga");
20
21static li_symbol_ref crate_obj("moneycrate"), moneyplane("moneyplane");
22
23static li_int_class_member li_income_time("income_time"),
24  li_moneyplanes("moneyplanes"),
25  li_time("time"),
26  li_crates("crates"),
27  li_crate_value("crate_value"),
28  li_crate_capacity("crate_capacity"),
29  li_ticks_till_next_deploy("ticks_till_next_deploy"),
30  li_reset_time_in_ticks("reset_time_in_ticks");
31
32static li_g1_ref_class_member li_crate("crate");
33static li_symbol_ref li_sym_crate("moneycrate");
34
35static g1_model_ref model_ref("bank");
36static i4_3d_vector crate_platform;
37
38i4_isl_list<g1_bank_class> g1_bank_list[G1_MAX_PLAYERS];
39int g1_bank_list_count[G1_MAX_PLAYERS] = { 0 };
40
41S1_SFX(bank_secured, "narrative/bank_captured_22khz.wav", S1_STREAMED, 200);
42S1_SFX(bank_lost, "narrative/bank_lost_22khz.wav", S1_STREAMED, 200);
43
44static void g1_bank_init()
45{
46  crate_platform.set(0,0,3.0);
47  model_ref()->get_mount_point("crate", crate_platform);
48}
49
50g1_object_definer<g1_bank_class>
51g1_bank_def("bank", g1_object_definition_class::EDITOR_SELECTABLE, g1_bank_init);
52
53g1_bank_class::g1_bank_class(g1_object_type id, g1_loader_class *fp)
54  : g1_factory_class(id,fp)
55{
56  radar_type=G1_RADAR_BUILDING;
57
58  radar_image=&bank_radar_im;
59
60  set_flag(BLOCKING      |
61           TARGETABLE    |
62           SELECTABLE, 1);
63}
64 
65g1_moneycrate_class* g1_bank_class::crate()
66{
67  li_class_context context(vars);
68  g1_moneycrate_class *c=(g1_moneycrate_class *)li_crate()->value();
69  return c;
70}
71
72void g1_bank_class::set_crate(g1_moneycrate_class *cr)
73{
74  vars->set(li_crate, new li_g1_ref(cr));
75}
76
77i4_bool g1_bank_class::occupy_location()
78{
79  if (!g1_factory_class::occupy_location())
80    return i4_F;
81
82  i4_transform_class t;
83  calc_world_transform(1.0,&t);
84  t.transform(crate_platform,crate_pos);
85
86  g1_bank_list[player_num].insert(*this);
87  g1_bank_list_count[player_num]++;
88
89  request_think();
90  return i4_T;
91}
92
93void g1_bank_class::unoccupy_location()
94{
95  g1_factory_class::unoccupy_location();
96  g1_bank_list[player_num].find_and_unlink(this);
97  g1_bank_list_count[player_num]--;
98}
99 
100void g1_bank_class::change_player_num(int new_team)
101{
102  if (new_team!=player_num)
103  {
104    g1_bank_list[player_num].find_and_unlink(this);
105    g1_bank_list_count[player_num]--;
106    g1_bank_list[new_team].insert(*this);
107    g1_bank_list_count[new_team]++;
108     
109    if (new_team==g1_player_man.local_player)
110    {
111      if (g1_current_controller.get())
112        g1_current_controller->add_spin_event("powerup_bank", 0);
113      bank_secured.play();
114    }
115     
116    if (player_num==g1_player_man.local_player)
117    {
118      if (g1_current_controller.get())
119        g1_current_controller->add_spin_event("powerup_bank", 1);
120      bank_lost.play();
121    }
122  }
123  g1_factory_class::change_player_num(new_team);
124}
125
126void g1_bank_class::think()
127{
128  if (!death.think())
129    return;
130
131  int time = li_time();
132  if (time>0)
133    time--;
134  else
135  {
136    if (li_crates()<li_crate_capacity())
137    {
138      li_crates()++;
139      time=li_income_time();
140    }
141  }
142  li_time() = time;
143
144  if (li_crates()>0 && !crate())
145    create_crate();
146
147  if (li_ticks_till_next_deploy())
148    li_ticks_till_next_deploy()--;
149  else
150  {
151    if (li_moneyplanes()>0 && player_num!=0)
152    {
153      g1_object_class *o=g1_create_object(g1_get_object_type(moneyplane.get()));
154
155      if (o)
156      {
157        li_ticks_till_next_deploy() = li_reset_time_in_ticks();
158        li_moneyplanes()--;
159        o->player_num=player_num;
160        o->x=x; o->y=y; o->h=h;
161        o->theta=theta;
162       
163        o->grab_old();
164        o->occupy_location();
165        o->request_think();
166       
167        g1_player_man.get(o->player_num)->add_object(o->global_id);
168      }
169    }
170  }
171
172  request_think();
173}
174
175
176void g1_bank_class::request_remove()
177{
178  if (crate())
179  {
180    crate()->unoccupy_location();
181    crate()->request_remove();
182  }
183 
184  g1_factory_class::request_remove();
185}
186
187void g1_bank_class::crate_location(i4_3d_vector &pos)
188{
189  pos = crate_pos;
190}
191
192void g1_bank_class::create_crate()
193{
194  if (crate())
195    return;
196
197  li_class_context c(vars);
198
199  set_crate((g1_moneycrate_class *)g1_create_object(g1_get_object_type(crate_obj.get())));
200
201  i4_transform_class t;
202  calc_world_transform(1.0,&t);
203 
204  i4_3d_point_class p;
205
206  t.transform(crate_platform, p);
207 
208  if (crate())
209    crate()->setup(p, li_crate_value());
210}
211
212void g1_bank_class::detach_crate()
213{
214  li_class_context c(vars);
215
216  if (!crate())
217    return;
218
219  set_crate(0);
220
221  li_crates()--;
222  if (li_crates()>0)
223    create_crate();
224}
225
226i4_bool g1_bank_class::build(int type)
227{
228  li_class_context c(vars);
229
230  if (type!=g1_get_object_type(moneyplane.get()))
231    return i4_F;
232     
233  int cost=g1_object_type_array[type]->defaults->cost;     
234  if (cost<=g1_player_man.get(player_num)->money())
235  {
236    g1_player_man.get(player_num)->money()-=cost;
237    li_moneyplanes()++;
238    return i4_T;
239  }
240  return i4_F;
241}
Note: See TracBrowser for help on using the repository browser.