source: golgotha/src/golg/objs/bases.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 "lisp/li_class.hh"
10#include "g1_object.hh"
11#include "li_objref.hh"
12#include "math/random.hh"
13#include "math/pi.hh"
14#include "object_definer.hh"
15#include "player.hh"
16#include "controller.hh"
17#include "objs/path_object.hh"
18#include "objs/bases.hh"
19#include "sound/sfx_id.hh"
20#include "player.hh"
21#include "image_man.hh"
22#include "map.hh"
23#include "map_man.hh"
24
25i4_isl_list<g1_factory_class> g1_factory_list;
26
27
28static li_symbol_ref build("build");
29
30
31S1_SFX(sfx_built, "assembled/vehicle_ready_22khz.wav", S1_STREAMED, 100);
32
33static li_int_class_member ticks_till_next_deploy("ticks_till_next_deploy"),
34  reset_time_in_ticks("reset_time_in_ticks"),
35  path_color("path_color"),
36  selected_path_color("selected_path_color");
37
38static li_g1_ref_class_member start("start");
39static li_object_class_member can_build("can_build");
40static g1_team_icon_ref airbase_radar_im("bitmaps/radar/airbase.tga");
41static g1_team_icon_ref garage_radar_im("bitmaps/radar/garage.tga");
42static g1_team_icon_ref mainbasepad_radar_im("bitmaps/radar/base_golg.tga");
43
44void g1_factory_class::set_start(g1_path_object_class *_start)
45{
46  li_class_context context(vars);
47  start();
48  vars->set_value(start.offset, new li_g1_ref(_start));
49}
50
51g1_path_object_class *g1_factory_class::get_start()
52{
53  g1_object_class *o=li_g1_ref::get(vars->get(start),0)->value();
54  if (!o) return 0;
55  return g1_path_object_class::cast(o);
56}
57
58
59w32 g1_factory_class::get_path_color()
60{
61  return vars->get(path_color);
62}
63
64
65w32 g1_factory_class::get_selected_path_color()
66{
67  return vars->get(selected_path_color);
68}
69
70
71g1_factory_class::g1_factory_class(g1_object_type id, g1_loader_class *fp)
72  : g1_object_class(id,fp), death(this)
73{
74  const char *n=name();
75  char lod_n[256];
76  sprintf(lod_n, "%s_lod", n);
77  draw_params.setup(n,0,lod_n);
78
79  if (!strcmp(n, "garage"))
80    radar_image=&garage_radar_im;
81  else if (!strcmp(n, "airbase"))
82    radar_image=&airbase_radar_im;
83  else if (!strcmp(n, "mainbasepad"))
84    radar_image=&mainbasepad_radar_im;
85
86  radar_type=G1_RADAR_BUILDING;
87  set_flag(BLOCKING      |
88           CAN_DRIVE_ON  |
89           GROUND
90           ,1);
91}
92
93i4_bool g1_factory_class::occupy_location()
94{
95  if (g1_object_class::occupy_location())
96  {
97    g1_factory_list.insert(*this);
98    return i4_T;
99  }
100  else
101    return i4_F;
102}
103 
104void g1_factory_class::unoccupy_location()
105{
106  g1_object_class::unoccupy_location();
107  g1_factory_list.find_and_unlink(this);
108}
109
110g1_map_piece_class *g1_factory_class::create_object(int type)
111{
112  if (start()->value())
113  {                         
114    g1_object_class *o=g1_object_type_array[type]->create_object(type,0);
115    if (o)
116    {
117      g1_map_piece_class *mp=g1_map_piece_class::cast(o);
118      if (!mp)
119        mp->request_remove();
120      else
121      {
122        mp->player_num=player_num;
123        mp->x=x; mp->y=y; mp->h=h;
124        mp->theta=theta;
125        mp->add_team_flag();
126
127        mp->grab_old();
128        mp->occupy_location();
129     
130        g1_player_man.get(mp->player_num)->add_object(mp->global_id);
131        return mp;
132      }     
133    }
134  }
135  return 0;
136}
137
138i4_bool g1_factory_class::build(int type)
139{
140  li_class_context context(vars);
141   
142  g1_path_object_class *startp=get_start();
143  if (startp)
144  {
145    // is this a object type we can build?
146    int found=0;
147    for (li_object *blist=can_build(); !found && blist; blist=li_cdr(blist,0))
148      if (li_int::get(li_get_value(li_symbol::get(li_car(blist,0),0)),0)->value()==type)
149        found=1;
150   
151    if (!found)
152      return 0;
153       
154    int cost=g1_object_type_array[type]->defaults->cost;
155   
156    if (cost<=g1_player_man.get(player_num)->money() && !deploy_que.full())
157    {
158      if (player_num==g1_player_man.local_player)
159        sfx_built.play();
160
161      g1_player_man.get(player_num)->money()-=cost;
162      g1_build_item item;
163      item.type=type;
164     
165      g1_path_object_class *list[400];
166     
167      if (startp)
168      {
169        int t=startp->find_path(g1_player_man.get(player_num)->get_team(), list, 400);
170        item.path=(g1_id_ref *)i4_malloc(sizeof(g1_id_ref) *(t+1), "");
171        for (int i=0; i<t; i++)
172          item.path[i]=list[i];
173        item.path[t].id=0;
174      }
175      else
176        item.path=0;
177     
178      deploy_que.que(item); 
179     
180      request_think();
181      return i4_T;
182    }
183  }
184  return i4_F;
185}
186 
187void g1_factory_class::think()
188
189  if (!death.think())
190    return;
191
192  if (ticks_till_next_deploy())
193  {
194    ticks_till_next_deploy()--;
195    request_think();
196  }
197  else if (!deploy_que.empty())
198  {
199    ticks_till_next_deploy()=reset_time_in_ticks();
200
201    g1_build_item item;
202    deploy_que.deque(item);
203
204    g1_map_piece_class *o=create_object(item.type);
205    if (o)
206    {
207      o->set_path(item.path);
208      char msg[100];
209      sprintf(msg, "Vehicle advancing : %s", o->name());
210      g1_player_man.show_message(msg, 0x00ff00, player_num);
211    }
212    else
213      i4_free(item.path);
214
215    request_think();
216  }
217}
218 
219void g1_factory_class::damage(g1_object_class *obj, int hp, i4_3d_vector damage_dir)
220{
221  death.damage(obj, hp, damage_dir);
222}
223 
224static g1_object_definer<g1_factory_class>
225garage_def("garage", g1_object_definition_class::EDITOR_SELECTABLE);
226
227static g1_object_definer<g1_factory_class>
228airbase_def("airbase", g1_object_definition_class::EDITOR_SELECTABLE);
Note: See TracBrowser for help on using the repository browser.