source: golgotha/src/golg/objs/defaults.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: 6.2 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 "string/string.hh"
10#include "memory/array.hh"
11#include "objs/defaults.hh"
12#include "lisp/lisp.hh"
13#include "loaders/load.hh"
14#include "image/image.hh"
15#include "g1_object.hh"
16
17static li_symbol_ref li_sing("sing"), li_mult("mult");
18
19i4_array<g1_object_defaults_struct> g1_obj_defaults(0,32);
20i4_array<g1_stank_ammo_type_struct> g1_stank_ammo_types(0,32);
21i4_array<g1_damage_map_struct>      g1_damage_maps(0,32);
22
23li_object *g1_defaults(li_object *i, li_environment *env)
24{
25  while (i)
26  {
27    g1_object_defaults_struct *d=g1_obj_defaults.add();
28    li_object *o=li_car(i,env);
29
30    strcpy(d->object_name, li_get_string(li_symbol::get(li_car(o,env),env)->name(),env)); 
31    o=li_cdr(o,env);
32           
33    d->speed=li_get_float(li_car(o,env),env);                 o=li_cdr(o,env);
34    d->turn_speed=li_get_float(li_car(o,env),env);            o=li_cdr(o,env);
35    d->accel=li_get_float(li_car(o,env),env);                 o=li_cdr(o,env);
36    d->cost=li_get_int(li_car(o,env),env);                    o=li_cdr(o,env);
37
38    d->health=li_get_int(li_car(o,env),env);                  o=li_cdr(o,env);
39    d->fire_delay=li_get_int(li_car(o,env),env);              o=li_cdr(o,env);
40    d->detection_range=li_get_float(li_car(o,env),env);       o=li_cdr(o,env);
41
42    d->fire_type=li_symbol::get(li_car(o,env),env);           o=li_cdr(o,env);
43   
44    i=li_cdr(i,env);
45  }
46  return 0;
47}
48
49li_object *g1_add_stank_weapons(li_object *i, li_environment *env)
50{
51  while (i)
52  {
53    li_object *o=li_car(i,env);
54    g1_stank_ammo_type_struct *a=g1_stank_ammo_types.add();
55    a->weapon_type=li_symbol::get(li_car(o,env),env);              o=li_cdr(o,env);
56    a->max_amount=li_get_int(li_eval(li_car(o,env),env),env);     o=li_cdr(o,env);
57    a->refuel_delay=li_get_int(li_eval(li_car(o,env),env),env);   o=li_cdr(o,env);
58    a->fire_delay=li_get_int(li_eval(li_car(o,env),env),env);     o=li_cdr(o,env);
59
60    char name[100];
61    sprintf(name,"bitmaps/stank/frame_%s.tga", li_get_string(li_car(o,env),env));
62    a->icon=i4_load_image(name);
63   
64    sprintf(name,"bitmaps/stank/dark_%s.tga", li_get_string(li_car(o,env), env));
65    a->dark_icon=i4_load_image(name);
66   
67   
68    i=li_cdr(i,env);
69  }
70  return 0;
71}
72
73li_object *g1_def_weapon_damage(li_object *i, li_environment *env)
74{
75  while (i)
76  {
77    li_object *o=li_car(i,env), *c;
78    g1_damage_map_struct *a=g1_damage_maps.add();
79
80    a->object_for=li_symbol::get(li_car(o,env),env);      o=li_cdr(o,env);
81
82    li_symbol *htype=li_symbol::get(li_car(o,env),env);
83    if (htype==li_sing.get())
84      a->hurt_type=g1_damage_map_struct::HURT_SINGLE_GUY;
85    else if (htype==li_mult.get())
86      a->hurt_type=g1_damage_map_struct::DO_AREA_OF_EFFECT;
87    else li_error(env, "unknown hurt type %O", o);
88    o=li_cdr(o,env);
89   
90    a->default_damage=li_get_int(li_car(o,env),env);      o=li_cdr(o,env);
91    a->special_damage=li_get_int(li_car(o,env),env);      o=li_cdr(o,env);
92    a->speed=li_get_float(li_car(o,env),env);             o=li_cdr(o,env);
93    a->range=li_get_float(li_car(o,env),env);             o=li_cdr(o,env);
94       
95    // count how many exceptions follow
96    for (a->t_maps=0, c=o; c; c=li_cdr(c,env), a->t_maps++);
97
98    if (a->t_maps)
99    {
100      a->maps=(g1_damage_map_struct::map *)i4_malloc(a->t_maps *
101                                                     sizeof(g1_damage_map_struct::map),"");
102      int i=0;
103      for (;o; o=li_cdr(o,env))
104      {
105        a->maps[i].object_type=li_symbol::get(li_car(li_car(o,env),env),env);
106        a->maps[i].damage=li_get_int(li_car(li_cdr(li_car(o,env),env),env),env);
107        i++;
108      }
109    }
110    else a->maps=0;
111    i=li_cdr(i,env);
112  }
113
114  return 0;
115}
116
117
118g1_damage_map_struct *g1_find_damage_map(int object_type)
119{
120  int t=g1_damage_maps.size();
121  for (int i=0; i<t; i++)
122    if (g1_get_object_type(g1_damage_maps[i].object_for)==object_type)
123      return &g1_damage_maps[i];
124 
125  return 0;
126}
127
128int g1_damage_map_struct::get_damage_for(int object_type)
129{
130  for (int i=0; i<t_maps; i++)
131    if (g1_get_object_type(maps[i].object_type)==object_type)
132      return maps[i].damage;
133
134  return default_damage;
135}
136
137g1_stank_ammo_type_struct *g1_find_stank_ammo_type(li_symbol *sym)
138{
139  for (int i=0; i<g1_stank_ammo_types.size(); i++)
140    if (g1_stank_ammo_types[i].weapon_type==sym)
141      return &g1_stank_ammo_types[i];
142 
143  return 0;
144}
145
146void g1_load_object_defaults()
147{
148  li_add_function("defaults", g1_defaults, 0);
149  li_add_function("def_stank_weapons", g1_add_stank_weapons, 0);
150  li_add_function("def_weapon_damage", g1_def_weapon_damage, 0);
151 
152  li_load("scheme/balance.scm",0); 
153}
154
155g1_object_defaults_struct *g1_get_object_defaults(const char *object_name,
156                                                  i4_bool barf_on_error)
157{
158  if (!g1_obj_defaults.size())
159    g1_load_object_defaults();
160
161  for (int i=0; i<g1_obj_defaults.size(); i++)
162    if (strcmp(g1_obj_defaults[i].object_name, object_name)==0)
163      return &g1_obj_defaults[i];
164
165  if (barf_on_error)
166    i4_error("unable to find object default for %s",object_name);
167  else
168    return g1_get_object_defaults("default", i4_T);
169                                 
170  return 0;
171}
172
173void g1_unload_object_defaults()     // call at end of game to clean up memory
174{
175  g1_obj_defaults.uninit();
176
177  int i;
178 
179  for (i=0; i<g1_stank_ammo_types.size(); i++)
180  {
181    if (g1_stank_ammo_types[i].icon) delete g1_stank_ammo_types[i].icon;
182    if (g1_stank_ammo_types[i].dark_icon) delete g1_stank_ammo_types[i].dark_icon;
183  }
184  g1_stank_ammo_types.uninit();
185 
186  for (i=0; i<g1_damage_maps.size(); i++)
187  {
188    if (g1_damage_maps[i].maps)
189      i4_free(g1_damage_maps[i].maps);
190  }
191  g1_damage_maps.uninit();
192
193}
Note: See TracBrowser for help on using the repository browser.