Skip to content

Commit c3bcc29

Browse files
author
cyberjunk
committed
Astar
1 parent eeebc47 commit c3bcc29

File tree

13 files changed

+842
-225
lines changed

13 files changed

+842
-225
lines changed

blakserv/astar.c

Lines changed: 504 additions & 0 deletions
Large diffs are not rendered by default.

blakserv/astar.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Meridian 59, Copyright 1994-2012 Andrew Kirmse and Chris Kirmse.
2+
// All rights reserved.
3+
//
4+
// This software is distributed under a license that is described in
5+
// the LICENSE file that accompanies it.
6+
//
7+
// Meridian is a registered trademark.
8+
/*
9+
* astar.h:
10+
*/
11+
12+
#ifndef _ASTAR_H
13+
#define _ASTAR_H
14+
15+
#define CLOSEENOUGHDIST 3
16+
#define DESTBLOCKIGNORE 3
17+
#define ASTARENABLED 1
18+
19+
#define LCHILD(x) (2 * x + 1)
20+
#define RCHILD(x) (2 * x + 2)
21+
#define PARENT(x) ((x-1) / 2)
22+
23+
#define HCOST 1.0f
24+
#define HCOST_DIAG ((float)M_SQRT2)
25+
26+
typedef struct room_type room_type;
27+
typedef struct BspLeaf BspLeaf;
28+
typedef struct astar_node_data astar_node_data;
29+
typedef struct astar_node astar_node;
30+
31+
typedef struct astar_node_data
32+
{
33+
float cost;
34+
float heuristic;
35+
float combined;
36+
astar_node* parent;
37+
astar_node* heapslot;
38+
int heapindex;
39+
bool isInClosedList;
40+
bool isBlocked;
41+
} astar_node_data;
42+
43+
typedef struct astar_node
44+
{
45+
int Row;
46+
int Col;
47+
V2 Location;
48+
BspLeaf* Leaf;
49+
astar_node_data* Data;
50+
} astar_node;
51+
52+
typedef struct astar
53+
{
54+
astar_node_data* NodesData;
55+
int NodesDataSize;
56+
astar_node** Grid;
57+
astar_node* EndNode;
58+
astar_node* LastNode;
59+
int ObjectID;
60+
int HeapSize;
61+
} astar;
62+
63+
void AStarGenerateGrid(room_type* Room);
64+
void AStarFreeGrid(room_type* Room);
65+
bool AStarGetStepTowards(room_type* Room, V2* S, V2* E, V2* P, unsigned int* Flags, int ObjectID);
66+
67+
#endif /*#ifndef _ASTAR_H */

blakserv/blakserv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ char * GetLastErrorStr();
241241
#include "stringinthash.h"
242242
#include "intstringhash.h"
243243

244+
#include "geometry.h"
245+
244246
#include "blakres.h"
245247
#include "channel.h"
246248
#include "kodbase.h"
@@ -257,6 +259,7 @@ char * GetLastErrorStr();
257259
#include "system.h"
258260
#include "loadrsc.h"
259261
#include "loadgame.h"
262+
#include "astar.h"
260263
#include "roofile.h"
261264
#include "roomdata.h"
262265
#include "files.h"

blakserv/blakserv.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ copy $(SolutionDir)bin\libcurl.dll $(SolutionDir)run\server</Command>
168168
<ClInclude Include="admincons.h" />
169169
<ClInclude Include="adminfn.h" />
170170
<ClInclude Include="apndfile.h" />
171+
<ClInclude Include="astar.h" />
171172
<ClInclude Include="async.h" />
172173
<ClInclude Include="blakres.h" />
173174
<ClInclude Include="blakserv.h" />
@@ -242,6 +243,7 @@ copy $(SolutionDir)bin\libcurl.dll $(SolutionDir)run\server</Command>
242243
<ClCompile Include="admincons.c" />
243244
<ClCompile Include="adminfn.c" />
244245
<ClCompile Include="apndfile.c" />
246+
<ClCompile Include="astar.c" />
245247
<ClCompile Include="async.c" />
246248
<ClCompile Include="blakres.c" />
247249
<ClCompile Include="block.c" />

blakserv/blakserv.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@
230230
<ClInclude Include="geometry.h">
231231
<Filter>Header Files</Filter>
232232
</ClInclude>
233+
<ClInclude Include="astar.h">
234+
<Filter>Header Files</Filter>
235+
</ClInclude>
233236
</ItemGroup>
234237
<ItemGroup>
235238
<ClCompile Include="account.c">
@@ -436,6 +439,9 @@
436439
<ClCompile Include="database.c">
437440
<Filter>Source Files</Filter>
438441
</ClCompile>
442+
<ClCompile Include="astar.c">
443+
<Filter>Source Files</Filter>
444+
</ClCompile>
439445
</ItemGroup>
440446
<ItemGroup>
441447
<Image Include="logo.ico">

blakserv/ccode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,7 @@ int C_CanMoveInRoomBSP(int object_id, local_var_type *local_vars,
26752675
e.Y = GRIDCOORDTOROO(row_dest.v.data, finerow_dest.v.data);
26762676

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

26802680
#if DEBUGMOVE
26812681
//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);

blakserv/makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ OBJS = \
9191
$(OUTDIR)\files.obj \
9292
$(OUTDIR)\sprocket.obj \
9393
$(OUTDIR)\database.obj \
94-
94+
$(OUTDIR)\astar.obj \
95+
9596
all : makedirs $(OUTDIR)\blakserv.exe
9697

9798
$(OUTDIR)\rscload.obj : $(TOPDIR)\util\rscload.c

blakserv/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ const char *memory_stat_names[] =
247247
"Systimer", "Nameid",
248248
"Class", "Message", "Object",
249249
"List", "Object properties",
250-
"Configuration", "Rooms",
250+
"Configuration", "Rooms", "Astar",
251251
"Admin constants", "Buffers", "Game loading",
252252
"Tables", "Socket blocks", "Game saving",
253253

blakserv/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum
2121
MALLOC_ID_SYSTIMER, MALLOC_ID_NAMEID,
2222
MALLOC_ID_CLASS, MALLOC_ID_MESSAGE, MALLOC_ID_OBJECT,
2323
MALLOC_ID_LIST, MALLOC_ID_OBJECT_PROPERTIES,
24-
MALLOC_ID_CONFIG, MALLOC_ID_ROOM,
24+
MALLOC_ID_CONFIG, MALLOC_ID_ROOM, MALLOC_ID_ASTAR,
2525
MALLOC_ID_ADMIN_CONSTANTS, MALLOC_ID_BUFFER, MALLOC_ID_LOAD_GAME,
2626
MALLOC_ID_TABLE, MALLOC_ID_BLOCK, MALLOC_ID_SAVE_GAME,
2727

0 commit comments

Comments
 (0)