source: golgotha/src/golg/objs/bird.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.5 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 "objs/def_object.hh"
10#include "lisp/li_init.hh"
11#include "lisp/li_class.hh"
12#include "li_objref.hh"
13#include "map_man.hh"
14#include "map.hh"
15#include "math/pi.hh"
16#include "objs/model_draw.hh"
17#include "math/angle.hh"
18
19static li_symbol_class_member flapping("flapping");
20
21static li_int_class_member ticks_to_think("ticks_to_think");
22
23static li_float_class_member xy_v("xy_v"), zv("zv"),
24  turn_speed("turn_speed"),
25  flap_theta("flap_theta");
26
27// current destination of the bird is set by def_object automatically if the
28// object has these variables when deploy_to is called
29static li_float_class_member dest_x("dest_x"), dest_y("dest_y");     
30
31
32static li_symbol *sym_yes=0, *sym_no=0;    // cache the pointer to the "yes" symbol
33
34
35li_object *g1_draw_and_think(li_object *o, li_environment *env)
36{
37  g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
38
39
40  g1_model_draw_parameters mp;
41  mp.model=me->get_type()->model;
42  g1_model_draw(me, mp, g1_draw_context);
43
44  if (me->get_flag(g1_object_class::MAP_OCCUPIED))
45  {
46    ticks_to_think()=20;
47    me->request_think();
48  }
49
50  return 0;
51}
52
53
54li_object *g1_bird_message(li_object *o, li_environment *env)
55{
56  g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
57  return 0;
58}
59
60li_object *g1_bird_think(li_object *o, li_environment *env)
61{
62  g1_dynamic_object_class *me=g1_dynamic_object_class::get(li_car(o));
63 
64  me->grab_old();
65  me->unoccupy_location();
66 
67
68
69  me->x += cos(me->theta) * xy_v();
70  me->y += sin(me->theta) * xy_v();
71
72  if (dest_x()>=0.0)
73  {
74    float desired_theta=atan2(me->y-dest_y(), me->x-dest_x());
75    me->theta = i4_interpolate_angle(me->theta, desired_theta, 0.1);
76  }
77  else
78    me->theta+=turn_speed();
79
80  xy_v() *= 0.99;     // air friction
81 
82  if (flapping()==li_get_symbol("yes", sym_yes))
83  {
84    zv() += 0.001;
85    if (zv()>0.03)
86      zv()=0.03;
87    xy_v() += 0.001;
88  }
89  else
90  {
91    zv() += -0.001;
92    if (zv()<-0.05)
93      zv()=-0.05;
94
95    xy_v() += 0.001;
96    if (xy_v()>0.2)
97      xy_v()=0.2;
98  }
99
100  float z_vel=zv();
101  me->pitch = z_vel * (i4_pi()/8) / 0.2;
102  me->h += zv();
103
104  float agh=me->height_above_ground();
105
106  if (agh<1.5)
107    flapping()=li_get_symbol("yes", sym_yes);
108  else if (agh>2.0)
109    flapping() = li_get_symbol("no", sym_no);
110
111
112  if (flapping()==li_get_symbol("yes", sym_yes))
113  {
114    flap_theta()+=1.0;
115   
116    me->mini_objects[0].rotation.x=cos(flap_theta()) * i4_pi()/8 + i4_pi()/16;
117    me->mini_objects[1].rotation.x=cos(flap_theta()) * -i4_pi()/8 + i4_pi()/16;
118  }
119  else
120  {
121    me->mini_objects[0].rotation.x *= 0.5;
122    me->mini_objects[1].rotation.x *= 0.5;
123  }
124   
125
126  if (me->occupy_location())
127  {
128    if (ticks_to_think())
129    {
130      ticks_to_think()--;
131      me->request_think();
132    }
133  }
134
135  return 0;
136}
137
138li_automatic_add_function(g1_bird_message, "bird_message");
139li_automatic_add_function(g1_bird_think, "bird_think");
140li_automatic_add_function(g1_draw_and_think, "draw_and_think");
Note: See TracBrowser for help on using the repository browser.