source: golgotha/src/golg/cheat.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: 4.4 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 "lisp/lisp.hh"
10#include "lisp/li_init.hh"
11#include "app/app.hh"
12#include "lisp/li_dialog.hh"
13#include "lisp/li_class.hh"
14#include "window/style.hh"
15#include "player.hh"
16#include "gui/button.hh"
17#include "gui/image_win.hh"
18#include "loaders/load.hh"
19#include "window/wmanager.hh"
20#include "objs/stank.hh"
21#include "map_man.hh"
22#include "objs/stank.hh"
23#include "border_frame.hh"
24
25i4_event_handler_reference_class<i4_parent_window_class> g1_cheat_window;
26static int team_editing;
27
28enum { CHEAT_MONEY,
29       CHEAT_STANK_INVINSIBILITY,
30       CHEAT_TROOP_INVINSIBILITY,
31       CHEAT_NUKE };
32
33static char *cheats[]={"bitmaps/cheats/mo_money.jpg",
34                       "bitmaps/cheats/invulnerable.jpg",
35                       "bitmaps/cheats/group_invulnerable.jpg",
36                       "bitmaps/cheats/nuke.jpg", 0};
37
38
39class cheat_handler_class : public i4_event_handler_class
40{
41public:
42  void receive_event(i4_event *ev)
43  {
44    if (!g1_map_is_loaded())
45      return;
46   
47    CAST_PTR(uev, i4_user_message_event_class, ev);
48    switch(uev->sub_type)
49    {
50      case CHEAT_MONEY :
51        g1_player_man.get_local()->money()+=5000;
52        break;
53       
54      case CHEAT_STANK_INVINSIBILITY :
55      {
56        g1_player_piece_class *stank=g1_player_man.get_local()->get_commander();     
57        if (stank)
58          stank->stank_flags ^= g1_player_piece_class::ST_GODMODE;
59      } break;
60     
61      case CHEAT_NUKE :
62      {
63        g1_player_piece_class *stank=g1_player_man.get_local()->get_commander();
64        if (stank)
65        {
66          for (int i=0; i<g1_player_piece_class::MAX_WEAPONS-1; i++)
67          {
68            int mx=stank->ammo[i].ammo_type->max_amount;
69            stank->ammo[i].amount=mx;
70          }
71        }
72       
73      } break;
74     
75    }
76   
77  }
78 
79  char *name() { return "cheat_handler"; }
80} cheat_handler;
81
82li_object *g1_cheat_menu(li_object *o, li_environment *env)
83
84  if (g1_cheat_window.get())
85    i4_kernel.delete_handler(g1_cheat_window.get());
86  else
87  {
88    i4_graphical_style_class *s=i4_current_app->get_style();
89    i4_color_window_class *cw=new i4_color_window_class(0,0,0,s);
90
91    int id=0;
92    for (char **a=cheats; *a; a++, id++)
93    {
94      i4_image_class *im=i4_load_image(*a);
95      if (im)
96      {
97        i4_button_class *b=new i4_button_class(0, new i4_image_window_class(im, i4_T), s,
98                                               new i4_event_reaction_class(&cheat_handler, id));
99        b->set_popup(i4_T);
100        cw->add_child(0,0, b);
101      }
102    }
103    cw->arrange_right_down();
104    cw->resize_to_fit_children();
105    i4_window_manager_class *wm=i4_current_app->get_window_manager();
106    wm->add_child(wm->width()-cw->width()-1,
107                  wm->height()-cw->height()-1, cw);
108    g1_cheat_window=cw;
109  }
110
111  return 0;
112}
113
114
115li_automatic_add_function(g1_cheat_menu, "Cheat Menu");
116
117
118
119li_object *g1_upgrade_level_0(li_object *o, li_environment *env)
120{
121  g1_player_piece_class *p=g1_player_man.get_local()->get_commander();
122  if (p && g1_border.get())
123  {
124    g1_player_man.get_local()->supertank_upgrade_level=0;
125    p->find_weapons();
126  }
127
128  return 0;
129}
130
131
132
133li_object *g1_upgrade_level_1(li_object *o, li_environment *env)
134{
135  g1_player_piece_class *p=g1_player_man.get_local()->get_commander();
136  if (p && g1_border.get())
137  {
138    g1_player_man.get_local()->supertank_upgrade_level=1;
139    p->find_weapons();
140  }
141
142  return 0;
143}
144
145
146
147li_object *g1_upgrade_level_2(li_object *o, li_environment *env)
148{
149  g1_player_piece_class *p=g1_player_man.get_local()->get_commander();
150  if (p && g1_border.get())
151  {   
152    g1_player_man.get_local()->supertank_upgrade_level=2;     
153    p->find_weapons();
154  }
155
156  return 0;
157}
158
159
160li_automatic_add_function(g1_upgrade_level_0, "upgrade_level_0");
161li_automatic_add_function(g1_upgrade_level_1, "upgrade_level_1");
162li_automatic_add_function(g1_upgrade_level_2, "upgrade_level_2");
163
Note: See TracBrowser for help on using the repository browser.