source: golgotha/src/golg/objs/stank_factory.cc

Last change on this file 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.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 "g1_object.hh"
10#include "lisp/li_class.hh"
11#include "g1_object.hh"
12#include "li_objref.hh"
13#include "math/random.hh"
14#include "object_definer.hh"
15#include "player.hh"
16#include "controller.hh"
17#include "objs/stank.hh"
18#include "objs/path_object.hh"
19#include "objs/bases.hh"
20#include "app/app.hh"
21#include "device/event.hh"
22#include "mess_id.hh"
23#include "device/kernel.hh"
24#include "math/pi.hh"
25#include "border_frame.hh"
26
27static li_symbol_ref stank("stank");
28
29class g1_stank_factory_class : public g1_factory_class
30{
31public:
32  g1_stank_factory_class(g1_object_type id, g1_loader_class *fp)
33    : g1_factory_class(id,fp)
34  {
35    flags|=THINKING;
36  }
37 
38  i4_bool occupy_location()
39  {
40    if (occupy_location_center())
41    {
42      g1_factory_list.insert(*this);
43      return i4_T;
44    }
45    else return i4_F;
46  }
47
48
49  void continue_game()
50  {
51   
52  }
53
54  void think()
55  {
56    request_think();
57
58    if (!g1_player_man.get(player_num)->get_commander() &&
59        !g1_player_man.get(player_num)->continue_wait)
60    {
61      if (g1_player_man.get(player_num)->num_stank_lives())
62      {
63        g1_object_class *o=g1_create_object(g1_get_object_type(stank.get()));
64        g1_player_piece_class *stank=g1_player_piece_class::cast(o);
65        if (stank)
66        {
67          g1_player_man.get(player_num)->num_stank_lives()--;
68          g1_player_man.get(player_num)->calc_upgrade_level();
69
70          stank->player_num=player_num;
71          stank->x=x; stank->y=y; stank->h=h;
72          stank->theta=theta-i4_pi()/2.0;
73          stank->turret->rotation.z = stank->base_angle = stank->theta;
74
75          stank->grab_old();
76          stank->occupy_location();
77
78          g1_player_man.get(player_num)->add_object(stank->global_id);
79
80          g1_player_man.get(player_num)->set_commander(stank);
81
82
83
84          if (player_num==g1_player_man.get_local()->get_player_num() &&
85              g1_current_controller.get())
86          {
87            if (g1_border.get())
88            {
89              if (g1_border->strategy_on_top)
90                li_call("strategy_toggle");
91              else
92                g1_current_controller->view.suggest_camera_mode(G1_ACTION_MODE);
93            }
94          }
95
96
97          stank->request_think();   
98        }
99        else delete o;
100      }
101      else
102      {
103        if (g1_player_man.local_player==player_num)
104        {
105          i4_user_message_event_class loser(G1_YOU_LOSE);
106          i4_kernel.send_event(i4_current_app, &loser);
107        }
108      }
109    }
110  }
111
112  virtual i4_bool build(int type)
113  {
114    if (type!=g1_supertank_type || g1_player_man.get(player_num)->num_stank_lives()>=5)
115      return i4_F;
116
117    if (g1_player_man.get(player_num)->money()>=g1_object_type_array[type]->defaults->cost)
118    {
119      g1_player_man.get(player_num)->money()-=g1_object_type_array[type]->defaults->cost;
120      g1_player_man.get(player_num)->num_stank_lives()++;
121      return i4_T;
122    }
123    else return i4_F;
124
125
126
127  }
128 
129};
130
131static g1_object_definer<g1_stank_factory_class>
132mainbase_def("mainbasepad", g1_object_definition_class::EDITOR_SELECTABLE);
133
Note: See TracBrowser for help on using the repository browser.