CleanUp
This commit is contained in:
parent
f10d5c5c8e
commit
43a340ee34
8 changed files with 368 additions and 362 deletions
|
@ -5,12 +5,12 @@
|
||||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||||
// \/ \/ \//_____/ \/
|
// \/ \/ \//_____/ \/
|
||||||
// ______________________ ______________________
|
// ______________________ ______________________
|
||||||
// T H E W A R B E G I N S
|
// T H E W A R B E G I N S
|
||||||
// Stratagus - A free fantasy real time strategy game engine
|
// Stratagus - A free fantasy real time strategy game engine
|
||||||
//
|
//
|
||||||
/**@name astar.c - The a* path finder routines. */
|
/**@name astar.c - The a* path finder routines. */
|
||||||
//
|
//
|
||||||
// (c) Copyright 1999-2003 by Lutz Sammer,Fabrice Rossi, Russell Smith
|
// (c) Copyright 1999-2003 by Lutz Sammer,Fabrice Rossi, Russell Smith
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,12 +26,12 @@
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
//@{
|
//@{
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Includes
|
-- Includes
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -45,20 +45,20 @@
|
||||||
#include "pathfinder.h"
|
#include "pathfinder.h"
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Declarations
|
-- Declarations
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
typedef struct _node_ {
|
typedef struct _node_ {
|
||||||
char Direction; /// Direction for trace back
|
char Direction; ///< Direction for trace back
|
||||||
char InGoal; /// is this point in the goal
|
char InGoal; ///< is this point in the goal
|
||||||
int CostFromStart; /// Real costs to reach this point
|
int CostFromStart; ///< Real costs to reach this point
|
||||||
} Node;
|
} Node;
|
||||||
|
|
||||||
typedef struct _open_ {
|
typedef struct _open_ {
|
||||||
int X; /// X coordinate
|
int X; ///< X coordinate
|
||||||
int Y; /// Y coordinate
|
int Y; ///< Y coordinate
|
||||||
int O; /// Offset into matrix
|
int O; ///< Offset into matrix
|
||||||
int Costs; /// complete costs to goal
|
int Costs; ///< complete costs to goal
|
||||||
} Open;
|
} Open;
|
||||||
|
|
||||||
/// heuristic cost fonction for a star
|
/// heuristic cost fonction for a star
|
||||||
|
@ -68,11 +68,11 @@ typedef struct _open_ {
|
||||||
// #define AStarCosts(sx,sy,ex,ey) isqrt((abs(sx-ex)*abs(sx-ex))+(abs(sy-ey)*abs(sy-ey)))
|
// #define AStarCosts(sx,sy,ex,ey) isqrt((abs(sx-ex)*abs(sx-ex))+(abs(sy-ey)*abs(sy-ey)))
|
||||||
// #define AStarCosts(sx,sy,ex,ey) max(abs(sx-ex),abs(sy-ey))
|
// #define AStarCosts(sx,sy,ex,ey) max(abs(sx-ex),abs(sy-ey))
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Variables
|
-- Variables
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// Convert heading into direction.
|
// Convert heading into direction.
|
||||||
// // N NE E SE S SW W NW
|
// // N NE E SE S SW W NW
|
||||||
const int Heading2X[9] = { 0,+1,+1,+1, 0,-1,-1,-1, 0 };
|
const int Heading2X[9] = { 0,+1,+1,+1, 0,-1,-1,-1, 0 };
|
||||||
const int Heading2Y[9] = { -1,-1, 0,+1,+1,+1, 0,-1, 0 };
|
const int Heading2Y[9] = { -1,-1, 0,+1,+1,+1, 0,-1, 0 };
|
||||||
const int XY2Heading[3][3] = { {7,6,5},{0,0,4},{1,2,3}};
|
const int XY2Heading[3][3] = { {7,6,5},{0,0,4},{1,2,3}};
|
||||||
|
@ -84,7 +84,7 @@ static int Threshold;
|
||||||
static int OpenSetMaxSize;
|
static int OpenSetMaxSize;
|
||||||
static int AStarMatrixSize;
|
static int AStarMatrixSize;
|
||||||
#define MAX_CLOSE_SET_RATIO 4
|
#define MAX_CLOSE_SET_RATIO 4
|
||||||
#define MAX_OPEN_SET_RATIO 8 // 10,16 to small
|
#define MAX_OPEN_SET_RATIO 8 // 10,16 to small
|
||||||
|
|
||||||
/// see pathfinder.h
|
/// see pathfinder.h
|
||||||
int AStarFixedUnitCrossingCost = MaxMapWidth * MaxMapHeight;
|
int AStarFixedUnitCrossingCost = MaxMapWidth * MaxMapHeight;
|
||||||
|
@ -93,9 +93,9 @@ int AStarKnowUnknown = 0;
|
||||||
int AStarUnknownTerrainCost = 2;
|
int AStarUnknownTerrainCost = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** The Open set is handled by a Heap stored in a table
|
** The Open set is handled by a Heap stored in a table
|
||||||
** 0 is the root
|
** 0 is the root
|
||||||
** node i left son is at 2*i+1 and right son is at 2*i+2
|
** node i left son is at 2*i+1 and right son is at 2*i+2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// The set of Open nodes
|
/// The set of Open nodes
|
||||||
|
@ -104,7 +104,7 @@ static Open* OpenSet;
|
||||||
static int OpenSetSize;
|
static int OpenSetSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Init A* data structures
|
** Init A* data structures
|
||||||
*/
|
*/
|
||||||
void InitAStar(void)
|
void InitAStar(void)
|
||||||
{
|
{
|
||||||
|
@ -119,7 +119,7 @@ void InitAStar(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Free A* data structure
|
** Free A* data structure
|
||||||
*/
|
*/
|
||||||
void FreeAStar(void)
|
void FreeAStar(void)
|
||||||
{
|
{
|
||||||
|
@ -132,7 +132,7 @@ void FreeAStar(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Prepare path finder.
|
** Prepare path finder.
|
||||||
*/
|
*/
|
||||||
static void AStarPrepare(void)
|
static void AStarPrepare(void)
|
||||||
{
|
{
|
||||||
|
@ -140,7 +140,7 @@ static void AStarPrepare(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Clean up the AStarMatrix
|
** Clean up the AStarMatrix
|
||||||
*/
|
*/
|
||||||
static void AStarCleanUp(int num_in_close)
|
static void AStarCleanUp(int num_in_close)
|
||||||
{
|
{
|
||||||
|
@ -157,9 +157,9 @@ static void AStarCleanUp(int num_in_close)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Find the best node in the current open node set
|
** Find the best node in the current open node set
|
||||||
** Returns the position of this node in the open node set (always 0 in the
|
** Returns the position of this node in the open node set (always 0 in the
|
||||||
** current heap based implementation)
|
** current heap based implementation)
|
||||||
*/
|
*/
|
||||||
#define AStarFindMinimum() 0
|
#define AStarFindMinimum() 0
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -170,8 +170,8 @@ static int AStarFindMinimum()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Remove the minimum from the open node set (and update the heap)
|
** Remove the minimum from the open node set (and update the heap)
|
||||||
** pos is the position of the minimum (0 in the heap based implementation)
|
** pos is the position of the minimum (0 in the heap based implementation)
|
||||||
*/
|
*/
|
||||||
static void AStarRemoveMinimum(int pos)
|
static void AStarRemoveMinimum(int pos)
|
||||||
{
|
{
|
||||||
|
@ -204,8 +204,8 @@ static void AStarRemoveMinimum(int pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add a new node to the open set (and update the heap structure)
|
** Add a new node to the open set (and update the heap structure)
|
||||||
** Returns Pathfinder failed
|
** Returns Pathfinder failed
|
||||||
*/
|
*/
|
||||||
static int AStarAddNode(int x, int y, int o, int costs)
|
static int AStarAddNode(int x, int y, int o, int costs)
|
||||||
{
|
{
|
||||||
|
@ -240,8 +240,8 @@ static int AStarAddNode(int x, int y, int o, int costs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Change the cost associated to an open node. The new cost MUST BE LOWER
|
** Change the cost associated to an open node. The new cost MUST BE LOWER
|
||||||
** than the old one in the current heap based implementation.
|
** than the old one in the current heap based implementation.
|
||||||
*/
|
*/
|
||||||
static void AStarReplaceNode(int pos, int costs)
|
static void AStarReplaceNode(int pos, int costs)
|
||||||
{
|
{
|
||||||
|
@ -267,8 +267,8 @@ static void AStarReplaceNode(int pos, int costs)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Check if a node is already in the open set.
|
** Check if a node is already in the open set.
|
||||||
** Return -1 if not found and the position of the node in the table if found.
|
** Return -1 if not found and the position of the node in the table if found.
|
||||||
*/
|
*/
|
||||||
static int AStarFindNode(int eo)
|
static int AStarFindNode(int eo)
|
||||||
{
|
{
|
||||||
|
@ -283,10 +283,10 @@ static int AStarFindNode(int eo)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Compute the cost of crossing tile (dx,dy)
|
** Compute the cost of crossing tile (dx,dy)
|
||||||
** -1 -> impossible to cross
|
** -1 -> impossible to cross
|
||||||
** 0 -> no induced cost, except move
|
** 0 -> no induced cost, except move
|
||||||
** >0 -> costly tile
|
** >0 -> costly tile
|
||||||
*/
|
*/
|
||||||
static int CostMoveTo(Unit* unit, int ex, int ey, int mask, int current_cost) {
|
static int CostMoveTo(Unit* unit, int ex, int ey, int mask, int current_cost) {
|
||||||
int j;
|
int j;
|
||||||
|
@ -332,7 +332,7 @@ static int CostMoveTo(Unit* unit, int ex, int ey, int mask, int current_cost) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** MarkAStarGoal
|
** MarkAStarGoal
|
||||||
*/
|
*/
|
||||||
static int AStarMarkGoal(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int maxrange,
|
static int AStarMarkGoal(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int maxrange,
|
||||||
int mask, int* num_in_close)
|
int mask, int* num_in_close)
|
||||||
|
@ -506,7 +506,7 @@ static int AStarMarkGoal(Unit* unit, int gx, int gy, int gw, int gh, int minrang
|
||||||
return goal_reachable;
|
return goal_reachable;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
** Find path.
|
** Find path.
|
||||||
*/
|
*/
|
||||||
int AStarFindPath(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int maxrange, char* path)
|
int AStarFindPath(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int maxrange, char* path)
|
||||||
{
|
{
|
||||||
|
@ -583,7 +583,7 @@ int AStarFindPath(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int
|
||||||
|
|
||||||
while( 1 ) {
|
while( 1 ) {
|
||||||
//
|
//
|
||||||
// Find the best node of from the open set
|
// Find the best node of from the open set
|
||||||
//
|
//
|
||||||
shortest=AStarFindMinimum();
|
shortest=AStarFindMinimum();
|
||||||
x=OpenSet[shortest].X;
|
x=OpenSet[shortest].X;
|
||||||
|
@ -594,7 +594,7 @@ int AStarFindPath(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int
|
||||||
AStarRemoveMinimum(shortest);
|
AStarRemoveMinimum(shortest);
|
||||||
|
|
||||||
//
|
//
|
||||||
// If we have reached the goal, then exit.
|
// If we have reached the goal, then exit.
|
||||||
if( AStarMatrix[o].InGoal==1 ) {
|
if( AStarMatrix[o].InGoal==1 ) {
|
||||||
ex=x;
|
ex=x;
|
||||||
ey=y;
|
ey=y;
|
||||||
|
@ -602,19 +602,19 @@ int AStarFindPath(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If we have looked too long, then exit.
|
// If we have looked too long, then exit.
|
||||||
//
|
//
|
||||||
if( !counter-- ) {
|
if( !counter-- ) {
|
||||||
//
|
//
|
||||||
// Select a "good" point from the open set.
|
// Select a "good" point from the open set.
|
||||||
// Nearest point to goal.
|
// Nearest point to goal.
|
||||||
DebugPrint("%d way too long\n" _C_ UnitNumber(unit));
|
DebugPrint("%d way too long\n" _C_ UnitNumber(unit));
|
||||||
AStarCleanUp(num_in_close);
|
AStarCleanUp(num_in_close);
|
||||||
return PF_FAILED;
|
return PF_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Generate successors of this node.
|
// Generate successors of this node.
|
||||||
|
|
||||||
// Node that this node was generated from.
|
// Node that this node was generated from.
|
||||||
px=x-Heading2X[(int)AStarMatrix[x+TheMap.Width*y].Direction];
|
px=x-Heading2X[(int)AStarMatrix[x+TheMap.Width*y].Direction];
|
||||||
|
@ -631,7 +631,7 @@ int AStarFindPath(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// Outside the map or can't be entered.
|
// Outside the map or can't be entered.
|
||||||
//
|
//
|
||||||
if( ex<0 || ex>=TheMap.Width ) {
|
if( ex<0 || ex>=TheMap.Width ) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -685,7 +685,7 @@ int AStarFindPath(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int
|
||||||
// we don't have to add this point to the close set
|
// we don't have to add this point to the close set
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( OpenSetSize<=0 ) { // no new nodes generated
|
if( OpenSetSize<=0 ) { // no new nodes generated
|
||||||
AStarCleanUp(num_in_close);
|
AStarCleanUp(num_in_close);
|
||||||
return PF_UNREACHABLE;
|
return PF_UNREACHABLE;
|
||||||
}
|
}
|
||||||
|
@ -733,14 +733,14 @@ int AStarFindPath(Unit* unit, int gx, int gy, int gw, int gh, int minrange, int
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Returns the next element of a path.
|
** Returns the next element of a path.
|
||||||
**
|
**
|
||||||
** @param unit Unit that wants the path element.
|
** @param unit Unit that wants the path element.
|
||||||
** @param pxd Pointer for the x direction.
|
** @param pxd Pointer for the x direction.
|
||||||
** @param pyd Pointer for the y direction.
|
** @param pyd Pointer for the y direction.
|
||||||
**
|
**
|
||||||
** @return >0 remaining path length, 0 wait for path, -1
|
** @return >0 remaining path length, 0 wait for path, -1
|
||||||
** reached goal, -2 can't reach the goal.
|
** reached goal, -2 can't reach the goal.
|
||||||
*/
|
*/
|
||||||
int NextPathElement(Unit* unit,int* pxd,int *pyd)
|
int NextPathElement(Unit* unit,int* pxd,int *pyd)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||||
// \/ \/ \//_____/ \/
|
// \/ \/ \//_____/ \/
|
||||||
// ______________________ ______________________
|
// ______________________ ______________________
|
||||||
// T H E W A R B E G I N S
|
// T H E W A R B E G I N S
|
||||||
// Stratagus - A free fantasy real time strategy game engine
|
// Stratagus - A free fantasy real time strategy game engine
|
||||||
//
|
//
|
||||||
/**@name pathfinder.c - The path finder routines. */
|
/**@name pathfinder.c - The path finder routines. */
|
||||||
//
|
//
|
||||||
// I use breadth-first.
|
// I use breadth-first.
|
||||||
//
|
//
|
||||||
// (c) Copyright 1998,2000-2003 by Lutz Sammer,Russell Smith
|
// (c) Copyright 1998,2000-2003 by Lutz Sammer,Russell Smith
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -28,12 +28,12 @@
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
//@{
|
//@{
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Includes
|
-- Includes
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||||
// \/ \/ \//_____/ \/
|
// \/ \/ \//_____/ \/
|
||||||
// ______________________ ______________________
|
// ______________________ ______________________
|
||||||
// T H E W A R B E G I N S
|
// T H E W A R B E G I N S
|
||||||
// Stratagus - A free fantasy real time strategy game engine
|
// Stratagus - A free fantasy real time strategy game engine
|
||||||
//
|
//
|
||||||
/**@name splitter.c - Map splitter into regions. */
|
/**@name splitter.c - Map splitter into regions. */
|
||||||
//
|
//
|
||||||
// (c) Copyright 1999-2003 by Ludovic Pollet
|
// (c) Copyright 1999-2003 by Ludovic Pollet
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,14 +26,14 @@
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
//@{
|
|
||||||
|
|
||||||
#ifdef MAP_REGIONS
|
#ifdef MAP_REGIONS
|
||||||
|
|
||||||
|
//@{
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Includes
|
-- Includes
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
#include "splitter_local.h"
|
#include "splitter_local.h"
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Variables
|
-- Variables
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,17 +66,17 @@ int ZoneNeedRefresh;
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Functions
|
-- Functions
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Unassign a tile to a region.
|
** Unassign a tile to a region.
|
||||||
** Connections are not updated here
|
** Connections are not updated here
|
||||||
**
|
**
|
||||||
** @param region the region ID
|
** @param region The region ID
|
||||||
** @param x X coord of the tile
|
** @param x X coord of the tile
|
||||||
** @param y Y coord of the tile
|
** @param y Y coord of the tile
|
||||||
*/
|
*/
|
||||||
void RegionUnassignTile(RegionId region, int x, int y)
|
void RegionUnassignTile(RegionId region, int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -144,12 +144,12 @@ void RegionUnassignTile(RegionId region, int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Assign a tile to a region.
|
** Assign a tile to a region.
|
||||||
** Connections are not updated here
|
** Connections are not updated here
|
||||||
**
|
**
|
||||||
** @param region the region ID
|
** @param region The region ID
|
||||||
** @param x X coord of the tile
|
** @param x X coord of the tile
|
||||||
** @param y Y coord of the tile
|
** @param y Y coord of the tile
|
||||||
*/
|
*/
|
||||||
void RegionAssignTile(RegionId region, int x, int y)
|
void RegionAssignTile(RegionId region, int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -196,10 +196,10 @@ void RegionAssignTile(RegionId region, int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Allocate a new region
|
** Allocate a new region
|
||||||
**
|
**
|
||||||
** @param iswater Indicate if the region is water/sea/...
|
** @param iswater Indicate if the region is water/sea/...
|
||||||
** @return the new RegionID
|
** @return the new RegionID
|
||||||
*/
|
*/
|
||||||
RegionId NewRegion(int iswater)
|
RegionId NewRegion(int iswater)
|
||||||
{
|
{
|
||||||
|
@ -241,9 +241,9 @@ RegionId NewRegion(int iswater)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Free a region
|
** Free a region
|
||||||
**
|
**
|
||||||
** @param regid The region to free
|
** @param regid The region to free
|
||||||
*/
|
*/
|
||||||
void RegionFree(RegionId regid)
|
void RegionFree(RegionId regid)
|
||||||
{
|
{
|
||||||
|
@ -273,7 +273,7 @@ void RegionFree(RegionId regid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Update connections for all regions (slow)
|
** Update connections for all regions (slow)
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void UpdateConnections(void)
|
void UpdateConnections(void)
|
||||||
|
@ -293,12 +293,12 @@ void UpdateConnections(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Split region according to the content of the "TempStorage"
|
** Split region according to the content of the "TempStorage"
|
||||||
** All tile with equal value will go in the same region
|
** All tile with equal value will go in the same region
|
||||||
**
|
**
|
||||||
** @param reg The region to split
|
** @param reg The region to split
|
||||||
** @param nbarea The number of area
|
** @param nbarea The number of area
|
||||||
** @param updateConnections indicate if connection should be updated
|
** @param updateConnections Indicate if connection should be updated
|
||||||
*/
|
*/
|
||||||
void RegionSplitUsingTemp(RegionId reg, int nbarea, int updateConnections)
|
void RegionSplitUsingTemp(RegionId reg, int nbarea, int updateConnections)
|
||||||
{
|
{
|
||||||
|
@ -394,10 +394,10 @@ void RegionSplitUsingTemp(RegionId reg, int nbarea, int updateConnections)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Join to region into only one. Either a or b is destroyed
|
** Join to region into only one. Either a or b is destroyed
|
||||||
**
|
**
|
||||||
** @param a One of the two regions
|
** @param a One of the two regions
|
||||||
** @param b One of the two regions
|
** @param b One of the two regions
|
||||||
*/
|
*/
|
||||||
void RegionJoin(RegionId a, RegionId b)
|
void RegionJoin(RegionId a, RegionId b)
|
||||||
{
|
{
|
||||||
|
@ -443,10 +443,10 @@ void RegionJoin(RegionId a, RegionId b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Split a region in two parts
|
** Split a region in two parts
|
||||||
**
|
**
|
||||||
** @param regid the region to broke
|
** @param regid the region to broke
|
||||||
** @param updateConnections indicate if connection should be updated as well
|
** @param updateConnections indicate if connection should be updated as well
|
||||||
*/
|
*/
|
||||||
void RegionSplit(RegionId regid, int updateConnections)
|
void RegionSplit(RegionId regid, int updateConnections)
|
||||||
{
|
{
|
||||||
|
@ -461,7 +461,7 @@ void RegionSplit(RegionId regid, int updateConnections)
|
||||||
int blocker;
|
int blocker;
|
||||||
int oldZoneNeedRefresh;
|
int oldZoneNeedRefresh;
|
||||||
int i;
|
int i;
|
||||||
CircularFiller fillers[2]; // We have 2 concurrent floodfiller
|
CircularFiller fillers[2]; // We have 2 concurrent floodfiller
|
||||||
|
|
||||||
oldZoneNeedRefresh = ZoneNeedRefresh;
|
oldZoneNeedRefresh = ZoneNeedRefresh;
|
||||||
|
|
||||||
|
@ -557,10 +557,10 @@ void RegionSplit(RegionId regid, int updateConnections)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Check that the given region is 8 - connex
|
** Check that the given region is 8 - connex
|
||||||
** ( all its tiles are reachable )
|
** (all its tiles are reachable)
|
||||||
**
|
**
|
||||||
** @param reg the region ID
|
** @param reg the region ID
|
||||||
*/
|
*/
|
||||||
void RegionCheckConnex(RegionId reg)
|
void RegionCheckConnex(RegionId reg)
|
||||||
{
|
{
|
||||||
|
@ -607,12 +607,13 @@ void RegionCheckConnex(RegionId reg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Called when a tile should no more belong to any regions
|
** Called when a tile should no more belong to any regions
|
||||||
**
|
**
|
||||||
** @param x x position of the tile
|
** @param x x position of the tile
|
||||||
** @param y y position of the tile
|
** @param y y position of the tile
|
||||||
*/
|
*/
|
||||||
static void MapSplitterTileOccuped(int x, int y) {
|
static void MapSplitterTileOccuped(int x, int y)
|
||||||
|
{
|
||||||
RegionId reg;
|
RegionId reg;
|
||||||
int tx;
|
int tx;
|
||||||
int ty;
|
int ty;
|
||||||
|
@ -669,14 +670,15 @@ static void MapSplitterTileOccuped(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add a rectangle of tiles to region mapping. Called when map change
|
** Add a rectangle of tiles to region mapping. Called when map change
|
||||||
**
|
**
|
||||||
** @param x0 x0 coord of the changed rectangle
|
** @param x0 x0 coord of the changed rectangle
|
||||||
** @param y0 y0 coord of the changed rectangle
|
** @param y0 y0 coord of the changed rectangle
|
||||||
** @param x1 x1 coord of the changed rectangle
|
** @param x1 x1 coord of the changed rectangle
|
||||||
** @param y1 y1 coord of the changed rectangle
|
** @param y1 y1 coord of the changed rectangle
|
||||||
*/
|
*/
|
||||||
void MapSplitterTilesCleared(int x0, int y0, int x1, int y1) {
|
void MapSplitterTilesCleared(int x0, int y0, int x1, int y1)
|
||||||
|
{
|
||||||
static int directions[5][2] = {{1,0},{0,1},{-1,0},{0,-1},{0,0}};
|
static int directions[5][2] = {{1,0},{0,1},{-1,0},{0,-1},{0,0}};
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
@ -774,12 +776,12 @@ void MapSplitterTilesCleared(int x0, int y0, int x1, int y1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Remove a rectangle of tiles from region mapping. Called when map change
|
** Remove a rectangle of tiles from region mapping. Called when map change
|
||||||
**
|
**
|
||||||
** @param x0 x0 coord of the changed rectangle
|
** @param x0 x0 coord of the changed rectangle
|
||||||
** @param y0 y0 coord of the changed rectangle
|
** @param y0 y0 coord of the changed rectangle
|
||||||
** @param x1 x1 coord of the changed rectangle
|
** @param x1 x1 coord of the changed rectangle
|
||||||
** @param y1 y1 coord of the changed rectangle
|
** @param y1 y1 coord of the changed rectangle
|
||||||
*/
|
*/
|
||||||
void MapSplitterTilesOccuped(int x0, int y0, int x1, int y1)
|
void MapSplitterTilesOccuped(int x0, int y0, int x1, int y1)
|
||||||
{
|
{
|
||||||
|
@ -798,7 +800,7 @@ void MapSplitterTilesOccuped(int x0, int y0, int x1, int y1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Decide if region should be broken, regarding size & nb of tiles
|
** Decide if region should be broken, regarding size & nb of tiles
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
static int ShouldBreakRegion(int x0, int y0, int x1, int y1, int tilecount, int hardlimit)
|
static int ShouldBreakRegion(int x0, int y0, int x1, int y1, int tilecount, int hardlimit)
|
||||||
|
@ -825,7 +827,7 @@ static int ShouldBreakRegion(int x0, int y0, int x1, int y1, int tilecount, int
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Extend A segment, fill it.
|
** Extend A segment, fill it.
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
static void FindHExtent(int x, int y, int* vx0, int* vx1, int water)
|
static void FindHExtent(int x, int y, int* vx0, int* vx1, int water)
|
||||||
|
@ -858,7 +860,7 @@ static void FindHExtent(int x, int y, int* vx0, int* vx1, int water)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Flood fill a region in the mapping area
|
** Flood fill a region in the mapping area
|
||||||
*/
|
*/
|
||||||
static void RegionFloodFill(int x0, int x1, int starty, int RegId, int IsWater)
|
static void RegionFloodFill(int x0, int x1, int starty, int RegId, int IsWater)
|
||||||
{
|
{
|
||||||
|
@ -909,8 +911,8 @@ static void RegionFloodFill(int x0, int x1, int starty, int RegId, int IsWater)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Initialise the region mapping ( map tile => regions )
|
** Initialise the region mapping ( map tile => regions )
|
||||||
** Need an already initialised map to work correctly
|
** Need an already initialised map to work correctly
|
||||||
*/
|
*/
|
||||||
void InitaliseMapping(void)
|
void InitaliseMapping(void)
|
||||||
{
|
{
|
||||||
|
@ -981,15 +983,15 @@ void InitaliseMapping(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Find a point of connexion between two zone.
|
** Find a point of connexion between two zone.
|
||||||
** The point closer to (refx,refy) in (a) is returned
|
** The point closer to (refx,refy) in (a) is returned
|
||||||
**
|
**
|
||||||
** @param a a zone number
|
** @param a a zone number
|
||||||
** @param b the other zone number
|
** @param b The other zone number
|
||||||
** @param refx Search closest to (refx,refy)
|
** @param refx Search closest to (refx,refy)
|
||||||
** @param refy Search closest to (refx,refy)
|
** @param refy Search closest to (refx,refy)
|
||||||
** @param rsltx Will hold result X
|
** @param rsltx Will hold result X
|
||||||
** @param rsltx Will hold result Y
|
** @param rsltx Will hold result Y
|
||||||
*/
|
*/
|
||||||
void ZoneFindConnexion(int a, int b, int refx, int refy, int* rsltx, int* rslty)
|
void ZoneFindConnexion(int a, int b, int refx, int refy, int* rsltx, int* rslty)
|
||||||
{
|
{
|
||||||
|
@ -1051,7 +1053,7 @@ void ZoneFindConnexion(int a, int b, int refx, int refy, int* rsltx, int* rslty)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Refresh connection between zones
|
** Refresh connection between zones
|
||||||
*/
|
*/
|
||||||
static void RefreshZones(void)
|
static void RefreshZones(void)
|
||||||
{
|
{
|
||||||
|
@ -1114,7 +1116,7 @@ static void RefreshZones(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Allocate space for tile=>region mapping
|
** Allocate space for tile=>region mapping
|
||||||
*/
|
*/
|
||||||
static void AllocateMapping(void)
|
static void AllocateMapping(void)
|
||||||
{
|
{
|
||||||
|
@ -1128,7 +1130,7 @@ static void AllocateMapping(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Initialise all data structures of the MapSplitter
|
** Initialise all data structures of the MapSplitter
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MapSplitterInit(void)
|
void MapSplitterInit(void)
|
||||||
|
@ -1144,7 +1146,7 @@ void MapSplitterInit(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Free all structure owned by the MapSplitter
|
** Free all structure owned by the MapSplitter
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MapSplitterClean(void)
|
void MapSplitterClean(void)
|
||||||
|
@ -1154,7 +1156,7 @@ void MapSplitterClean(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Called each cycle to maintain correctness of the mapping
|
** Called each cycle to maintain correctness of the mapping
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void MapSplitterEachCycle(void)
|
void MapSplitterEachCycle(void)
|
||||||
|
@ -1240,16 +1242,16 @@ void MapSplitterEachCycle(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Can the unit 'src' reach the place x,y.
|
** Can the unit 'src' reach the place x,y.
|
||||||
**
|
**
|
||||||
** @param src Unit for the path.
|
** @param src Unit for the path.
|
||||||
** @param x Map X tile position.
|
** @param x Map X tile position.
|
||||||
** @param y Map Y tile position.
|
** @param y Map Y tile position.
|
||||||
** @param w Width of Goal
|
** @param w Width of Goal
|
||||||
** @param h Height of Goal
|
** @param h Height of Goal
|
||||||
** @param range Range to the tile.
|
** @param range Range to the tile.
|
||||||
**
|
**
|
||||||
** @return Distance to place.
|
** @return Distance to place.
|
||||||
*/
|
*/
|
||||||
int PlaceReachable(Unit* src, int goal_x, int goal_y, int w, int h, int minrange, int maxrange)
|
int PlaceReachable(Unit* src, int goal_x, int goal_y, int w, int h, int minrange, int maxrange)
|
||||||
{
|
{
|
||||||
|
@ -1271,7 +1273,7 @@ int PlaceReachable(Unit* src, int goal_x, int goal_y, int w, int h, int minrange
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Check if zone connections need a refresh & do it
|
** Check if zone connections need a refresh & do it
|
||||||
*/
|
*/
|
||||||
void ClearZoneNeedRefresh(void)
|
void ClearZoneNeedRefresh(void)
|
||||||
{
|
{
|
||||||
|
@ -1281,5 +1283,7 @@ void ClearZoneNeedRefresh(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MAP_REGIONS
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
#endif // MAP_REGIONS
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||||
// \/ \/ \//_____/ \/
|
// \/ \/ \//_____/ \/
|
||||||
// ______________________ ______________________
|
// ______________________ ______________________
|
||||||
// T H E W A R B E G I N S
|
// T H E W A R B E G I N S
|
||||||
// Stratagus - A free fantasy real time strategy game engine
|
// Stratagus - A free fantasy real time strategy game engine
|
||||||
//
|
//
|
||||||
/**@name splitter.h - The map splitter headerfile. */
|
/**@name splitter.h - The map splitter headerfile. */
|
||||||
//
|
//
|
||||||
// (c) Copyright 1998-2003 by Ludovic Pollet
|
// (c) Copyright 1998-2003 by Ludovic Pollet
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
#ifndef __SPLITTER_H__
|
#ifndef __SPLITTER_H__
|
||||||
#define __SPLITTER_H__
|
#define __SPLITTER_H__
|
||||||
|
@ -38,10 +38,10 @@
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// Should be enough for every one :-)
|
// Should be enough for every one :-)
|
||||||
#define MaxZoneNumber 512 /// Max number of zone ( separated area )
|
#define MaxZoneNumber 512 ///< Max number of zone ( separated area )
|
||||||
#define MaxRegionNumber 4096 /// Max number of regions ( divisions of zones )
|
#define MaxRegionNumber 4096 ///< Max number of regions ( divisions of zones )
|
||||||
|
|
||||||
#define NoRegion ((RegionId)~0UL)
|
#define NoRegion ((RegionId)~0UL)
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Structures
|
-- Structures
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||||
// \/ \/ \//_____/ \/
|
// \/ \/ \//_____/ \/
|
||||||
// ______________________ ______________________
|
// ______________________ ______________________
|
||||||
// T H E W A R B E G I N S
|
// T H E W A R B E G I N S
|
||||||
// Stratagus - A free fantasy real time strategy game engine
|
// Stratagus - A free fantasy real time strategy game engine
|
||||||
//
|
//
|
||||||
/**@name splitter_debug.c - Map splitter into regions - debugging. */
|
/**@name splitter_debug.c - Map splitter into regions - debugging. */
|
||||||
//
|
//
|
||||||
// (c) Copyright 1999-2003 by Ludovic Pollet
|
// (c) Copyright 1999-2003 by Ludovic Pollet
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,13 +26,13 @@
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
//@{
|
//@{
|
||||||
|
|
||||||
#ifdef MAP_REGIONS
|
#ifdef MAP_REGIONS
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Includes
|
-- Includes
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -49,12 +49,12 @@
|
||||||
#include "splitter_local.h"
|
#include "splitter_local.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Start an xpm file for storing map representation (debug only)
|
** Start an xpm file for storing map representation (debug only)
|
||||||
**
|
**
|
||||||
** @param f Output file
|
** @param f Output file
|
||||||
** @param sx Image size (X)
|
** @param sx Image size (X)
|
||||||
** @param sy Image size (Y)
|
** @param sy Image size (Y)
|
||||||
** @param nbcols Max number of colors
|
** @param nbcols Max number of colors
|
||||||
*/
|
*/
|
||||||
static void StartXpm(FILE * f, int sx,int sy, int nbcols)
|
static void StartXpm(FILE * f, int sx,int sy, int nbcols)
|
||||||
{
|
{
|
||||||
|
@ -92,8 +92,8 @@ static void StartXpm(FILE * f, int sx,int sy, int nbcols)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Assign each region a color in such a way that
|
** Assign each region a color in such a way that
|
||||||
** two adjacents regions will never have the same color
|
** two adjacents regions will never have the same color
|
||||||
*/
|
*/
|
||||||
static void RegionAssignColor(void)
|
static void RegionAssignColor(void)
|
||||||
{
|
{
|
||||||
|
@ -119,9 +119,9 @@ static void RegionAssignColor(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Full Debug
|
** Full Debug
|
||||||
** Create a "debugregions.xpm" containing the splitted map
|
** Create a "debugregions.xpm" containing the splitted map
|
||||||
** Also call some debug functions
|
** Also call some debug functions
|
||||||
*/
|
*/
|
||||||
void MapSplitterDebug(void)
|
void MapSplitterDebug(void)
|
||||||
{
|
{
|
||||||
|
@ -220,9 +220,9 @@ void MapSplitterDebug(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Check that not mappable tile are not mapped,
|
** Check that not mappable tile are not mapped,
|
||||||
** check that water is mapped in watter region,
|
** check that water is mapped in watter region,
|
||||||
** ...
|
** ...
|
||||||
*/
|
*/
|
||||||
void RegionDebugWater(void)
|
void RegionDebugWater(void)
|
||||||
{
|
{
|
||||||
|
@ -242,10 +242,10 @@ void RegionDebugWater(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Check existing connections for a given region
|
** Check existing connections for a given region
|
||||||
** and compare with existing values
|
** and compare with existing values
|
||||||
**
|
**
|
||||||
** @param reg the region
|
** @param reg the region
|
||||||
*/
|
*/
|
||||||
static void RegionDebugConnexion(RegionId reg)
|
static void RegionDebugConnexion(RegionId reg)
|
||||||
{
|
{
|
||||||
|
@ -254,12 +254,12 @@ static void RegionDebugConnexion(RegionId reg)
|
||||||
int Connections[MaxRegionNumber];
|
int Connections[MaxRegionNumber];
|
||||||
int ConnectionsCount[MaxRegionNumber];
|
int ConnectionsCount[MaxRegionNumber];
|
||||||
int ConnectionNb;
|
int ConnectionNb;
|
||||||
// RegionDefinition * adef;
|
// RegionDefinition * adef;
|
||||||
|
|
||||||
int tx,ty;
|
int tx,ty;
|
||||||
int x,y;
|
int x,y;
|
||||||
int i,j;
|
int i,j;
|
||||||
// int found;
|
// int found;
|
||||||
|
|
||||||
seg = Regions[reg].FirstSegment;
|
seg = Regions[reg].FirstSegment;
|
||||||
ConnectionNb = 0;
|
ConnectionNb = 0;
|
||||||
|
@ -327,7 +327,7 @@ static void RegionDebugConnexion(RegionId reg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Find all existing connections between regions & compare to dynamic structure
|
** Find all existing connections between regions & compare to dynamic structure
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
void RegionDebugAllConnexions(void)
|
void RegionDebugAllConnexions(void)
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||||
// \/ \/ \//_____/ \/
|
// \/ \/ \//_____/ \/
|
||||||
// ______________________ ______________________
|
// ______________________ ______________________
|
||||||
// T H E W A R B E G I N S
|
// T H E W A R B E G I N S
|
||||||
// Stratagus - A free fantasy real time strategy game engine
|
// Stratagus - A free fantasy real time strategy game engine
|
||||||
//
|
//
|
||||||
/**@name splitter_local.h - The map headerfile. */
|
/**@name splitter_local.h - The map headerfile. */
|
||||||
//
|
//
|
||||||
// (c) Copyright 1998-2003 by Ludovic Pollet
|
// (c) Copyright 1998-2003 by Ludovic Pollet
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
#ifndef __SPLITTER_LOCAL_H__
|
#ifndef __SPLITTER_LOCAL_H__
|
||||||
#define __SPLITTER_LOCAL_H__
|
#define __SPLITTER_LOCAL_H__
|
||||||
|
@ -46,9 +46,9 @@ struct _region_line_{
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _region_definition_{
|
typedef struct _region_definition_{
|
||||||
int TileCount; ///< Nb of tile assigned to it
|
int TileCount; ///< Nb of tile assigned to it
|
||||||
int MinX, MinY; ///< Upper left corner
|
int MinX, MinY; ///< Upper left corner
|
||||||
int MaxX, MaxY; ///< Bottom right corner
|
int MaxX, MaxY; ///< Bottom right corner
|
||||||
|
|
||||||
long SumX, SumY; ///< May limit map to ~512x512
|
long SumX, SumY; ///< May limit map to ~512x512
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ typedef struct _circular_filler_{
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Macros
|
-- Macros
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
#define MaxZone 1024
|
#define MaxZone 1024
|
||||||
#define InMap(x,y) (((unsigned)(x)<(unsigned)TheMap.Width)&&(((unsigned)(y)<(unsigned)TheMap.Height)))
|
#define InMap(x,y) (((unsigned)(x)<(unsigned)TheMap.Width)&&(((unsigned)(y)<(unsigned)TheMap.Height)))
|
||||||
#define MapFlag(x,y) TheMap.Fields[x + TheMap.Width * y].Flags
|
#define MapFlag(x,y) TheMap.Fields[x + TheMap.Width * y].Flags
|
||||||
#define RegionMapping(x,y) (RegionMappingStorage[(x) + TheMap.Width * (y)])
|
#define RegionMapping(x,y) (RegionMappingStorage[(x) + TheMap.Width * (y)])
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||||
// \/ \/ \//_____/ \/
|
// \/ \/ \//_____/ \/
|
||||||
// ______________________ ______________________
|
// ______________________ ______________________
|
||||||
// T H E W A R B E G I N S
|
// T H E W A R B E G I N S
|
||||||
// Stratagus - A free fantasy real time strategy game engine
|
// Stratagus - A free fantasy real time strategy game engine
|
||||||
//
|
//
|
||||||
/**@name splitter_lowlevel.c - Low level funcs for Regions. */
|
/**@name splitter_lowlevel.c - Low level funcs for Regions. */
|
||||||
//
|
//
|
||||||
// (c) Copyright 1999-2003 by Ludovic Pollet
|
// (c) Copyright 1999-2003 by Ludovic Pollet
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,14 +26,14 @@
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
//@{
|
|
||||||
|
|
||||||
#ifdef MAP_REGIONS
|
#ifdef MAP_REGIONS
|
||||||
|
|
||||||
|
//@{
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Includes
|
-- Includes
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -50,10 +50,10 @@
|
||||||
#include "splitter_local.h"
|
#include "splitter_local.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Remove a segment from a region
|
** Remove a segment from a region
|
||||||
**
|
**
|
||||||
** @param def the RegionDefinition structure
|
** @param def The RegionDefinition structure
|
||||||
** @param seg the segment to remove
|
** @param seg The segment to remove
|
||||||
*/
|
*/
|
||||||
void RegionDelSegment(RegionDefinition* def, RegionSegment* seg)
|
void RegionDelSegment(RegionDefinition* def, RegionSegment* seg)
|
||||||
{
|
{
|
||||||
|
@ -73,12 +73,12 @@ void RegionDelSegment(RegionDefinition* def, RegionSegment* seg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add a segment to a region
|
** Add a segment to a region
|
||||||
**
|
**
|
||||||
** @param def the RegionDefinition structure
|
** @param def The RegionDefinition structure
|
||||||
** @param seg the segment to add
|
** @param seg The segment to add
|
||||||
*/
|
*/
|
||||||
void RegionAddSegment(RegionDefinition * def,int x0,int x1,int y)
|
void RegionAddSegment(RegionDefinition* def,int x0,int x1,int y)
|
||||||
{
|
{
|
||||||
RegionSegment* seg;
|
RegionSegment* seg;
|
||||||
seg = (RegionSegment*) malloc(sizeof(RegionSegment));
|
seg = (RegionSegment*) malloc(sizeof(RegionSegment));
|
||||||
|
@ -99,14 +99,14 @@ void RegionAddSegment(RegionDefinition * def,int x0,int x1,int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add a segment to a region. Eventually, existing segment are collapsed
|
** Add a segment to a region. Eventually, existing segment are collapsed
|
||||||
**
|
**
|
||||||
** @param def the RegionDefinition structure
|
** @param def The RegionDefinition structure
|
||||||
** @param x0 Minimum x of the segment
|
** @param x0 Minimum x of the segment
|
||||||
** @param x0 Maximum x of the segment
|
** @param x1 Maximum x of the segment
|
||||||
** @param y Y coord of the segment
|
** @param y Y coord of the segment
|
||||||
*/
|
*/
|
||||||
void RegionAppendSegment(RegionDefinition * def,int x0,int x1,int y)
|
void RegionAppendSegment(RegionDefinition* def, int x0, int x1, int y)
|
||||||
{
|
{
|
||||||
RegionSegment* seg;
|
RegionSegment* seg;
|
||||||
seg = def->FirstSegment;
|
seg = def->FirstSegment;
|
||||||
|
@ -125,11 +125,11 @@ void RegionAppendSegment(RegionDefinition * def,int x0,int x1,int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Update min & max in a region
|
** Update min & max in a region
|
||||||
**
|
**
|
||||||
** @param def the RegionDefinition structure
|
** @param def The RegionDefinition structure
|
||||||
** @param x X coord of a cell
|
** @param x X coord of a cell
|
||||||
** @param y Y coord of a cell
|
** @param y Y coord of a cell
|
||||||
*/
|
*/
|
||||||
void RegionUpdateMinMax(RegionDefinition* adef,int x,int y)
|
void RegionUpdateMinMax(RegionDefinition* adef,int x,int y)
|
||||||
{
|
{
|
||||||
|
@ -156,14 +156,14 @@ void RegionUpdateMinMax(RegionDefinition* adef,int x,int y)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Find A point one a region, closest to a given vertical line (x)
|
** Find A point one a region, closest to a given vertical line (x)
|
||||||
**
|
**
|
||||||
** @param def the RegionDefinition structure
|
** @param def The RegionDefinition structure
|
||||||
** @param x x coord of the vertical line
|
** @param x x coord of the vertical line
|
||||||
** @param vx X result value
|
** @param vx X result value
|
||||||
** @param vy Y result value
|
** @param vy Y result value
|
||||||
*/
|
*/
|
||||||
void RegionFindPointOnX(RegionDefinition * def,int x,int * vx,int * vy)
|
void RegionFindPointOnX(RegionDefinition* def,int x,int * vx,int * vy)
|
||||||
{
|
{
|
||||||
RegionSegment *cur;
|
RegionSegment *cur;
|
||||||
int bestx, besty, bestxdelta, bestydelta;
|
int bestx, besty, bestxdelta, bestydelta;
|
||||||
|
@ -209,14 +209,14 @@ void RegionFindPointOnX(RegionDefinition * def,int x,int * vx,int * vy)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Find A point one a region, closest to a given horizontal line (y)
|
** Find A point one a region, closest to a given horizontal line (y)
|
||||||
**
|
**
|
||||||
** @param def the RegionDefinition structure
|
** @param def The RegionDefinition structure
|
||||||
** @param x y coord of the horizontal line
|
** @param x y coord of the horizontal line
|
||||||
** @param vx X result value
|
** @param vx X result value
|
||||||
** @param vy Y result value
|
** @param vy Y result value
|
||||||
*/
|
*/
|
||||||
void RegionFindPointOnY(RegionDefinition * def,int y,int * vx,int * vy)
|
void RegionFindPointOnY(RegionDefinition* def,int y,int * vx,int * vy)
|
||||||
{
|
{
|
||||||
RegionSegment *cur;
|
RegionSegment *cur;
|
||||||
int bestx, besty, bestxdelta, bestydelta;
|
int bestx, besty, bestxdelta, bestydelta;
|
||||||
|
@ -262,7 +262,7 @@ void RegionFindPointOnY(RegionDefinition * def,int y,int * vx,int * vy)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Allocate the temp storage area
|
** Allocate the temp storage area
|
||||||
*/
|
*/
|
||||||
void RegionTempStorageAllocate(void)
|
void RegionTempStorageAllocate(void)
|
||||||
{
|
{
|
||||||
|
@ -270,7 +270,7 @@ void RegionTempStorageAllocate(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Free the temp storage area
|
** Free the temp storage area
|
||||||
*/
|
*/
|
||||||
void RegionTempStorageFree(void)
|
void RegionTempStorageFree(void)
|
||||||
{
|
{
|
||||||
|
@ -278,10 +278,10 @@ void RegionTempStorageFree(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Fill a region in the temp storage area
|
** Fill a region in the temp storage area
|
||||||
**
|
**
|
||||||
** @param adef the region definition
|
** @param adef The region definition
|
||||||
** @param value value to fill with
|
** @param value Value to fill with
|
||||||
*/
|
*/
|
||||||
void RegionTempStorageFillRegion(RegionDefinition* adef,int value)
|
void RegionTempStorageFillRegion(RegionDefinition* adef,int value)
|
||||||
{
|
{
|
||||||
|
@ -304,10 +304,10 @@ void RegionTempStorageFillRegion(RegionDefinition* adef,int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Unmark points of a regions in the temp storage area
|
** Unmark points of a regions in the temp storage area
|
||||||
**
|
**
|
||||||
** @param regid the regiond ID
|
** @param regid The regiond ID
|
||||||
** @param markvalue cells with value == markvalue will become 0
|
** @param markvalue Cells with value == markvalue will become 0
|
||||||
*/
|
*/
|
||||||
void RegionTempStorageUnmarkPoints(RegionId regid, int markvalue)
|
void RegionTempStorageUnmarkPoints(RegionId regid, int markvalue)
|
||||||
{
|
{
|
||||||
|
@ -333,16 +333,16 @@ void RegionTempStorageUnmarkPoints(RegionId regid, int markvalue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Mark some points of a region in the temp storage area
|
** Mark some points of a region in the temp storage area
|
||||||
**
|
**
|
||||||
** @param regid the regiond ID
|
** @param regid The regiond ID
|
||||||
** @param points MapPoint array
|
** @param points MapPoint array
|
||||||
** @param nbpoint MapPoint array size
|
** @param nbpoint MapPoint array size
|
||||||
** @param maxmak Maximum number of point to mark
|
** @param maxmak Maximum number of point to mark
|
||||||
** @param markvalu points get marked with this value
|
** @param markvalue Points get marked with this value
|
||||||
** @return The number of points marked
|
** @return The number of points marked
|
||||||
*/
|
*/
|
||||||
static int RegionTempStorageMarkPoints(RegionId regid, MapPoint * points, int nbpoints, int maxmark,int markvalue)
|
static int RegionTempStorageMarkPoints(RegionId regid, MapPoint* points, int nbpoints, int maxmark, int markvalue)
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
int rslt;
|
int rslt;
|
||||||
|
@ -374,11 +374,11 @@ static int RegionTempStorageMarkPoints(RegionId regid, MapPoint * points, int nb
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Mark limits of a regions in the temp storage area
|
** Mark limits of a regions in the temp storage area
|
||||||
**
|
**
|
||||||
** @param regid the regiond ID
|
** @param regid The regiond ID
|
||||||
** @param maxmak Maximum number of point to mark
|
** @param maxmak Maximum number of point to mark
|
||||||
** @param markvalu points get marked with this value
|
** @param markvalue Points get marked with this value
|
||||||
*/
|
*/
|
||||||
int RegionTempStorageMarkObstacle(RegionId regid, int maxmark,int markvalue)
|
int RegionTempStorageMarkObstacle(RegionId regid, int maxmark,int markvalue)
|
||||||
{
|
{
|
||||||
|
@ -472,19 +472,19 @@ int RegionTempStorageMarkObstacle(RegionId regid, int maxmark,int markvalue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Make marked points bigger ( mark their adjacent with markvalue + 1 )
|
** Make marked points bigger ( mark their adjacent with markvalue + 1 )
|
||||||
** Multiple invoquation lead to bigger marks
|
** Multiple invoquation lead to bigger marks
|
||||||
**
|
**
|
||||||
** @param regid the regiond ID
|
** @param regid The regiond ID
|
||||||
** @param maxmak Maximum number of point to mark
|
** @param maxmak Maximum number of point to mark
|
||||||
** @param markvalu points marked with this value will be "grown"
|
** @param markvalue Points marked with this value will be "grown"
|
||||||
*/
|
*/
|
||||||
int RegionTempStorageEmbossObstacle(RegionId regid, int maxmark,int markvalue)
|
int RegionTempStorageEmbossObstacle(RegionId regid, int maxmark,int markvalue)
|
||||||
{
|
{
|
||||||
int markednb;
|
int markednb;
|
||||||
RegionDefinition * adef;
|
RegionDefinition* adef;
|
||||||
RegionSegment * seg;
|
RegionSegment* seg;
|
||||||
MapPoint * marked;
|
MapPoint* marked;
|
||||||
int x,y;
|
int x,y;
|
||||||
int tx,ty;
|
int tx,ty;
|
||||||
int i;
|
int i;
|
||||||
|
@ -535,15 +535,15 @@ int RegionTempStorageEmbossObstacle(RegionId regid, int maxmark,int markvalue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Set the connection count in rega for regb to value
|
** Set the connection count in rega for regb to value
|
||||||
**
|
**
|
||||||
** @param rega The region to change connection value
|
** @param rega The region to change connection value
|
||||||
** @param regb Other region in the connection
|
** @param regb Other region in the connection
|
||||||
** @param value The new connection count between the two regions
|
** @param value The new connection count between the two regions
|
||||||
*/
|
*/
|
||||||
void RegionSetConnection(RegionId rega, RegionId regb, int value)
|
void RegionSetConnection(RegionId rega, RegionId regb, int value)
|
||||||
{
|
{
|
||||||
RegionDefinition * adef;
|
RegionDefinition* adef;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
adef = Regions + rega;
|
adef = Regions + rega;
|
||||||
|
@ -582,11 +582,11 @@ void RegionSetConnection(RegionId rega, RegionId regb, int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add to the connection count in rega for regb to value
|
** Add to the connection count in rega for regb to value
|
||||||
**
|
**
|
||||||
** @param rega The region to change connection value
|
** @param rega The region to change connection value
|
||||||
** @param regb Other region in the connection
|
** @param regb Other region in the connection
|
||||||
** @param value The value to add to the connection count between the two regions
|
** @param value The value to add to the connection count between the two regions
|
||||||
*/
|
*/
|
||||||
void RegionAddConnection(RegionId rega, RegionId regb,int value)
|
void RegionAddConnection(RegionId rega, RegionId regb,int value)
|
||||||
{
|
{
|
||||||
|
@ -627,11 +627,11 @@ void RegionAddConnection(RegionId rega, RegionId regb,int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add a value to a connection count between two regions (symetrical)
|
** Add a value to a connection count between two regions (symetrical)
|
||||||
**
|
**
|
||||||
** @param rega On of the region to change connection value
|
** @param rega On of the region to change connection value
|
||||||
** @param regb Other region in the connection
|
** @param regb Other region in the connection
|
||||||
** @param value The value to add to the connection count between the two regions
|
** @param value The value to add to the connection count between the two regions
|
||||||
*/
|
*/
|
||||||
void RegionAddBidirConnection(RegionId rega, RegionId regb,int value)
|
void RegionAddBidirConnection(RegionId rega, RegionId regb,int value)
|
||||||
{
|
{
|
||||||
|
@ -640,13 +640,13 @@ void RegionAddBidirConnection(RegionId rega, RegionId regb,int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Initialise a "CircularFiller", which fill points in the temp storage area.
|
** Initialise a "CircularFiller", which fill points in the temp storage area.
|
||||||
**
|
**
|
||||||
** @param filler pointer to a CircularFiller structure
|
** @param filler pointer to a CircularFiller structure
|
||||||
** @param region region to fill
|
** @param region region to fill
|
||||||
** @param startx start point x coord
|
** @param startx start point x coord
|
||||||
** @param starty start point y coord
|
** @param starty start point y coord
|
||||||
** @param value value it will fill with
|
** @param value value it will fill with
|
||||||
*/
|
*/
|
||||||
void CircularFillerInit(CircularFiller* filler, RegionId region, int startx, int starty, int value)
|
void CircularFillerInit(CircularFiller* filler, RegionId region, int startx, int starty, int value)
|
||||||
{
|
{
|
||||||
|
@ -663,9 +663,9 @@ void CircularFillerInit(CircularFiller* filler, RegionId region, int startx, int
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Free a CircularFiller private structures
|
** Free a CircularFiller private structures
|
||||||
**
|
**
|
||||||
** @param filler the filler to free
|
** @param filler the filler to free
|
||||||
*/
|
*/
|
||||||
void CircularFillerDone(CircularFiller * filler)
|
void CircularFillerDone(CircularFiller * filler)
|
||||||
{
|
{
|
||||||
|
@ -673,10 +673,10 @@ void CircularFillerDone(CircularFiller * filler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Mark one point with a circularefiller
|
** Mark one point with a circularefiller
|
||||||
**
|
**
|
||||||
** @param filler the filler
|
** @param filler the filler
|
||||||
** @return 1 if one point marked, 0 else
|
** @return 1 if one point marked, 0 else
|
||||||
*/
|
*/
|
||||||
int CircularFillerStep(CircularFiller * filler)
|
int CircularFillerStep(CircularFiller * filler)
|
||||||
{
|
{
|
||||||
|
@ -725,9 +725,9 @@ int CircularFillerStep(CircularFiller * filler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Rescan a region to update its connections
|
** Rescan a region to update its connections
|
||||||
**
|
**
|
||||||
** @param regid the region to scan
|
** @param regid the region to scan
|
||||||
*/
|
*/
|
||||||
void RegionRescanAdjacents(RegionId regid)
|
void RegionRescanAdjacents(RegionId regid)
|
||||||
{
|
{
|
||||||
|
@ -810,16 +810,16 @@ void RegionRescanAdjacents(RegionId regid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Adjust the connections of the given region, when taking cell x,y into account
|
** Adjust the connections of the given region, when taking cell x,y into account
|
||||||
** This function updates connections and eventually mark the region for a connex check
|
** This function updates connections and eventually mark the region for a connex check
|
||||||
**
|
**
|
||||||
** @param reg the region
|
** @param reg the region
|
||||||
** @param x X coord of the cell
|
** @param x X coord of the cell
|
||||||
** @param y Y coord of the cell
|
** @param y Y coord of the cell
|
||||||
** @param add 1 if cell is added to the region, 0 else
|
** @param add 1 if cell is added to the region, 0 else
|
||||||
** @param bidir Operate in both directions
|
** @param bidir Operate in both directions
|
||||||
*/
|
*/
|
||||||
void RegionUpdateConnection(RegionId reg,int x,int y,int add,int bidir)
|
void RegionUpdateConnection(RegionId reg, int x, int y, int add, int bidir)
|
||||||
{
|
{
|
||||||
int adj;
|
int adj;
|
||||||
int ax, ay;
|
int ax, ay;
|
||||||
|
@ -846,6 +846,7 @@ void RegionUpdateConnection(RegionId reg,int x,int y,int add,int bidir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // MAP_REGIONS
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
#endif // MAP_REGIONS
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||||
// \/ \/ \//_____/ \/
|
// \/ \/ \//_____/ \/
|
||||||
// ______________________ ______________________
|
// ______________________ ______________________
|
||||||
// T H E W A R B E G I N S
|
// T H E W A R B E G I N S
|
||||||
// Stratagus - A free fantasy real time strategy game engine
|
// Stratagus - A free fantasy real time strategy game engine
|
||||||
//
|
//
|
||||||
/**@name splitter_zoneset.c - Manipulation of zone set. */
|
/**@name splitter_zoneset.c - Manipulation of zone set. */
|
||||||
//
|
//
|
||||||
// (c) Copyright 1999-2003 by Ludovic Pollet
|
// (c) Copyright 1999-2003 by Ludovic Pollet
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// 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
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,14 +26,14 @@
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
// 02111-1307, USA.
|
// 02111-1307, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
//@{
|
|
||||||
|
|
||||||
#ifdef MAP_REGIONS
|
#ifdef MAP_REGIONS
|
||||||
|
|
||||||
|
//@{
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
-- Includes
|
-- Includes
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -51,10 +51,10 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Clear a ZoneSet structure (make it ready for usage)
|
** Clear a ZoneSet structure (make it ready for usage)
|
||||||
** Only first call eats CPU cycle.
|
** Only first call eats CPU cycle.
|
||||||
**
|
**
|
||||||
** @param m pointer to a ZoneSet structure
|
** @param m pointer to a ZoneSet structure
|
||||||
*/
|
*/
|
||||||
void ZoneSetClear(ZoneSet* m)
|
void ZoneSetClear(ZoneSet* m)
|
||||||
{
|
{
|
||||||
|
@ -74,11 +74,11 @@ void ZoneSetClear(ZoneSet* m)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add a zone to a ZoneSet structure
|
** Add a zone to a ZoneSet structure
|
||||||
**
|
**
|
||||||
** @param m pointer to a ZoneSet structure
|
** @param m Pointer to a ZoneSet structure
|
||||||
** @param zone zone to add
|
** @param zone Zone to add
|
||||||
** @return 1 if the zone is new in the set
|
** @return 1 if the zone is new in the set
|
||||||
*/
|
*/
|
||||||
int ZoneSetAddZone(ZoneSet * m, int zone)
|
int ZoneSetAddZone(ZoneSet * m, int zone)
|
||||||
{
|
{
|
||||||
|
@ -91,10 +91,10 @@ int ZoneSetAddZone(ZoneSet * m, int zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Make a union of two ZoneSet
|
** Make a union of two ZoneSet
|
||||||
**
|
**
|
||||||
** @param dst ZoneSet which will be modifier
|
** @param dst ZoneSet which will be modifier
|
||||||
** @param src ZoneSet which will be added into dst
|
** @param src ZoneSet which will be added into dst
|
||||||
*/
|
*/
|
||||||
void ZoneSetAddSet(ZoneSet* dst, ZoneSet* src)
|
void ZoneSetAddSet(ZoneSet* dst, ZoneSet* src)
|
||||||
{
|
{
|
||||||
|
@ -106,11 +106,11 @@ void ZoneSetAddSet(ZoneSet* dst, ZoneSet* src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Check if two ZoneSet have at least one common zone
|
** Check if two ZoneSet have at least one common zone
|
||||||
**
|
**
|
||||||
** @param dst pointer to a ZoneSet structure
|
** @param dst pointer to a ZoneSet structure
|
||||||
** @param src pointer to a ZoneSet structure
|
** @param src pointer to a ZoneSet structure
|
||||||
** @return 1 if a common zone was found, 0 else
|
** @return 1 if a common zone was found, 0 else
|
||||||
*/
|
*/
|
||||||
int ZoneSetHasIntersect(ZoneSet* dst, ZoneSet* src)
|
int ZoneSetHasIntersect(ZoneSet* dst, ZoneSet* src)
|
||||||
{
|
{
|
||||||
|
@ -124,10 +124,10 @@ int ZoneSetHasIntersect(ZoneSet* dst, ZoneSet* src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Compute the intersection of two ZoneSet structure
|
** Compute the intersection of two ZoneSet structure
|
||||||
**
|
**
|
||||||
** @param dst pointer to the ZoneSet which will hold the result
|
** @param dst pointer to the ZoneSet which will hold the result
|
||||||
** @param src other ZoneSet in the operation
|
** @param src other ZoneSet in the operation
|
||||||
*/
|
*/
|
||||||
void ZoneSetIntersect(ZoneSet* dst, ZoneSet* src)
|
void ZoneSetIntersect(ZoneSet* dst, ZoneSet* src)
|
||||||
{
|
{
|
||||||
|
@ -154,13 +154,13 @@ void ZoneSetIntersect(ZoneSet* dst, ZoneSet* src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add the zone of a map cell into a ZoneSet
|
** Add the zone of a map cell into a ZoneSet
|
||||||
**
|
**
|
||||||
** @param zs pointer to a ZoneSet structure
|
** @param zs pointer to a ZoneSet structure
|
||||||
** @param x X coord of the map cell
|
** @param x X coord of the map cell
|
||||||
** @param y Y coord of the map cell
|
** @param y Y coord of the map cell
|
||||||
*/
|
*/
|
||||||
void ZoneSetAddCell(ZoneSet * zs,int x,int y)
|
void ZoneSetAddCell(ZoneSet* zs, int x, int y)
|
||||||
{
|
{
|
||||||
RegionId region;
|
RegionId region;
|
||||||
|
|
||||||
|
@ -174,31 +174,31 @@ void ZoneSetAddCell(ZoneSet * zs,int x,int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Check if a ZoneSet contains a given zone
|
** Check if a ZoneSet contains a given zone
|
||||||
**
|
**
|
||||||
** @param zs pointer to the ZoneSet
|
** @param zs pointer to the ZoneSet
|
||||||
** @param zone the zone
|
** @param zone The zone
|
||||||
** @return 1 if zs contains the zone, 0 else
|
** @return 1 if zs contains the zone, 0 else
|
||||||
*/
|
*/
|
||||||
int ZoneSetContains(ZoneSet * zs,int zone)
|
int ZoneSetContains(ZoneSet* zs, int zone)
|
||||||
{
|
{
|
||||||
return zs->Marks[zone] == zs->Id;
|
return zs->Marks[zone] == zs->Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add a rectangle (not filled) of tile, if they are accessible regarding the mask
|
** Add a rectangle (not filled) of tile, if they are accessible regarding the mask
|
||||||
**
|
**
|
||||||
** @param zs pointer to a ZoneSet
|
** @param zs pointer to a ZoneSet
|
||||||
** @param x0 Rectangle coordinate
|
** @param x0 Rectangle coordinate
|
||||||
** @param y0 Rectangle coordinate
|
** @param y0 Rectangle coordinate
|
||||||
** @param x1 Rectangle coordinate
|
** @param x1 Rectangle coordinate
|
||||||
** @param y1 Rectangle coordinate
|
** @param y1 Rectangle coordinate
|
||||||
** @param range Range around the rectangle
|
** @param range Range around the rectangle
|
||||||
** @param mask Mask to check cell for
|
** @param mask Mask to check cell for
|
||||||
*/
|
*/
|
||||||
static void ZoneSetAddPassableRange(ZoneSet * zs,int x0,int y0,int x1,int y1,int range,int mask)
|
static void ZoneSetAddPassableRange(ZoneSet* zs, int x0, int y0, int x1, int y1, int range, int mask)
|
||||||
{
|
{
|
||||||
static int turn[5][2]={{1,0},{0,1},{-1,0},{0,-1}};
|
static const int turn[5][2] = {{1,0},{0,1},{-1,0},{0,-1}};
|
||||||
int x,y;
|
int x,y;
|
||||||
int dir;
|
int dir;
|
||||||
|
|
||||||
|
@ -219,15 +219,15 @@ static void ZoneSetAddPassableRange(ZoneSet * zs,int x0,int y0,int x1,int y1,int
|
||||||
dir++;
|
dir++;
|
||||||
}
|
}
|
||||||
x += turn[dir][0];
|
x += turn[dir][0];
|
||||||
y += turn[dir][1];
|
y += turn[dir][1];
|
||||||
} while (dir < 4);
|
} while (dir < 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add the zone(s) accessible by an unit
|
** Add the zone(s) accessible by an unit
|
||||||
**
|
**
|
||||||
** @param source pointer to a ZoneSet
|
** @param source Pointer to a ZoneSet
|
||||||
** @param src pointer to an unit
|
** @param src Pointer to an unit
|
||||||
*/
|
*/
|
||||||
void ZoneSetAddUnitZones(ZoneSet * source,Unit * src)
|
void ZoneSetAddUnitZones(ZoneSet * source,Unit * src)
|
||||||
{
|
{
|
||||||
|
@ -257,16 +257,16 @@ void ZoneSetAddUnitZones(ZoneSet * source,Unit * src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add a unit's goal to a zoneset. The goal is checked with the unit's movement mask
|
** Add a unit's goal to a zoneset. The goal is checked with the unit's movement mask
|
||||||
**
|
**
|
||||||
** @param dest pointer to a ZoneSet
|
** @param dest pointer to a ZoneSet
|
||||||
** @param src pointer to an unit
|
** @param src pointer to an unit
|
||||||
** @param goal_x coordinate of the goal
|
** @param goal_x coordinate of the goal
|
||||||
** @param goal_y coordinate of the goal
|
** @param goal_y coordinate of the goal
|
||||||
** @param w width in cell of the goal
|
** @param w width in cell of the goal
|
||||||
** @param h height in cell of the goal
|
** @param h height in cell of the goal
|
||||||
** @param minrange minrange to the goal
|
** @param minrange minrange to the goal
|
||||||
** @param maxrange maxrange to the goal
|
** @param maxrange maxrange to the goal
|
||||||
*/
|
*/
|
||||||
void ZoneSetAddGoalZones(ZoneSet* dest,Unit* src, int goal_x, int goal_y,int w,int h,int minrange,int maxrange)
|
void ZoneSetAddGoalZones(ZoneSet* dest,Unit* src, int goal_x, int goal_y,int w,int h,int minrange,int maxrange)
|
||||||
{
|
{
|
||||||
|
@ -309,11 +309,11 @@ void ZoneSetAddGoalZones(ZoneSet* dest,Unit* src, int goal_x, int goal_y,int w,i
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add To a ZoneSet zone which can be reached in one step from zone.
|
** Add To a ZoneSet zone which can be reached in one step from zone.
|
||||||
** Only Water-to-Land connexion are taken into account.
|
** Only Water-to-Land connexion are taken into account.
|
||||||
**
|
**
|
||||||
** @param dst pointer to a ZoneSet
|
** @param dst pointer to a ZoneSet
|
||||||
** @param zone the zone which adjacent are searched
|
** @param zone The zone which adjacent are searched
|
||||||
*/
|
*/
|
||||||
static void ZoneSetAddZoneAdjacents(ZoneSet * dst, int zone)
|
static void ZoneSetAddZoneAdjacents(ZoneSet * dst, int zone)
|
||||||
{
|
{
|
||||||
|
@ -335,10 +335,10 @@ static void ZoneSetAddZoneAdjacents(ZoneSet * dst, int zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Add to a ZoneSet all zone which are directly connected zones
|
** Add to a ZoneSet all zone which are directly connected zones
|
||||||
**
|
**
|
||||||
** @param dst ZoneSet to add zones to
|
** @param dst ZoneSet to add zones to
|
||||||
** @param src Zones for which connected zones are searched
|
** @param src Zones for which connected zones are searched
|
||||||
*/
|
*/
|
||||||
void ZoneSetAddConnected(ZoneSet* dst, ZoneSet * src)
|
void ZoneSetAddConnected(ZoneSet* dst, ZoneSet * src)
|
||||||
{
|
{
|
||||||
|
@ -349,17 +349,17 @@ void ZoneSetAddConnected(ZoneSet* dst, ZoneSet * src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Find a path throught zones (for transporters, ...)
|
** Find a path throught zones (for transporters, ...)
|
||||||
**
|
**
|
||||||
** @param src Starting zones
|
** @param src Starting zones
|
||||||
** @param dst Destination zones
|
** @param dst Destination zones
|
||||||
** @param path will hold the zones
|
** @param path will hold the zones
|
||||||
** @param pathlen will hold the path length
|
** @param pathlen will hold the path length
|
||||||
*/
|
*/
|
||||||
int ZoneSetFindPath(ZoneSet* src,ZoneSet* dst,int * path,int * pathlen)
|
int ZoneSetFindPath(ZoneSet* src, ZoneSet* dst, int* path, int* pathlen)
|
||||||
{
|
{
|
||||||
static ZoneSet current={0};
|
static ZoneSet current = {0};
|
||||||
static ZoneSet newzones={0};
|
static ZoneSet newzones = {0};
|
||||||
int zonedst[MaxZoneNumber];
|
int zonedst[MaxZoneNumber];
|
||||||
int zonenext[MaxZoneNumber];
|
int zonenext[MaxZoneNumber];
|
||||||
int i, j, curdst;
|
int i, j, curdst;
|
||||||
|
@ -425,6 +425,7 @@ int ZoneSetFindPath(ZoneSet* src,ZoneSet* dst,int * path,int * pathlen)
|
||||||
} while(1);
|
} while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MAP_REGIONS
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
#endif // MAP_REGIONS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue