Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
504 changes: 504 additions & 0 deletions blakserv/astar.c

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions blakserv/astar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Meridian 59, Copyright 1994-2012 Andrew Kirmse and Chris Kirmse.
// All rights reserved.
//
// This software is distributed under a license that is described in
// the LICENSE file that accompanies it.
//
// Meridian is a registered trademark.
/*
* astar.h:
*/

#ifndef _ASTAR_H
#define _ASTAR_H

#define CLOSEENOUGHDIST 3
#define DESTBLOCKIGNORE 3
#define ASTARENABLED 1

#define LCHILD(x) (2 * x + 1)
#define RCHILD(x) (2 * x + 2)
#define PARENT(x) ((x-1) / 2)

#define COST 1.0f
#define COST_DIAG ((float)M_SQRT2)

typedef struct room_type room_type;
typedef struct BspLeaf BspLeaf;
typedef struct astar_node_data astar_node_data;
typedef struct astar_node astar_node;

typedef struct astar_node_data
{
float cost;
float heuristic;
float combined;
astar_node* parent;
astar_node* heapslot;
int heapindex;
bool isInClosedList;
bool isBlocked;
} astar_node_data;

typedef struct astar_node
{
int Row;
int Col;
V2 Location;
BspLeaf* Leaf;
astar_node_data* Data;
} astar_node;

typedef struct astar
{
astar_node_data* NodesData;
int NodesDataSize;
astar_node** Grid;
astar_node* EndNode;
astar_node* LastNode;
int ObjectID;
int HeapSize;
} astar;

void AStarGenerateGrid(room_type* Room);
void AStarFreeGrid(room_type* Room);
bool AStarGetStepTowards(room_type* Room, V2* S, V2* E, V2* P, unsigned int* Flags, int ObjectID);

#endif /*#ifndef _ASTAR_H */
3 changes: 3 additions & 0 deletions blakserv/blakserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ char * GetLastErrorStr();
#include "stringinthash.h"
#include "intstringhash.h"

#include "geometry.h"

#include "blakres.h"
#include "channel.h"
#include "kodbase.h"
Expand All @@ -257,6 +259,7 @@ char * GetLastErrorStr();
#include "system.h"
#include "loadrsc.h"
#include "loadgame.h"
#include "astar.h"
#include "roofile.h"
#include "roomdata.h"
#include "files.h"
Expand Down
2 changes: 2 additions & 0 deletions blakserv/blakserv.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ copy $(SolutionDir)bin\libcurl.dll $(SolutionDir)run\server</Command>
<ClInclude Include="admincons.h" />
<ClInclude Include="adminfn.h" />
<ClInclude Include="apndfile.h" />
<ClInclude Include="astar.h" />
<ClInclude Include="async.h" />
<ClInclude Include="blakres.h" />
<ClInclude Include="blakserv.h" />
Expand Down Expand Up @@ -242,6 +243,7 @@ copy $(SolutionDir)bin\libcurl.dll $(SolutionDir)run\server</Command>
<ClCompile Include="admincons.c" />
<ClCompile Include="adminfn.c" />
<ClCompile Include="apndfile.c" />
<ClCompile Include="astar.c" />
<ClCompile Include="async.c" />
<ClCompile Include="blakres.c" />
<ClCompile Include="block.c" />
Expand Down
6 changes: 6 additions & 0 deletions blakserv/blakserv.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@
<ClInclude Include="geometry.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="astar.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="account.c">
Expand Down Expand Up @@ -436,6 +439,9 @@
<ClCompile Include="database.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="astar.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="logo.ico">
Expand Down
2 changes: 1 addition & 1 deletion blakserv/ccode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2675,7 +2675,7 @@ int C_CanMoveInRoomBSP(int object_id, local_var_type *local_vars,
e.Y = GRIDCOORDTOROO(row_dest.v.data, finerow_dest.v.data);

Wall* blockWall;
ret_val.v.data = BSPCanMoveInRoom(&r->data, &s, &e, objectid.v.data, (move_outside_bsp.v.data != 0), &blockWall);
ret_val.v.data = BSPCanMoveInRoom(&r->data, &s, &e, objectid.v.data, (move_outside_bsp.v.data != 0), &blockWall, false);

#if DEBUGMOVE
//dprintf("MOVE:%i R:%i S:(%1.2f/%1.2f) E:(%1.2f/%1.2f)", ret_val.v.data, r->data.roomdata_id, s.X, s.Y, e.X, e.Y);
Expand Down
3 changes: 2 additions & 1 deletion blakserv/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ OBJS = \
$(OUTDIR)\files.obj \
$(OUTDIR)\sprocket.obj \
$(OUTDIR)\database.obj \

$(OUTDIR)\astar.obj \

all : makedirs $(OUTDIR)\blakserv.exe

$(OUTDIR)\rscload.obj : $(TOPDIR)\util\rscload.c
Expand Down
2 changes: 1 addition & 1 deletion blakserv/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const char *memory_stat_names[] =
"Systimer", "Nameid",
"Class", "Message", "Object",
"List", "Object properties",
"Configuration", "Rooms",
"Configuration", "Rooms", "Astar",
"Admin constants", "Buffers", "Game loading",
"Tables", "Socket blocks", "Game saving",

Expand Down
2 changes: 1 addition & 1 deletion blakserv/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum
MALLOC_ID_SYSTIMER, MALLOC_ID_NAMEID,
MALLOC_ID_CLASS, MALLOC_ID_MESSAGE, MALLOC_ID_OBJECT,
MALLOC_ID_LIST, MALLOC_ID_OBJECT_PROPERTIES,
MALLOC_ID_CONFIG, MALLOC_ID_ROOM,
MALLOC_ID_CONFIG, MALLOC_ID_ROOM, MALLOC_ID_ASTAR,
MALLOC_ID_ADMIN_CONSTANTS, MALLOC_ID_BUFFER, MALLOC_ID_LOAD_GAME,
MALLOC_ID_TABLE, MALLOC_ID_BLOCK, MALLOC_ID_SAVE_GAME,

Expand Down
Loading