2003-07-28 01:44:38 +00:00
|
|
|
/* Copyright (C) 1994-2003 Revolution Software Ltd
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ROUTER_H
|
|
|
|
#define _ROUTER_H
|
|
|
|
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/memory.h"
|
|
|
|
#include "sword2/object.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-12 14:40:04 +00:00
|
|
|
// This used to be a variable, but it was never set. Actually, it wasn't even
|
|
|
|
// initialised!
|
|
|
|
//
|
|
|
|
// Define this to force the use of slidy router (so solid path not used when
|
|
|
|
// ending walk in ANY direction)
|
|
|
|
//
|
|
|
|
// #define FORCE_SLIDY
|
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-09-13 20:42:08 +00:00
|
|
|
#if !defined(__GNUC__)
|
|
|
|
#pragma START_PACK_STRUCTS
|
|
|
|
#endif
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-03 13:53:46 +00:00
|
|
|
struct _walkData {
|
2003-09-20 15:34:53 +00:00
|
|
|
uint16 frame;
|
|
|
|
int16 x;
|
|
|
|
int16 y;
|
|
|
|
uint8 step;
|
|
|
|
uint8 dir;
|
2003-10-03 13:53:46 +00:00
|
|
|
} GCC_PACK;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-03 13:53:46 +00:00
|
|
|
struct _barData {
|
2003-09-20 15:34:53 +00:00
|
|
|
int16 x1;
|
|
|
|
int16 y1;
|
|
|
|
int16 x2;
|
|
|
|
int16 y2;
|
|
|
|
int16 xmin;
|
|
|
|
int16 ymin;
|
|
|
|
int16 xmax;
|
|
|
|
int16 ymax;
|
|
|
|
int16 dx; // x2 - x1
|
|
|
|
int16 dy; // y2 - y1
|
2003-10-12 14:40:04 +00:00
|
|
|
int32 co; // co = (y1 * dx) - (x1 * dy) from an equation for a
|
|
|
|
// line y * dx = x * dy + co
|
2003-10-03 13:53:46 +00:00
|
|
|
} GCC_PACK;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-03 13:53:46 +00:00
|
|
|
struct _nodeData {
|
2003-09-20 15:34:53 +00:00
|
|
|
int16 x;
|
|
|
|
int16 y;
|
|
|
|
int16 level;
|
|
|
|
int16 prev;
|
|
|
|
int16 dist;
|
2003-10-03 13:53:46 +00:00
|
|
|
} GCC_PACK;
|
2003-09-13 20:42:08 +00:00
|
|
|
|
|
|
|
#if !defined(__GNUC__)
|
|
|
|
#pragma END_PACK_STRUCTS
|
|
|
|
#endif
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-12 14:40:04 +00:00
|
|
|
// because we only have 2 megas in the game!
|
|
|
|
#define TOTAL_ROUTE_SLOTS 2
|
|
|
|
|
|
|
|
#define MAX_FRAMES_PER_CYCLE 16
|
|
|
|
#define NO_DIRECTIONS 8
|
|
|
|
#define MAX_FRAMES_PER_CHAR (MAX_FRAMES_PER_CYCLE * NO_DIRECTIONS)
|
|
|
|
#define ROUTE_END_FLAG 255
|
|
|
|
|
|
|
|
#define MAX_WALKGRIDS 10
|
|
|
|
|
|
|
|
#define O_WALKANIM_SIZE 600 // max number of nodes in router output
|
|
|
|
#define O_GRID_SIZE 200 // max 200 lines & 200 points
|
|
|
|
#define EXTRA_GRID_SIZE 20 // max 20 lines & 20 points
|
|
|
|
#define O_ROUTE_SIZE 50 // max number of modules in a route
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int32 x;
|
|
|
|
int32 y;
|
|
|
|
int32 dirS;
|
|
|
|
int32 dirD;
|
|
|
|
} _routeData;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int32 x;
|
|
|
|
int32 y;
|
|
|
|
int32 dir;
|
|
|
|
int32 num;
|
|
|
|
} _pathData;
|
|
|
|
|
|
|
|
class Router {
|
|
|
|
private:
|
|
|
|
// stores pointers to mem blocks containing routes created & used by
|
|
|
|
// megas (NULL if slot not in use)
|
|
|
|
mem *_routeSlots[TOTAL_ROUTE_SLOTS];
|
|
|
|
|
|
|
|
// because extra bars will be copied into here afer walkgrid loaded
|
|
|
|
_barData _bars[O_GRID_SIZE + EXTRA_GRID_SIZE];
|
|
|
|
_nodeData _node[O_GRID_SIZE + EXTRA_GRID_SIZE];
|
|
|
|
|
|
|
|
int32 _walkGridList[MAX_WALKGRIDS];
|
|
|
|
|
|
|
|
int32 _nbars;
|
|
|
|
int32 _nnodes;
|
|
|
|
|
|
|
|
// area for extra route data to block parts of floors and enable
|
|
|
|
// routing round mega charaters
|
|
|
|
|
|
|
|
int32 _nExtraBars;
|
|
|
|
int32 _nExtraNodes;
|
|
|
|
_barData _extraBars[EXTRA_GRID_SIZE];
|
|
|
|
_nodeData _extraNode[EXTRA_GRID_SIZE];
|
|
|
|
|
|
|
|
int32 _startX;
|
|
|
|
int32 _startY;
|
|
|
|
int32 _startDir;
|
|
|
|
int32 _targetX;
|
|
|
|
int32 _targetY;
|
|
|
|
int32 _targetDir;
|
|
|
|
int32 _scaleA;
|
|
|
|
int32 _scaleB;
|
|
|
|
_routeData _route[O_ROUTE_SIZE];
|
|
|
|
_pathData _smoothPath[O_ROUTE_SIZE];
|
|
|
|
_pathData _modularPath[O_ROUTE_SIZE];
|
|
|
|
int32 _routeLength;
|
|
|
|
|
|
|
|
int32 _framesPerStep;
|
|
|
|
int32 _framesPerChar;
|
|
|
|
|
|
|
|
uint8 _nWalkFrames; // no. of frames per walk cycle
|
|
|
|
uint8 _usingStandingTurnFrames; // any standing turn frames?
|
|
|
|
uint8 _usingWalkingTurnFrames; // any walking turn frames?
|
|
|
|
uint8 _usingSlowInFrames; // any slow-in frames?
|
|
|
|
uint8 _usingSlowOutFrames; // any slow-out frames?
|
|
|
|
int32 _dx[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR];
|
|
|
|
int32 _dy[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR];
|
|
|
|
int8 _modX[NO_DIRECTIONS];
|
|
|
|
int8 _modY[NO_DIRECTIONS];
|
|
|
|
int32 _diagonalx;
|
|
|
|
int32 _diagonaly;
|
|
|
|
|
|
|
|
int32 _firstStandFrame;
|
|
|
|
|
|
|
|
int32 _firstStandingTurnLeftFrame;
|
|
|
|
int32 _firstStandingTurnRightFrame;
|
|
|
|
|
|
|
|
int32 _firstWalkingTurnLeftFrame; // left walking turn
|
|
|
|
int32 _firstWalkingTurnRightFrame; // right walking turn
|
|
|
|
|
|
|
|
uint32 _firstSlowInFrame[NO_DIRECTIONS];
|
|
|
|
uint32 _numberOfSlowInFrames[NO_DIRECTIONS];
|
|
|
|
|
|
|
|
uint32 _leadingLeg[NO_DIRECTIONS];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-12 14:40:04 +00:00
|
|
|
int32 _firstSlowOutFrame;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-12 14:40:04 +00:00
|
|
|
// number of slow-out frames on for each leading-leg in each direction
|
|
|
|
// ie. total number of slow-out frames = (numberOfSlowOutFrames * 2 *
|
|
|
|
// NO_DIRECTIONS)
|
|
|
|
|
|
|
|
int32 _numberOfSlowOutFrames;
|
|
|
|
|
|
|
|
int32 _stepCount;
|
|
|
|
|
|
|
|
int32 _moduleX;
|
|
|
|
int32 _moduleY;
|
|
|
|
int32 _currentDir;
|
|
|
|
int32 _lastCount;
|
|
|
|
int32 _frame;
|
|
|
|
|
|
|
|
uint8 returnSlotNo(uint32 megaId);
|
|
|
|
|
|
|
|
int32 getRoute(void);
|
|
|
|
void extractRoute(void);
|
|
|
|
void loadWalkGrid(void);
|
|
|
|
void setUpWalkGrid(Object_mega *ob_mega, int32 x, int32 y, int32 dir);
|
|
|
|
void loadWalkData(Object_walkdata *ob_walkdata);
|
|
|
|
int32 scan(int32 level);
|
|
|
|
|
|
|
|
int32 newCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2);
|
|
|
|
int32 lineCheck(int32 x1, int32 x2, int32 y1, int32 y2);
|
|
|
|
int32 vertCheck(int32 x, int32 y1, int32 y2);
|
|
|
|
int32 horizCheck(int32 x1, int32 y, int32 x2);
|
|
|
|
int32 check(int32 x1, int32 y1, int32 x2, int32 y2);
|
|
|
|
int32 checkTarget(int32 x, int32 y);
|
|
|
|
|
|
|
|
int32 smoothestPath(void);
|
|
|
|
int32 slidyPath(void);
|
|
|
|
|
|
|
|
int32 smoothCheck(int32 best, int32 p, int32 dirS, int32 dirD);
|
|
|
|
|
|
|
|
int32 addSlowInFrames(_walkData *walkAnim);
|
|
|
|
void addSlowOutFrames(_walkData *walkAnim);
|
|
|
|
void slidyWalkAnimator(_walkData *walkAnim);
|
|
|
|
|
|
|
|
#ifndef FORCE_SLIDY
|
|
|
|
int32 solidPath(void);
|
|
|
|
int32 solidWalkAnimator(_walkData *walkAnim);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void plotCross(int16 x, int16 y, uint8 colour);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Router() :
|
|
|
|
_nExtraBars(0), _nExtraNodes(0), _diagonalx(0),
|
|
|
|
_diagonaly(0) {}
|
|
|
|
|
|
|
|
int32 routeFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, int32 y, int32 dir);
|
|
|
|
|
|
|
|
void earlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata);
|
|
|
|
|
|
|
|
void allocateRouteMem(void);
|
|
|
|
_walkData* lockRouteMem(void);
|
|
|
|
void floatRouteMem(void);
|
|
|
|
void freeRouteMem(void);
|
|
|
|
void freeAllRouteMem(void);
|
|
|
|
void addWalkGrid(int32 gridResource);
|
|
|
|
void removeWalkGrid(int32 gridResource);
|
|
|
|
void clearWalkGridList(void);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-12 14:40:04 +00:00
|
|
|
void plotWalkGrid(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Router router;
|
2003-10-05 15:28:15 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|
|
|
|
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|