Shot Class Reference

#include <Shot.h>

Inheritance diagram for Shot:

Inheritance graph
[legend]
Collaboration diagram for Shot:

Collaboration graph
[legend]

Public Member Functions

 Shot (const Vector2D &c, const Vector2D &velocity, const double energy, const int shot_id=-1)
 ~Shot ()
void move (const double timestep)
void move_no_check (const double timestep)
void die ()
bool is_alive ()
double get_energy ()

Private Attributes

bool alive
double energy

Friends

void shot_collision (Shot *shot1p, Shot *shot2p)
void shot_collision (Shot *shot1p, const Vector2D &shot2_vel, const double shot2_en)

Constructor & Destructor Documentation

Shot::Shot const Vector2D c,
const Vector2D velocity,
const double  energy,
const int  shot_id = -1
 

Definition at line 33 of file Shot.cc.

References alive, energy, OPTION_SHOT_RADIUS, the_arena, and the_opts.

00035   : MovingObject(c, the_opts.get_d(OPTION_SHOT_RADIUS), vel)
00036 {
00037   alive = true;
00038   energy = en;
00039 
00040   if( shot_id == -1 )
00041     id = the_arena.increase_shot_count();
00042   else
00043     id = shot_id;
00044 }

Shot::~Shot  )  [inline]
 

Definition at line 31 of file Shot.h.

00031 {}


Member Function Documentation

void Shot::die  ) 
 

Definition at line 110 of file Shot.cc.

References alive, Gui::get_arenawindow_p(), Gui::get_bg_gdk_colour_p(), ArenaController::is_realtime(), realtime_arena, the_arena_controller, and the_gui.

Referenced by move(), Robot::move(), and shot_collision().

00111 {
00112   if( alive )
00113     {
00114       alive = false;
00115 #ifndef NO_GRAPHICS
00116       if (!no_graphics )
00117         the_gui.get_arenawindow_p()->
00118           draw_circle( last_drawn_center, last_drawn_radius,
00119                        *(the_gui.get_bg_gdk_colour_p()), true );
00120 #endif
00121       
00122       if( the_arena_controller.is_realtime() )
00123         realtime_arena.print_to_logfile('D', (int)'S', id);
00124     }
00125 }

Here is the call graph for this function:

double Shot::get_energy  )  [inline]
 

Definition at line 37 of file Shot.h.

Referenced by Robot::move().

00037 { return energy; }

bool Shot::is_alive  )  [inline]
 

Definition at line 36 of file Shot.h.

Referenced by ArenaBase::move_shots().

00036 { return alive; }

void Shot::move const double  timestep  )  [virtual]
 

Implements MovingObject.

Definition at line 47 of file Shot.cc.

References Robot::change_energy(), COLLISION, COOKIE, Extras::die(), die(), energy, Error(), Circle::get_center(), Robot::get_robot_angle(), MINE, object_type, rotation_t::pos, ROBOT, Robot::send_message(), SHOT, shot_collision, the_arena, vec2angle(), and WALL.

Referenced by ArenaBase::move_shots().

00048 {
00049   object_type closest_shape;
00050   Shape* colliding_object;
00051   double time_to_collision = the_arena.
00052     get_shortest_distance(center, velocity, radius, closest_shape, colliding_object);
00053 
00054   if( time_to_collision > timestep )
00055     {
00056       center += timestep*velocity;
00057     }
00058   else
00059     {
00060       switch( closest_shape )
00061         {
00062         case WALL:
00063           die();
00064           break;
00065         case ROBOT:
00066           {
00067             Robot* robotp = (Robot*)colliding_object;
00068             robotp->change_energy(-energy);
00069             robotp->send_message(COLLISION, SHOT,
00070                                  vec2angle(center-robotp->get_center()) - robotp->get_robot_angle().pos);
00071             die();
00072           }
00073           break;
00074         case SHOT:
00075           {
00076             Shot* shotp = (Shot*)colliding_object;
00077             shot_collision(this, shotp); 
00078           }
00079           break;
00080         case COOKIE:
00081           {
00082             Cookie* cookiep =(Cookie*)colliding_object;
00083             cookiep->die();
00084             the_arena.get_object_lists()[COOKIE].remove( cookiep );
00085             die();
00086           }
00087           break;
00088         case MINE:
00089           {
00090             Mine* minep =(Mine*)colliding_object;
00091             minep->die();
00092             the_arena.get_object_lists()[MINE].remove( minep );
00093             die();
00094           }
00095           break;
00096         default:
00097           Error(true, "Collided with unknown object", "Robot::move");
00098           break;
00099         }
00100     }
00101 }

Here is the call graph for this function:

void Shot::move_no_check const double  timestep  ) 
 

Definition at line 104 of file Shot.cc.

00105 {
00106   center += timestep*velocity;
00107 }


Friends And Related Function Documentation

void shot_collision Shot shot1p,
const Vector2D shot2_vel,
const double  shot2_en
[friend]
 

Definition at line 136 of file Shot.cc.

00137 {
00138   Vector2D vel = ( shot1p->energy * shot1p->velocity + 
00139                    shot2_en * shot2_vel ) / ( shot1p->energy + shot2_en );
00140 
00141   double en = dot( shot1p->energy * unit(shot1p->velocity) + shot2_en * unit(shot2_vel),  
00142                    unit(vel));
00143 
00144   if( en < the_opts.get_d(OPTION_SHOT_MIN_ENERGY) || 
00145       length(vel) < the_opts.get_d(OPTION_SHOT_SPEED) * 0.5 )
00146     {
00147       shot1p->die();
00148     }
00149   else
00150     {
00151       shot1p->velocity = vel;
00152       shot1p->energy = en;
00153       realtime_arena.print_to_logfile('D', (int)'S', shot1p->id);
00154       shot1p->id = the_arena.increase_shot_count();
00155       realtime_arena.print_to_logfile('S', shot1p->id, shot1p->center[0], shot1p->center[1], 
00156                                       shot1p->velocity[0], shot1p->velocity[1]);
00157       
00158 
00159     }
00160 }

void shot_collision Shot shot1p,
Shot shot2p
[friend]
 

Definition at line 128 of file Shot.cc.

Referenced by move().

00129 {
00130   shot_collision(shot1p, shot2p->velocity, shot2p->energy);
00131   shot2p->die();
00132   the_arena.get_object_lists()[SHOT].remove( shot2p );
00133 }


Field Documentation

bool Shot::alive [private]
 

Definition at line 45 of file Shot.h.

Referenced by die(), and Shot().

double Shot::energy [private]
 

Definition at line 46 of file Shot.h.

Referenced by move(), Shot(), and shot_collision().


The documentation for this class was generated from the following files:
Generated on Fri Oct 15 15:51:03 2004 for Real Time Battle by  doxygen 1.3.9.1