barge.h

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2000  Jeffrey S. Freedman
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifndef INCL_BARGE
00026 #define INCL_BARGE  1
00027 
00028 #include "contain.h"
00029 
00030 /*
00031  *  A 'barge', such as a ship or horse-and-cart.  The elements of a barge
00032  *  are stored in the outside world, so rendering and obstacle detection
00033  *  don't have to be reimplemented.
00034  */
00035 class Barge_object : public Container_game_object, public Time_sensitive
00036   {
00037   Game_object_vector objects; // All objects in/on barge.
00038   int perm_count;     // Counts permanent parts of barge,
00039           //   which proceed those placed on it.
00040   unsigned char xtiles, ytiles; // Tiles covered (when vertical).
00041   unsigned char dir;    // Direction: 0=N, 1=E, 2=S, 3=W.
00042   bool complete;      // Flag:  all members have been read.
00043   bool gathered;      // Items on barge have been gathered.
00044   bool ice_raft;      // For Serpent Isle.
00045   bool first_step;    // So first motion can just be 1 tile.
00046   signed char boat;   // 1 if a boat, 0 if not; -1=untested.
00047   int frame_time;     // Time between frames in msecs.  0 if
00048           //   not moving.
00049   PathFinder *path;   // For traveling.
00050   Tile_coord center;    // Center of barge.
00051   Game_object *get_object(int i)
00052     { return objects[i]; }
00053   void swap_dims();
00054   void set_center();
00055   int okay_to_rotate(Tile_coord pos);
00056   void add_dirty();
00057           // Finish up move/rotate operation.
00058   void finish_move(Tile_coord *positions);
00059 public:
00060   Barge_object(int shapenum, int framenum,
00061     unsigned int shapex, unsigned int shapey, unsigned int lft,
00062       int xt, int yt, int d)
00063     : Container_game_object(shapenum, framenum,
00064               shapex, shapey, lft),
00065       perm_count(0),
00066       xtiles(xt), ytiles(yt), dir(d),
00067       complete(false), gathered(false), ice_raft(false),
00068       first_step(true), boat(-1), frame_time(0), path(0)
00069     {  }
00070   Rectangle get_tile_footprint();
00071   bool is_moving()
00072     { return frame_time > 0; }
00073   int get_xtiles()    // Dims. in tiles.
00074     { return xtiles; }
00075   int get_ytiles()
00076     { return ytiles; }
00077   Tile_coord get_center()
00078     { return center; }
00079   virtual ~Barge_object();
00080   void set_to_gather()    // Require 'gather' on next move.
00081     { gathered = false; }
00082   void gather();      // Gather up objects on barge.
00083   void face_direction(int ndir);  // Face dir. (0-7).
00084           // Start rolling/sailing.
00085   void travel_to_tile(Tile_coord dest, int speed);
00086   void turn_right();    // Turn 90 degrees right.
00087   void turn_left();
00088   void turn_around();
00089   void stop()     // Stop moving.
00090     { frame_time = 0; first_step = true; }
00091   void done();      // No longer being operated.
00092   int okay_to_land();   // See if clear to land.
00093   virtual Barge_object *as_barge() { return this; }
00094           // For Time_sensitive:
00095   virtual void handle_event(unsigned long curtime, long udata);
00096           // Move to new abs. location.
00097   virtual void move(int newtx, int newty, int newlift);
00098           // Remove an object.
00099   virtual void remove(Game_object *obj);
00100           // Add an object.
00101   virtual bool add(Game_object *obj, bool dont_check = false,
00102               bool combine = false);
00103           // Drop another onto this.
00104   virtual int drop(Game_object *obj);
00105           // Render.
00106   virtual void paint();
00107           // Step onto an (adjacent) tile.
00108   virtual int step(Tile_coord t, int frame = -1);
00109           // Write out to IREG file.
00110   virtual void write_ireg(DataSource* out);
00111         // Get size of IREG. Returns -1 if can't write to buffer
00112   virtual int get_ireg_size();
00113   virtual void elements_read(); // Called when all member items read.
00114   };
00115 
00116 #endif

Generated on Mon Jul 9 14:42:49 2007 for ExultEngine by  doxygen 1.5.1