source: golgotha/src/golg/objs/bridger.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: 3.7 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 "object_definer.hh"
10#include "objs/map_piece.hh"
11#include "lisp/li_class.hh"
12#include "map_man.hh"
13#include "map.hh"
14#include "li_objref.hh"
15#include "camera.hh"
16#include "objs/path_object.hh"
17#include "saver.hh"
18#include "map_cell.hh"
19
20static li_symbol_class_member bridgeable_spot("bridgeable_spot");
21static li_symbol_ref bridger("bridger"), yes("yes"), already_attached("already_attached");
22static li_g1_ref_class_member marker_attached_to("marker_attached_to");
23
24class g1_bridger_object_class : public g1_map_piece_class
25{
26public:
27
28  g1_typed_reference_class<g1_object_class> last_on;
29 
30  g1_bridger_object_class(g1_object_type id, g1_loader_class *fp)
31    : g1_map_piece_class(id,fp)
32  {
33    allocate_mini_objects(1, "");
34    mini_objects[0].defmodeltype = g1_model_list_man.find_handle("bridger_wheels");
35    draw_params.setup("bridger_road", 0, "bridger_road");
36
37    radar_type=G1_RADAR_VEHICLE;
38    set_flag(BLOCKING      |
39             TARGETABLE    |
40             GROUND        |
41             SHADOWED      |
42             DANGEROUS, 1);
43  }
44
45
46  i4_bool occupy_location()
47  {
48    li_class_context context(vars);
49    if (!marker_attached_to()->value())
50      return g1_map_piece_class::occupy_location();
51    else
52      return occupy_location_center();
53  }
54
55 
56  void think()
57  {
58    if (!marker_attached_to()->value())
59    {
60      g1_map_piece_class::think();
61      stagger=0;                      // I want bridges to be in a straight line
62     
63      if (!alive())
64        return;
65   
66
67      g1_object_class *mark=0;
68      int bridgers_found=0;
69
70     
71      g1_object_chain_class *chain=g1_get_map()->cell((int)x, (int)y)->get_obj_list();
72      for (g1_object_chain_class *c=chain; c; c=c->next)
73        if (g1_path_object_class::cast(c->object))
74          mark=c->object;
75
76
77      if (mark && mark->vars->get(bridgeable_spot)==yes.get())
78      {
79        g1_camera_event cev;
80        cev.type=G1_WATCH_IDLE;
81        cev.follow_object=this;
82        g1_current_view_state()->suggest_camera_event(cev);
83       
84        unoccupy_location();
85
86        unlink();
87        set_flag(CAN_DRIVE_ON, 1);
88        set_flag(DANGEROUS,0);
89
90        x=mark->x;
91        y=mark->y;
92        h=mark->h;
93       
94        mark->vars->get(bridgeable_spot)=already_attached.get();
95        vars->get(marker_attached_to)=new li_g1_ref(mark->global_id);
96        set_flag(CAN_DRIVE_ON, 1);
97       
98        occupy_location();
99             
100        pitch = roll = 0;
101        groundpitch = 0;
102        groundroll = 0;
103        grab_old();       
104
105      }     
106    }
107    else if (!check_life())
108    {
109      unoccupy_location();
110      request_remove();     
111    }
112  }
113
114  void request_remove()
115  {
116    g1_object_class *marker=li_g1_ref::get(vars->get(marker_attached_to),0)->value();
117    if (marker)
118      marker->vars->get(bridgeable_spot)=yes.get();
119   
120    g1_map_piece_class::request_remove();
121  }
122 
123};
124
125
126g1_object_definer<g1_bridger_object_class>
127g1_bridger_def("bridger",
128               g1_object_definition_class::EDITOR_SELECTABLE |
129               g1_object_definition_class::TO_MAP_PIECE |
130               g1_object_definition_class::MOVABLE);
131
132
133
Note: See TracBrowser for help on using the repository browser.