Zombie.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 
00024 #include "Zombie.h"
00025 
00026 /*
00027  *  Find path from source to destination.
00028  *
00029  *  Output: 1 if successful, else 0.
00030  */
00031 int Zombie::NewPath(Tile_coord s, Tile_coord d, Pathfinder_client *)
00032 {
00033   src = s;      // Store start, destination.
00034   dest = d;
00035   cur = s;      // Get current coords.
00036   sum = 0;      // Clear accumulator.
00037   long deltax = Tile_coord::delta(cur.tx, dest.tx);
00038   long deltay = Tile_coord::delta(cur.ty, dest.ty);
00039   if (!deltax && !deltay)   // Going nowhere?
00040     {
00041     major_distance = 0;
00042     return (0);
00043     }   
00044   unsigned int abs_deltax, abs_deltay;
00045   int x_dir, y_dir;
00046   if (deltay >= 0)    // Figure directions.
00047     {
00048     y_dir = 1;
00049     abs_deltay = deltay;
00050     }
00051   else
00052     {
00053     y_dir = -1;
00054     abs_deltay = -deltay;
00055     }
00056   if (deltax >= 0)
00057     {
00058     x_dir = 1;
00059     abs_deltax = deltax;
00060     }
00061   else
00062     {
00063     x_dir = -1;
00064     abs_deltax = -deltax;
00065     }
00066   if (abs_deltay >= abs_deltax) // Moving faster along y?
00067     {
00068     major_coord = &cur.ty;
00069     minor_coord = &cur.tx;
00070     major_dir = y_dir;
00071     minor_dir = x_dir;
00072     major_delta = abs_deltay;
00073     minor_delta = abs_deltax;
00074     }
00075   else        // Moving faster along x?
00076     {
00077     major_coord = &cur.tx;
00078     minor_coord = &cur.ty;
00079     major_dir = x_dir;
00080     minor_dir = y_dir;
00081     major_delta = abs_deltax;
00082     minor_delta = abs_deltay;
00083     }
00084   major_distance = major_delta; // How far to go.
00085   return (1);
00086 }
00087 
00088 /*
00089  *  Get next point on path to go to (in tile coords).
00090  *
00091  *  Output: 0 if all done.
00092  */
00093 int Zombie::GetNextStep(Tile_coord& n, bool& done)
00094 {
00095   if (major_distance <= 0)
00096     {
00097     done = true;
00098     return (0);
00099     }
00100           // Subtract from distance to go.
00101   major_distance -= major_frame_incr;
00102           // Accumulate change.
00103   sum += major_frame_incr * minor_delta;
00104           // Figure change in slower axis.
00105   int minor_frame_incr = sum/major_delta;
00106   sum = sum % major_delta;  // Remove what we used.
00107           // Update coords. within world.
00108   *major_coord += major_dir*major_frame_incr;
00109   *minor_coord += minor_dir*minor_frame_incr;
00110           // Watch for wrapping.
00111   *major_coord = (*major_coord + c_num_tiles)%c_num_tiles;
00112   *minor_coord = (*minor_coord + c_num_tiles)%c_num_tiles;
00113   n = cur;      // Return new tile.
00114           // ++++++For now, ignore tz.
00115   done = (major_distance <= 0); // Indicate if this is the last one.
00116   return (1);
00117 }
00118 
00119 /*
00120  *  Delete.
00121  */
00122 Zombie::~Zombie
00123   (
00124   )
00125   {
00126   }

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