Initial full mirror of c:\VWE (source + assets + toolchain + outputs) via Git LFS

Complete disaster-recovery snapshot: engine/game source, game data assets,
VC6 toolchain + DX SDKs, build outputs, deployed game, and _UNUSED archive.
Large binaries in Git LFS; text preserved byte-for-byte (core.autocrlf=false,
no eol attributes). See RECOVERY.md for the one-clone rebuild procedure.
This commit is contained in:
Cyd
2026-06-24 21:28:16 -05:00
commit 2b8ca921cb
66341 changed files with 7923174 additions and 0 deletions
+386
View File
@@ -0,0 +1,386 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Adept"=..\Libraries\Adept\Adept.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "AnimSize"=..\Tools\AnimSize\AnimSize.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name MW4Animation
End Project Dependency
Begin Project Dependency
Project_Dep_Name Stuff
End Project Dependency
Begin Project Dependency
Project_Dep_Name DLLPlatform
End Project Dependency
Begin Project Dependency
Project_Dep_Name GameOS
End Project Dependency
Begin Project Dependency
Project_Dep_Name Adept
End Project Dependency
Begin Project Dependency
Project_Dep_Name Compost
End Project Dependency
Begin Project Dependency
Project_Dep_Name ElementProxies
End Project Dependency
Begin Project Dependency
Project_Dep_Name ElementRenderer
End Project Dependency
Begin Project Dependency
Project_Dep_Name gosFX
End Project Dependency
Begin Project Dependency
Project_Dep_Name GOSScript
End Project Dependency
Begin Project Dependency
Project_Dep_Name ImageLib
End Project Dependency
Begin Project Dependency
Project_Dep_Name MLR
End Project Dependency
Begin Project Dependency
Project_Dep_Name Proxies
End Project Dependency
}}}
###############################################################################
Project: "AnimationSuite"=..\Tools\3DSPlugins\AnimationSuite\AnimationSuite.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name DLLPlatform
End Project Dependency
Begin Project Dependency
Project_Dep_Name MAXProxies
End Project Dependency
Begin Project Dependency
Project_Dep_Name Stuff
End Project Dependency
Begin Project Dependency
Project_Dep_Name GameOS
End Project Dependency
Begin Project Dependency
Project_Dep_Name Proxies
End Project Dependency
Begin Project Dependency
Project_Dep_Name ElementProxies
End Project Dependency
Begin Project Dependency
Project_Dep_Name ElementRenderer
End Project Dependency
Begin Project Dependency
Project_Dep_Name gosFX
End Project Dependency
Begin Project Dependency
Project_Dep_Name MLR
End Project Dependency
Begin Project Dependency
Project_Dep_Name MW4Animation
End Project Dependency
Begin Project Dependency
Project_Dep_Name Adept
End Project Dependency
Begin Project Dependency
Project_Dep_Name GOSScript
End Project Dependency
Begin Project Dependency
Project_Dep_Name Compost
End Project Dependency
Begin Project Dependency
Project_Dep_Name ImageLib
End Project Dependency
Begin Project Dependency
Project_Dep_Name MaxControls
End Project Dependency
}}}
###############################################################################
Project: "BRB"=..\Tools\3DSPlugins\BRB\BRB.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name GameOS
End Project Dependency
Begin Project Dependency
Project_Dep_Name Proxies
End Project Dependency
Begin Project Dependency
Project_Dep_Name Stuff
End Project Dependency
Begin Project Dependency
Project_Dep_Name DLLPlatform
End Project Dependency
Begin Project Dependency
Project_Dep_Name MAXProxies
End Project Dependency
Begin Project Dependency
Project_Dep_Name ElementProxies
End Project Dependency
Begin Project Dependency
Project_Dep_Name gosFX
End Project Dependency
Begin Project Dependency
Project_Dep_Name ElementRenderer
End Project Dependency
Begin Project Dependency
Project_Dep_Name MLR
End Project Dependency
Begin Project Dependency
Project_Dep_Name ImageLib
End Project Dependency
}}}
###############################################################################
Project: "Compost"=..\Libraries\Compost\Compost.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "DLLPlatform"=..\..\coretech\libraries\DLLPlatform\DLLPlatform.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "ElementProxies"=..\Libraries\ElementProxies\ElementProxies.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "ElementRenderer"=..\Libraries\ElementRenderer\ElementRenderer.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "GOSScript"=..\..\CoreTech\Libraries\GOSScript\GOSScript.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "GameOS"=..\..\coretech\libraries\gameos\GameOS.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "GamePlatform"=..\..\coretech\libraries\GamePlatform\GamePlatform.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "ImageLib"=..\Libraries\ImageLib\ImageLib.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "MAXProxies"=..\Libraries\MAXProxies\MAXProxies.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "MLR"=..\Libraries\MLR\MLR.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "MW4Animation"=.\MW4\MW4Animation.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "MaxControls"=..\TOOLS\3DSPLUGINS\MaxControls\MaxControls.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "Poltest"=..\Tools\3DSPlugins\Polisher\Poltest.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "Proxies"=..\Libraries\Proxies\Proxies.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "Stuff"=..\Libraries\Stuff\Stuff.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name stlport
End Project Dependency
}}}
###############################################################################
Project: "gosFX"=..\Libraries\gosfx\gosFX.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "stlport"=..\Libraries\stlport\stlport.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################
+282
View File
@@ -0,0 +1,282 @@
# Microsoft Developer Studio Project File - Name="AI test" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=AI test - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "AI test.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "AI test.mak" CFG="AI test - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "AI test - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "AI test - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "AI test - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /Gr /W3 /GR /GX /Zi /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /D "DX5" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ddraw.lib winmm.lib /nologo /subsystem:windows /map /debug /machine:I386
!ELSEIF "$(CFG)" == "AI test - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /Gr /W3 /Gm /GR /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /D "DX5" /YX /FD /c
# SUBTRACT CPP /Fr
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib winmm.lib ddraw.lib version.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "AI test - Win32 Release"
# Name "AI test - Win32 Debug"
# Begin Group "Headers"
# PROP Default_Filter "*.hpp;*.h"
# Begin Source File
SOURCE=".\ai aware.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai combat.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai comm.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai command.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai conversation.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai event.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai formation.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai know.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai move.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai nnet.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai priority.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai state.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai test wnd.hpp"
# End Source File
# Begin Source File
SOURCE=".\ai test.hpp"
# End Source File
# Begin Source File
SOURCE=.\ai.hpp
# End Source File
# Begin Source File
SOURCE=.\aihicom.hpp
# End Source File
# Begin Source File
SOURCE=.\airailpath.hpp
# End Source File
# Begin Source File
SOURCE=.\globals.hpp
# End Source File
# Begin Source File
SOURCE=.\map.hpp
# End Source File
# Begin Source File
SOURCE=.\move.hpp
# End Source File
# Begin Source File
SOURCE=.\movecell.hpp
# End Source File
# Begin Source File
SOURCE=.\movezone.hpp
# End Source File
# Begin Source File
SOURCE=.\prototype.hpp
# End Source File
# Begin Source File
SOURCE=.\test.hpp
# End Source File
# Begin Source File
SOURCE=.\windows.hpp
# End Source File
# End Group
# Begin Group "Source"
# PROP Default_Filter "*.cpp;*.c"
# Begin Source File
SOURCE=".\ai aware.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai combat.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai comm.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai conversation.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai formation.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai global.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai know.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai move.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai nnet.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai state.cpp"
# End Source File
# Begin Source File
SOURCE=".\ai test wnd.cpp"
# End Source File
# Begin Source File
SOURCE=.\airailpath.cpp
# End Source File
# Begin Source File
SOURCE=.\globals.cpp
# End Source File
# Begin Source File
SOURCE=.\main.cpp
# End Source File
# Begin Source File
SOURCE=.\map.cpp
# End Source File
# Begin Source File
SOURCE=.\move.cpp
# End Source File
# Begin Source File
SOURCE=.\movecell.cpp
# End Source File
# Begin Source File
SOURCE=.\movezone.cpp
# End Source File
# Begin Source File
SOURCE=.\system.cpp
# End Source File
# Begin Source File
SOURCE=.\windows.cpp
# End Source File
# Begin Source File
SOURCE=.\work.cpp
# End Source File
# End Group
# End Target
# End Project
@@ -0,0 +1,19 @@
#pragma warning (disable:4786)
#include "ai.hpp"
AIAwareness::AIAwareness (AI *parent)
{
m_Knowledge = NULL;
m_SizeKnowledge = 0;
}
AIAwareness::~AIAwareness (void)
{
if (m_Knowledge)
delete[] m_Knowledge;
}
CommandEntry *AIAwareness::Think (double value,CommandEntry *lastcom)
{
return NULL;
}
@@ -0,0 +1,18 @@
#ifndef __AIAWAREHPP__
#define __AIAWAREHPP__
#include "ai know.hpp"
class AIAwareness {
private:
AIKnowledge *m_Knowledge;
UINT m_SizeKnowledge;
public:
AIAwareness (AI *parent);
~AIAwareness (void);
virtual CommandEntry *Think (double value,CommandEntry *lastcom); // if need to remove then delete
};
#endif
@@ -0,0 +1,16 @@
#pragma warning (disable:4786)
#include "ai.hpp"
AICombat::AICombat (AI *parent)
{
}
AICombat::~AICombat (void)
{
}
CommandEntry *AICombat::Think (double value,CommandEntry *lastcom)
{
return NULL;
}
@@ -0,0 +1,96 @@
#ifndef __AICOMBATHPP__
#define __AICOMBATHPP__
enum HTHTYPE { HIGHSWING_HTH,LOWSWING_HTH,HIGHBLOCK_HTH,LOWBLOCK_HTH,SIDESTEP_HTH,
HIGHKICK_HTH,LOWKICK_HTH,MOVEBACK_HTH,MOVETHROUGH_HTH,CRUSH_HTH};
enum RANGETYPE { CHARGE_RANGE,ATTACK_RANGE,FLANK_RANGE,COVER_RANGE,KNEEL_RANGE,PRONE_RANGE};
// hth structures for data
typedef struct
{
} highSwingData;
typedef struct
{
} lowSwingData;
typedef struct
{
} highBlockData;
typedef struct
{
} lowBlockData;
typedef struct
{
} sideStepData;
typedef struct
{
} highKickData;
typedef struct
{
} lowKickData;
typedef struct
{
} moveBackData;
typedef struct
{
} moveThroughData;
typedef struct
{
} crushData;
// ranged structures for data
typedef struct
{
} chargeData;
typedef struct
{
} attackData;
typedef struct
{
BOOL left;
} flankData;
typedef struct
{
} coverData;
typedef struct
{
} kneelData;
typedef struct
{
} proneData;
typedef union {
highSwingData HighSwingHTHData;
lowSwingData LowSwingHTHData;
highBlockData HighBlockHTHData;
lowBlockData LowBlockHTHData;
sideStepData SideStepHTHData;
highKickData HighKickHTHData;
lowKickData LowKickHTHData;
moveBackData MoveBackHTHData;
moveThroughData MoveThroughHTHData;
crushData CrushHTHData;
} HTHUnion;
typedef union {
chargeData ChargeRangeData;
attackData AttackRangeData;
flankData FlankRangeData;
coverData CoverRangeData;
kneelData KneelRangeData;
proneData ProneRangeData;
} RangeUnion;
class AICombat {
public:
AICombat (AI *parent);
~AICombat (void);
virtual CommandEntry *Think (double value,CommandEntry *lastcom); // if need to remove then delete
};
#endif
@@ -0,0 +1,15 @@
#pragma warning (disable:4786)
#include "ai.hpp"
AIComm::AIComm (AI *parent)
{
}
AIComm::~AIComm (void)
{
}
CommandEntry *AIComm::Think (double value,CommandEntry *lastcom)
{
return NULL;
}
@@ -0,0 +1,12 @@
#ifndef __AICOMMHPP__
#define __AICOMMHPP__
class AIComm {
public:
AIComm (AI *parent);
~AIComm (void);
virtual CommandEntry *Think (double value,CommandEntry *lastcom); // if need to remove then delete
};
#endif
@@ -0,0 +1,127 @@
#ifndef __AICOMMANDHPP__
#define __AICOMMANDHPP__
enum AICOMMAND { MOVE_CMD,SAY_CMD,STANCE_CMD,TURN_CMD,SEND_CMD,
PLACEMENT_CMD,ATTACK_CMD,TRADE_CMD,SPECIAL_CMD,ADJUST_CMD,REMOVE_CMD};
typedef struct
{
double speed; // speed to move there
void *curpath; // current path to follow, probably just a list of points
UINT inpath; // where in path list we are
double sx,sy,sz; // start location
double dx,dy,dz; // destination location
UINT sPosture; // starting posture
UINT dPosture; // destination posture
double dFacing; // destination facing
} MoveCommandData;
typedef struct
{
char *text; // text to say
UINT tone; // tone of voice
UINT intext; // where in text we are
} SayCommandData;
typedef struct
{
UINT stance; // stance to enter
UINT curpos; // phase of changing stance
} StanceCommandData;
typedef struct
{
bool absolute; // true if using the facing variable
double facing; // facing to turn to
double speed; // speed to turn
AI *turnto; // object to face, instead of absolute facing
} TurnCommandData;
typedef struct
{
UINT type; // type of information to send
AI *dest; // object to send the data to
UINT method; // how to send the data, means how much is sent at a time
UINT where; // where in data being sent we are
} SendCommandData;
typedef struct
{
double x,y,z; // location to be in
double facing; // direction to face
UINT pos; // position of various parts in location
UINT where; // where in movement we are
} PlacementCommandData;
typedef struct
{
AI *who; // object to attack
UINT with; // what to attack with
UINT action; // type of attack
UINT where; // where in sequence we are
} AttackCommandData;
typedef struct
{
AI *who; // object to trade with
AI *what; // object to trade
UINT how; // how we want to perform the trade (hand, magic, etc)
} TradeCommandData;
typedef struct
{
UINT action; // special action to perform
UINT where; // where in sequence we are
} SpecialCommandData;
typedef struct
{
//· code for changing sort order or priority levels
//· new sort order
//· new priority level
//· priority set to remove
//· priority set to add
} AdjustCommandData;
typedef struct
{
//· command area from which to remove command
//· command id of command to remove
//· other info to pick what command to remove
} RemoveCommandData;
union CommandUnion
{
MoveCommandData moveData;
SayCommandData sayData;
StanceCommandData stanceData;
TurnCommandData turnData;
SendCommandData sendData;
PlacementCommandData placementData;
AttackCommandData attackData;
TradeCommandData tradeData;
SpecialCommandData specialData;
AdjustCommandData adjustData;
RemoveCommandData removeData;
};
struct CommandEntry{
static FixedHeap<CommandEntry> m_EmptyCommand;
AICOMMAND commandType;
UINT validFor;
UINT priority;
AIAREA from;
CommandUnion commandData;
CommandEntry *next,*prev;
CommandEntry *sort_next,*sort_prev;
CommandEntry *chain_next,*chain_prev;
static CommandEntry *GetBlankCommand (void) { return (CommandEntry *) m_EmptyCommand.Alloc (); }
static void DoneCommand (CommandEntry *oldknow) { m_EmptyCommand.Free (oldknow); }
void *operator new (size_t size) {return GetBlankCommand (); }
void operator delete (void *value,size_t size) { DoneCommand ((CommandEntry *) value); }
};
#endif
@@ -0,0 +1,15 @@
#pragma warning (disable:4786)
#include "ai.hpp"
AIConverse::AIConverse (AI *parent)
{
}
AIConverse::~AIConverse (void)
{
}
CommandEntry *AIConverse::Think (double value,CommandEntry *lastcom)
{
return NULL;
}
@@ -0,0 +1,12 @@
#ifndef __AICONVERSATIONHPP__
#define __AICONVERSATIONHPP__
class AIConverse {
public:
AIConverse (AI *parent);
~AIConverse (void);
virtual CommandEntry *Think (double value,CommandEntry *lastcom); // if need to remove then delete
};
#endif
@@ -0,0 +1,68 @@
#ifndef __AIEVENTHPP__
#define __AIEVENTHPP__
enum EVENTTYPE {REACH_EVENT,RANDOM_EVENT,TIME_EVENT,TIMEOUT_EVENT,ATTACKED_EVENT,INTRUDER_EVENT,
WALKBY_EVENT,SPEAKTO_EVENT,PATHBLOCK_EVENT,TASKDONE_EVENT,PROTECTEDATTACKED_EVENT};
typedef struct {
} ReachEventData;
typedef struct {
int rollLess; // percentile system
} RandomEventData;
typedef struct {
int timePeriod;
} TimeEventData;
typedef struct {
int timePeriod;
int startTime;
} TimeoutEventData;
typedef struct {
} AttackedEventData;
typedef struct {
} IntruderEventData;
typedef struct {
} WalkByEventData;
typedef struct {
} SpeakToEventData;
typedef struct {
} PathBlockEventData;
typedef struct {
} TaskDoneEventData;
typedef struct {
} ProtectedAttackedEventData;
typedef union {
ReachEventData reachData;
RandomEventData randomData;
TimeEventData timeData;
TimeoutEventData timeoutData;
AttackedEventData attackedData;
IntruderEventData intruderData;
WalkByEventData walkbyData;
SpeakToEventData speaktoData;
PathBlockEventData pathblockData;
TaskDoneEventData taskdoneData;
ProtectedAttackedEventData protectedattackedData;
} EventUnion;
typedef struct EventEntry{
EVENTTYPE eventType;
int newStateID;
EventUnion eventData;
EventEntry *next,*prev;
} EventEntry;
#endif
@@ -0,0 +1,352 @@
#pragma warning (disable:4786)
#include "ai formation.hpp"
#include "globals.hpp"
extern float pathmap[MAPSIZE][MAPSIZE];
bool Passable (int dx,int dy);
AIFormation::AIFormation (void)
{
m_Location.x = 1;
m_Location.y = 1;
}
AIFormation::~AIFormation (void)
{
}
bool AIFormation::AddAI (AI *newai)
{
AIMove *temp;
temp = newai->Move ();
if (!temp)
return false;
return temp->JoinFormation (*this);
}
bool AIFormation::AddMove (AIMove *newmove)
{
FormationData temp;
temp.member = newmove;
temp.dx = 1;
temp.dy = 1;
m_CurrentMembers.push (temp);
return true;
}
void AIFormation::SetDestination (int x,int y)
{
curdes.x = x;
curdes.y = y;
newdes = true;
}
bool AIFormation::Think (double value)
{
if (newdes)
{
if (!g_Map[curdes.x][curdes.y].passable)
return false;
newdes = false;
if (!CalcPath (-1,true))
return false;
}
if (m_CurPath.empty())
return false;
int i,size;
FormationData temp;
PATHELEMENT path = m_CurPath.top();
m_CurPath.pop ();
size = m_CurrentMembers.size();
for (i=0;i<size;i++)
{
temp = m_CurrentMembers.front();
m_CurrentMembers.pop();
m_CurrentMembers.push (temp);
// temp.member->SetFormationDes (path.x,path.y);
temp.member->Parent ()->Think (value);
}
// m_Location.x = path.x;
// m_Location.y = path.y;
return true;
}
float AIFormation::GetOneCost (int sx,int sy,int dx,int dy)
{
int deltax,deltay;
if (!Passable (dx,dy))
return -1;
deltax = dx - sx;
deltay = dy - sy;
if (deltax == 0)
return 1;
if (deltay == 0)
return 1;
return 1.5f;
}
float AIFormation::PathCostGuess (int sx,int sy,int dx,int dy)
{
int t1,t2;
t1 = dx - sx;
t2 = dy - sy;
__asm
{
mov eax,t1
cdq
xor eax,edx
sub eax,edx
mov t1,eax
mov eax,t2
cdq
xor eax,edx
sub eax,edx
mov t2,eax
}
if (t1 == 0)
return t2;
if (t2 == 0)
return t1;
if ((t1 == 0) && (t2 == 0))
return 0;
float f1,f2;
f1 = t1;
f2 = t2;
return f2 < f1 ? (f1+(f2/2.0)) : (f2+(f1/2.0));
}
bool AIFormation::CalcPath (int depth,bool followshort)
{
#if 0
int i,j;
FibHeap calc;
CALCELEMENT *temp;
CALCELEMENT *shortdes = NULL;
const int OFFSIZE = 8;
int lastdepth;
int offset[OFFSIZE][2] = {
{-1,-1},
{-1,0},
{-1,1},
{0,-1},
{0,1},
{1,-1},
{1,0},
{1,1}
};
int x=-1,y=-1;
bool done;
while (!m_CurPath.empty ())
m_CurPath.pop ();
for (i=0;i<MAPSIZE;i++)
{
for (j=0;j<MAPSIZE;j++)
{
pathmap[i][j] = 0;
}
}
temp = new CALCELEMENT (Location().x,Location().y);
pathmap[Location().x][Location().y] = 1;
calc.Insert (temp);
done = false;
lastdepth = 0;
while (!done && ((depth == -1)||(depth<lastdepth)))
{
temp = (CALCELEMENT *) calc.ExtractMin ();
if (temp == NULL)
break;
lastdepth = pathmap[temp->x][temp->y];
for (i=0;i<OFFSIZE;i++)
{
x = offset[i][0] + temp->x;
y = offset[i][1] + temp->y;
float cost = GetOneCost (temp->x,temp->y,x,y);
if (cost == -1)
continue;
cost += PathCostGuess (x,y,curdes.x,curdes.y);
if ((pathmap[x][y] == 0) || (pathmap[x][y] > (pathmap[temp->x][temp->y]+cost)))
{
pathmap[x][y] = pathmap[temp->x][temp->y]+cost;
calc.Insert (new CALCELEMENT(x,y));
}
if ((x == curdes.x) && (y == curdes.y))
{
done = true;
break;
}
}
delete temp;
}
if ((!done) && (depth != -1) && (depth>=lastdepth) && followshort)
{
shortdes = (CALCELEMENT *) calc.ExtractMin ();
if (shortdes)
done = true;
}
while (temp = (CALCELEMENT *) calc.ExtractMin ())
delete temp;
if (!done)
return false;
done = false;
int curx,cury,min;
if (shortdes)
{
curx = shortdes->x;
cury = shortdes->y;
delete shortdes;
}
else
{
curx = curdes.x;
cury = curdes.y;
}
m_CurPath.push (PATHELEMENT (curx,cury));
min = -1;
while (!done)
{
min = -1;
assert (pathmap[curx][cury] != 0);
for (i=0;i<OFFSIZE;i++)
{
x = offset[i][0] + curx;
y = offset[i][1] + cury;
if (x < 0)
continue;
if (x >= MAPSIZE)
continue;
if (y < 0)
continue;
if (y >= MAPSIZE)
continue;
if (pathmap[x][y] == 0)
continue;
if (pathmap[x][y] < pathmap[curx][cury])
{
if (min == -1)
min = i;
else
{
if (pathmap[x][y] < pathmap[curx+offset[min][0]][cury+offset[min][1]])
min = i;
}
}
}
assert (min != -1);
m_CurPath.push (PATHELEMENT (curx+offset[min][0],cury+offset[min][1]));
if (((curx+offset[min][0]) == Location().x) && ((cury+offset[min][1]) == Location ().y))
{
done = true;
continue;
}
curx += offset[min][0];
cury += offset[min][1];
}
#endif
return true;
}
/*
bool PATHELEMENT::operator< (const PATHELEMENT& p1) const
{
if (p1.x < x)
return false;
if (x < p1.x)
return true;
if (p1.y < y)
return false;
if (y < p1.y)
return true;
return true;
}
bool PATHELEMENT::operator== (const PATHELEMENT& p1) const
{
if ((p1.x == x) && (p1.y == y))
return true;
return false;
}
*/
#if 0
class CALCELEMENT : public FibHeapNode
{
private:
static FixedHeap<CALCELEMENT> m_EmptyCalcElement;
public:
int x,y;
CALCELEMENT (int nx,int ny) { x = nx; y = ny;}
CALCELEMENT (void) { x = -1; y = -1; }
virtual void operator =(FibHeapNode& RHS);
virtual bool operator ==(FibHeapNode& RHS);
virtual bool operator <(FibHeapNode& RHS);
// static CALCELEMENT *GetBlankElement (void) { return (CALCELEMENT *) m_EmptyCalcElement.Alloc (); }
// static void DoneElement (CALCELEMENT *oldelem) { m_EmptyCalcElement.Free (oldelem); }
// void *operator new (size_t size) {return GetBlankElement (); }
// void operator delete (void *value,size_t size) { DoneElement ((CALCELEMENT *) value); }
};
//FixedHeap<CALCELEMENT> CALCELEMENT::m_EmptyCalcElement(1);
void CALCELEMENT::operator =(FibHeapNode& RHS)
{
CALCELEMENT& fred = (CALCELEMENT&) RHS;
x = fred.x;
y = fred.y;
}
bool CALCELEMENT::operator ==(FibHeapNode& RHS)
{
CALCELEMENT& fred = (CALCELEMENT&) RHS;
if (x != fred.x)
return false;
if (y != fred.y)
return false;
return true;
}
bool CALCELEMENT::operator <(FibHeapNode& RHS)
{
CALCELEMENT& fred = (CALCELEMENT&) RHS;
if (pathmap[x][y] < pathmap[fred.x][fred.y])
return true;
if (pathmap[x][y] > pathmap[fred.x][fred.y])
return false;
if (fred.x < x)
return false;
if (x < fred.x)
return true;
if (fred.y < y)
return false;
if (y < fred.y)
return true;
return true;
}
#endif
@@ -0,0 +1,58 @@
#ifndef __AIFORMATIONHPP__
#define __AIFORMATIONHPP__
/*
struct PATHELEMENT
{
int x,y;
bool operator< (const PATHELEMENT& p1) const;
bool operator== (const PATHELEMENT& p1) const;
PATHELEMENT (int nx,int ny) { x = nx; y = ny; }
PATHELEMENT (void) { x = -1; y = -1; }
};
*/
#include "ai move.hpp"
#include <queue>
#include <stack>
struct FormationData
{
AIMove *member;
int dx,dy;
bool operator< (const FormationData& p1)
{
if (dx < p1.dx)
return true;
if (dy < p1.dy)
return true;
return false;
}
};
class AIFormation
{
private:
CPoint curdes;
bool newdes;
std::queue<FormationData> m_CurrentMembers;
std::stack<PATHELEMENT> m_CurPath;
CPoint m_Location;
bool CalcPath (int depth,bool followshort); // depth = -1 means search until solution
float GetOneCost (int sx,int sy,int dx,int dy); // only to adjecent squares
float PathCostGuess (int sx,int sy,int dx,int dy);
public:
AIFormation (void);
~AIFormation (void);
bool AddAI (AI *newai);
bool AddMove (AIMove *newmove);
bool Think (double value);
void SetDestination (int x,int y);
const CPoint& Location (void) { return m_Location; }
};
#endif
@@ -0,0 +1,313 @@
#pragma warning (disable:4786)
#include "ai.hpp"
FixedHeap<CommandEntry> CommandEntry::m_EmptyCommand(100);
void InitAI (bool firstpass)
{
if (firstpass)
{
return;
}
}
void KillAI (void)
{
}
AI::AI (void)
{
UINT i;
m_Name.Empty ();
m_Awareness = NULL;
m_Combat = NULL;
m_Converse = NULL;
m_Comm = NULL;
m_Location.x = 1;
m_Location.y = 1;
m_LastSort[0] = SORT_PRIORITY;
for (i=1;i<SORT_DEPTH;i++)
{
m_LastSort[i] = SORT_NULL;
}
}
AI::~AI (void)
{
if (m_Awareness)
delete m_Awareness;
if (m_Combat)
delete m_Combat;
if (m_Converse)
delete m_Converse;
if (m_Comm)
delete m_Comm;
if (m_Move)
delete m_Move;
}
bool AI::Think (double value)
{
CommandEntry *temp;
if (m_Awareness)
{
temp = m_Awareness->Think (value,m_AreaLastCommand[AWARE_AREA]);
if (temp)
{
m_AreaLastCommand[AWARE_AREA] = temp;
InsertCommand (temp);
}
}
if (m_Combat)
{
temp = m_Combat->Think (value,m_AreaLastCommand[COMBAT_AREA]);
if (temp)
{
m_AreaLastCommand[COMBAT_AREA] = temp;
InsertCommand (temp);
}
}
if (m_Converse)
{
temp = m_Converse->Think (value,m_AreaLastCommand[CONVERSATION_AREA]);
if (temp)
{
m_AreaLastCommand[CONVERSATION_AREA] = temp;
InsertCommand (temp);
}
}
if (m_Comm)
{
temp = m_Comm->Think (value,m_AreaLastCommand[COMMUNICATION_AREA]);
if (temp)
{
m_AreaLastCommand[COMMUNICATION_AREA] = temp;
InsertCommand (temp);
}
}
if (m_Move)
{
temp = m_Move->Think (value,m_AreaLastCommand[MOVE_AREA]);
if (temp)
{
m_AreaLastCommand[MOVE_AREA] = temp;
InsertCommand (temp);
}
}
ExecuteCommand (GetTopCommand (true));
return true;
}
void AI::SetAreaOrder (const UINT neworder[MAX_AIAREA],bool resort)
{
memcpy (&(m_AreaOrder[0]),&(neworder[0]),sizeof (AIAREA)*MAX_AIAREA);
if (resort)
SortCommandList (m_LastSort);
}
void AI::SortCommandList (const SORTTYPE on[SORT_DEPTH])
{
CommandEntry *temp,*cur;
assert (on[0] != SORT_NULL);
assert (on[SORT_DEPTH-1] == SORT_NULL);
memcpy (&(m_LastSort[0]),&(on[0]),sizeof (SORTTYPE)*SORT_DEPTH);
cur = m_RootCommand;
m_RootCommand = NULL;
m_SortRoot = NULL;
while (cur)
{
temp = cur;
cur = cur->next;
InsertCommand (temp);
}
}
void AI::InsertCommand (CommandEntry *cmd)
{
CommandEntry *level[SORT_DEPTH];
UINT i,here;
bool done;
if (!cmd)
return;
assert (CheckCommandValid (cmd));
assert (m_LastSort[0] != SORT_NULL);
assert (m_LastSort[SORT_DEPTH-1] == SORT_NULL);
cmd->next = m_RootCommand;
cmd->prev = NULL;
if (m_RootCommand)
m_RootCommand->prev = cmd;
m_RootCommand = cmd;
if (m_SortRoot != NULL)
{
level[0] = m_SortRoot;
done = false;
here = 0;
for (i=0;(i<SORT_DEPTH) && (!done);i++)
{
while ((level[i]) && (here != 1) && (!done))
{
here = 0;
if (i != 0)
{
switch (m_LastSort[i-1])
{
case SORT_NULL:
assert (false); // should not continue searching if just did a null sort
break;
case SORT_PRIORITY:
if (level[i]->priority != cmd->priority)
here = 2;
break;
case SORT_VALID:
if (level[i]->validFor != cmd->validFor)
here = 2;
break;
case SORT_AREA:
if (CompareArea (level[i]->from,cmd->from) != 0)
here = 2;
break;
}
}
if ((here != 2) && (level[i]->sort_next == NULL))
here = 2;
else if (here != 2)
{
switch (m_LastSort[i])
{
case SORT_NULL:
here = 2;
case SORT_PRIORITY:
if (level[i]->priority == cmd->priority)
here = 1;
if (level[i]->priority > cmd->priority)
here = 2;
break;
case SORT_VALID:
if (level[i]->validFor == cmd->validFor)
here = 1;
if (level[i]->validFor > cmd->validFor)
here = 2;
break;
case SORT_AREA:
if (CompareArea(level[i]->from,cmd->from) == 0)
here = 1;
if (CompareArea(level[i]->from,cmd->from) > 0)
here = 2;
break;
}
}
switch (here)
{
case 0:
level[i] = level[i]->sort_next;
break;
case 1:
level[i+1] = level[i];
break;
case 2:
if (level[i]->sort_prev)
level[i]->sort_prev->sort_next = cmd;
cmd->sort_prev = level[i]->sort_prev;
cmd->sort_next = level[i];
level[i]->sort_prev = cmd;
if (m_SortRoot = level[i])
m_SortRoot = cmd;
done = true;
break;
}
}
}
}
else
{
m_SortRoot = cmd;
}
}
void AI::RemoveCommand (CommandEntry *cmd)
{
if (!cmd)
return;
if (cmd->next)
cmd->next->prev = cmd->prev;
if (cmd->prev)
cmd->prev->next = cmd->next;
if (m_RootCommand == cmd)
m_RootCommand = cmd->next;
cmd->next = NULL;
cmd->prev = NULL;
if (cmd->sort_next)
cmd->sort_next->sort_prev = cmd->sort_prev;
if (cmd->sort_prev)
cmd->sort_prev->sort_next = cmd->sort_next;
if (m_SortRoot == cmd)
m_SortRoot = cmd->sort_next;
cmd->sort_next = NULL;
cmd->sort_prev = NULL;
for (int i=0;i<MAX_AIAREA;i++)
{
if (m_AreaLastCommand[i] == cmd)
m_AreaLastCommand[i] = NULL;
}
}
void AI::ExecuteCommand (CommandEntry *command)
{
if (!command)
return;
switch (command->commandType)
{
case MOVE_CMD:
m_Location.x = command->commandData.moveData.dx;
m_Location.y = command->commandData.moveData.dy;
break;
case SAY_CMD:
break;
case STANCE_CMD:
break;
case TURN_CMD:
break;
case SEND_CMD:
break;
case PLACEMENT_CMD:
break;
case ATTACK_CMD:
break;
case TRADE_CMD:
break;
case SPECIAL_CMD:
break;
case ADJUST_CMD:
break;
case REMOVE_CMD:
break;
}
RemoveCommand (command);
delete command;
}
#ifdef _DEBUG
bool AI::CheckCommandValid (CommandEntry *cmd)
{
return true;
}
#endif
@@ -0,0 +1,30 @@
#pragma warning (disable:4786)
#include "ai.hpp"
#include "ai know.hpp"
FixedHeap<AIKnowledge> AIKnowledge::m_EmptyKnowledge(100);
AIKnowledge::AIKnowledge (void)
{
id = 0;
distance = 0;
bearing = 0;
curX=0;
curY = 0;
speed = 0;
knowledge = KNOW_BEARING;
threat = IMMEDIATE_THREAT;
validCount = 0;
next = NULL;
prev = NULL;
tnext = NULL;
tprev = NULL;
calcData.temp = 0;
}
AIKnowledge::~AIKnowledge (void)
{
}
@@ -0,0 +1,48 @@
#ifndef __AIKNOWHPP__
#define __AIKNOWHPP__
enum KNOWLEDGE_LEVEL {KNOW_BEARING,KNOW_BEARINGSPEED,KNOW_LOCATION,KNOW_TRUE};
enum THREAT_LEVEL {IMMEDIATE_THREAT,POTENTIAL_THREAT,WARNING_THREAT,OPPORTUNITY_THREAT};
typedef union {
struct {
double bearingOffset;
};
struct {
double temp;
};
} AICalcData;
class AIKnowledge
{
private:
static FixedHeap<AIKnowledge> m_EmptyKnowledge;
protected:
int id;
double distance;
double bearing;
double curX,curY;
double speed;
KNOWLEDGE_LEVEL knowledge;
THREAT_LEVEL threat;
UINT subthreat;
int validCount;
AIKnowledge *next,*prev;
AIKnowledge *tnext,*tprev;
AICalcData calcData;
public:
AIKnowledge (void);
~AIKnowledge (void);
static AIKnowledge *GetBlankKnowledge (void) { return (AIKnowledge *) m_EmptyKnowledge.Alloc (); }
static void DoneKnowledge (AIKnowledge *oldknow) { m_EmptyKnowledge.Free (oldknow); }
void *operator new (size_t size) {return GetBlankKnowledge (); }
void operator delete (void *value,size_t size) { DoneKnowledge ((AIKnowledge *) value); }
};
#endif
+116
View File
@@ -0,0 +1,116 @@
#pragma warning (disable:4786)
#include "ai.hpp"
#include "ai move.hpp"
#include "globals.hpp"
#include <stack>
#include <utils\utils.h>
AIMove::AIMove (AI *parent)
{
m_Parent = parent;
while (!m_CurPath.empty ())
m_CurPath.pop ();
}
AIMove::~AIMove (void)
{
}
bool AIMove::JoinFormation (AIFormation& formation)
{
if (formation.AddMove (this))
{
m_InFormation = true;
return true;
}
return false;
}
CommandEntry *AIMove::Think (double value,CommandEntry *lastcom)
{
CommandEntry *com;
if (newdes)
{
if (lastcom)
{
m_Parent->RemoveCommand (lastcom);
delete lastcom;
}
if (!g_Map[curdes.x][curdes.y].passable)
return NULL;
newdes = false;
if (!CalcPath (&m_CurPath,m_Parent->Location(),curdes,-1,true))
return NULL;
}
if (m_CurPath.empty())
return NULL;
com = new CommandEntry ();
memset (com,0,sizeof (CommandEntry));
com->commandType = MOVE_CMD;
PATHELEMENT temp = m_CurPath.top();
m_CurPath.pop ();
// com->commandData.moveData.dx = temp.x;
// com->commandData.moveData.dy = temp.y;
return com;
}
void AIMove::SetDestination (int x,int y)
{
if ((x == m_Parent->Location().x) && (y == m_Parent->Location().y))
return;
curdes.x = x;
curdes.y = y;
newdes = true;
}
bool AIMove::SetFormationDes (int x,int y)
{
/*
int i,min;
int curx,cury;
const int OFFSIZE = 8;
float cost[OFFSIZE];
int offset[OFFSIZE][2] = {
{-1,-1},
{-1,0},
{-1,1},
{0,-1},
{0,1},
{1,-1},
{1,0},
{1,1}
};
min = 0;
curx = m_Parent->Location().x;
cury = m_Parent->Location().y;
if ((curx == x) && (cury == y))
return true;
for (i=0;i<OFFSIZE;i++)
{
if ((cost[i] = GetOneCost (curx,cury,curx+offset[i][0],cury+offset[i][1])) != -1)
cost[i] += PathCostGuess (curx+offset[i][0],cury+offset[i][1],x,y);
if (cost[min] == -1)
min = i;
else if ((cost[i] != -1) && (cost[i] < cost[min]))
min = i;
}
if (cost[min] == -1)
return false;
while (!m_CurPath.empty())
m_CurPath.pop();
curx = m_Parent->Location().x;
cury = m_Parent->Location().y;
m_CurPath.push (PATHELEMENT (curx+offset[min][0],cury+offset[min][1]));
*/
return true;
}
@@ -0,0 +1,42 @@
#ifndef __AIMOVEHPP__
#define __AIMOVEHPP__
class AIMove;
#include <stack>
#include <utils\utils.h>
#include "map.hpp"
#include "move.hpp"
#include "ai.hpp"
#include "ai formation.hpp"
class AIMove {
friend class AIFormation;
private:
CPoint curdes;
bool newdes;
AI *m_Parent;
std::stack<PATHELEMENT> m_CurPath;
std::stack<PATHELEMENT> m_CellPath;
bool m_InFormation;
// bool CalcPath (int depth,bool followshort); // depth = -1 means search until solution
// float GetOneCost (int sx,int sy,int dx,int dy); // only to adjecent squares
// float PathCostGuess (int sx,int sy,int dx,int dy);
bool SetFormationDes (int x,int y);
public:
AIMove (AI *parent);
~AIMove (void);
virtual CommandEntry *Think (double value,CommandEntry *lastcom); // if need to remove then this func will delete
void SetDestination (int x,int y);
bool JoinFormation (AIFormation& formation);
AI *Parent (void) const { return m_Parent; }
void PathReady (std::stack<PATHELEMENT>& dest);
};
#endif
+258
View File
@@ -0,0 +1,258 @@
#pragma warning (disable:4786)
#include "ai nnet.hpp"
#include <assert.h>
#include <math.h>
Back_Layer::Back_Layer (int nodes,int ninputs,bool first)
{
Create (nodes,ninputs,first);
}
void Back_Layer::Create (int nodes,int ninputs,bool first)
{
int i,j;
double temp;
next = NULL;
prev = NULL;
num_nodes = nodes;
next = prev = NULL;
thenodes = (Back_Node *) calloc (sizeof (Back_Node),num_nodes);
num_inputs = ninputs;
inputs = (double *) calloc (sizeof (double),num_inputs);
outputs = (double *) calloc (sizeof (double),num_nodes);
errors = (double *) calloc (sizeof (double),num_nodes);
for (i=0;i<num_inputs;i++)
{ inputs[i] = 0;
}
for (i=0;i<num_nodes;i++)
{
thenodes[i].weights = (double *) calloc (sizeof (double),num_inputs);
thenodes[i].deltas = (double *) calloc (sizeof (double),num_inputs);
for (j=0;j<num_inputs;j++)
{
thenodes[i].deltas[j] = 0.0;
if (!first)
{
temp = rand ();
temp /= ((double) RAND_MAX);
temp = temp - 0.5;
thenodes[i].weights[j] = temp;
}
else
{
thenodes[i].weights[j] = 1.0;
}
}
}
}
Back_Layer::~Back_Layer (void)
{
Destroy ();
}
void Back_Layer::Destroy (void)
{
int i;
for (i=0;i<num_nodes;i++)
{
free (thenodes[i].weights);
free (thenodes[i].deltas);
}
free (thenodes);
free (inputs);
free (errors);
}
void Back_Layer::propagate_forward (void)
{
int i,j;
double sum;
assert ((!next) || (num_nodes == next->num_inputs));
for (i=0;i<num_nodes;i++)
{
if (!prev)
outputs[i] = inputs[i];
else
{
sum = 0.0;
for (j=0;j<num_inputs;j++)
{ sum += (inputs[j]*thenodes[i].weights[j]);
}
outputs[i] = 1.0/(1.0+exp (-1.0*sum));
}
if (next)
next->inputs[i] = outputs[i];
}
}
void Back_Layer::propagate_error (void)
{
int i,j;
assert (next);
for (i=0;i<num_nodes;i++)
{
errors[i] = 0;
for (j=0;j<next->num_nodes;j++)
{
errors[i] += (next->errors[j]*next->thenodes[j].weights[i]);
}
errors[i] *= (outputs[i] * (1.0-outputs[i]));
}
}
void Back_Network::correct (bool finetune)
{
compute_error (finetune);
propagate_error ();
adjust_weights ();
}
void Back_Network::adjust_weights (void)
{
int i,j,k;
double tochange;
for (i=1;i<num_layers;i++)
{
for (j=0;j<thelayers[i].num_nodes;j++)
{
for (k=0;k<thelayers[i].num_inputs;k++)
{
tochange = thelayers[i].inputs[k]*eta*thelayers[i].errors[j];
tochange += (alpha*thelayers[i].thenodes[j].deltas[k]);
thelayers[i].thenodes[j].deltas[k] = tochange;
thelayers[i].thenodes[j].weights[k] += tochange;
}
}
}
}
void Back_Network::propagate_error (void)
{
int i;
for (i=(num_layers-2);i>=0;i--)
{
thelayers[i].propagate_error ();
}
}
void Back_Network::compute_error (bool finetune)
{
int i;
for (i=0;i<num_outputs;i++)
{
if (!finetune)
thelayers[num_layers-1].errors[i] = (wanted_output[i] - output[i]);
else
{
thelayers[num_layers-1].errors[i] = output[i];
thelayers[num_layers-1].errors[i] *= (1.0 - output[i]);
thelayers[num_layers-1].errors[i] *= (wanted_output[i] - output[i]);
}
}
}
// This function does not work, the net will not stabalize to a solution
void Back_Network::Learn (bool iscorrect,bool finetune,double error)
{
int i;
double *temp;
if (iscorrect)
{
temp = get_answer ();
for (i=0;i<thelayers[num_layers-1].num_nodes;i++)
{
if (temp[i] > 0.5)
wanted_output[i] = 1.0;
else
wanted_output[i] = 0.0;
}
correct (finetune);
}
else
{
temp = get_answer ();
for (i=0;i<thelayers[num_layers-1].num_nodes;i++)
{
if ((rand ()%100) < error)
{
if (temp[i] > 0.5)
wanted_output[i] = 1.0;
else
wanted_output[i] = 0.0;
}
else
{
if ((rand ()&0x01))
wanted_output[i] = 1.0;
else
wanted_output[i] = 0.0;
}
}
correct (finetune);
}
}
Back_Network::Back_Network (int layers,int *num_nodes,double neta,double nalpha)
{
int i;
eta = neta;
alpha = nalpha;
num_inputs = num_nodes[0];
num_outputs = num_nodes[layers-1];
input = (double *) calloc (sizeof (double),num_inputs);
output = (double *) calloc (sizeof (double),num_outputs);
wanted_output = (double *) calloc (sizeof (double),num_outputs);
num_layers = layers;
thelayers = (Back_Layer *) calloc (sizeof (Back_Layer),layers);
thelayers[0].Create (num_nodes[0],num_nodes[0],true);
thelayers[0].next = &(thelayers[1]);
for (i=1;i<layers;i++)
{
thelayers[i].Create (num_nodes[i],num_nodes[i-1],false);
thelayers[i].prev = &(thelayers[i-1]);
thelayers[i].next = &(thelayers[i+1]);
}
thelayers[layers-1].next = NULL;
}
Back_Network::~Back_Network (void)
{
int i;
for (i=0;i<num_layers;i++)
{
thelayers[i].Destroy ();
}
free (thelayers);
}
void Back_Network::propagate_forward (double *ninputs)
{
int i;
for (i=0;i<num_inputs;i++)
{
input[i] = ninputs[i];
thelayers[0].inputs[i] = input[i];
}
for (i=0;i<num_layers;i++)
{
if (i != (num_layers-1))
assert (thelayers[i].num_nodes == thelayers[i+1].num_inputs);
thelayers[i].propagate_forward ();
}
for (i=0;i<num_outputs;i++)
{
output[i] = thelayers[num_layers-1].outputs[i];
}
}
@@ -0,0 +1,58 @@
#ifndef __AINNETHPP__
#define __AINNETHPP__
#include <windows.h>
typedef struct {
double *weights; // size is num_inputs
double *deltas; // size is num_inputs
} Back_Node;
class Back_Layer
{
public:
Back_Layer *next,*prev;
Back_Node *thenodes;
int num_nodes;
int num_inputs; // this should equal number of nodes from lower layer
double *inputs;
double *outputs;
double *errors;
Back_Layer (int nodes,int inputs,bool first);
~Back_Layer (void);
void Create (int nodes,int inputs,bool first);
void Destroy (void);
void propagate_forward (void);
void propagate_error (void);
};
class Back_Network
{
public:
Back_Layer *thelayers;
int num_layers;
double *input;
double *output;
double *wanted_output;
double eta,alpha;
int num_outputs,num_inputs;
Back_Network (int layers,int *num_nodes,double neta,double nalpha);
~Back_Network (void);
void propagate_forward (double *inputs);
// This function does not work, the net will not stabalize to a solution
void Learn (bool iscorrect,bool finetune = false,double percent = 0);
void correct (bool finetune = false);
void compute_error (bool finetune);
void propagate_error (void);
void adjust_weights (void);
double *get_answer (void) { return thelayers[num_layers-1].outputs;}
double *get_wanted (void) { return wanted_output;}
};
#endif
+14
View File
@@ -0,0 +1,14 @@
#include "ai.hpp"
AINPC::AINPC (AI *parent)
{
}
AINPC::~AINPC (void)
{
}
CommandEntry *AINPC::Think (double value,CommandEntry *lastcom)
{
return NULL;
}
+12
View File
@@ -0,0 +1,12 @@
#ifndef __AINPCHPP__
#define __AINPCHPP__
class AINPC {
public:
AINPC (AI *parent);
~AINPC (void);
virtual CommandEntry *Think (double value,CommandEntry *lastcom); // if need to remove then delete
};
#endif
@@ -0,0 +1,5 @@
#ifndef __AIPRIORITYHPP__
#define __AIPRIORITYHPP__
#endif
@@ -0,0 +1,22 @@
#pragma warning (disable:4786)
#include "ai state.hpp"
AIStateTable::AIStateTable (void)
{
m_Root = NULL;
m_CurrentState = NULL;
}
AIStateTable::~AIStateTable (void)
{
while (m_Root)
{
StateEntry *temp;
temp = m_Root;
m_Root = m_Root->next;
delete temp;
}
m_CurrentState = NULL;
}
+139
View File
@@ -0,0 +1,139 @@
#ifndef __AISTATEHPP__
#define __AISTATEHPP__
#include <windows.h>
#include "ai event.hpp"
enum STATETYPE {MOVE_STATE,SLEEP_STATE,GUARD_STATE,WANDER_STATE,EAT_STATE,PLAY_STATE,READ_STATE,
WAIT_STATE,TALK_STATE,SELL_STATE,BUY_STATE,ATTACK_STATE,DANCE_STATE,TAICHI_STATE,
FIGHT_STATE,WORK_STATE,PROTECT_STATE};
#define LASTMOVESIZE 10
typedef struct {
double destX;
double destY;
double speed;
} MoveStateData;
typedef struct {
bool snore;
} SleepStateData;
typedef struct {
bool burp;
} EatStateData;
typedef struct {
double guardPointX[2];
double guardPointY[2];
double speed;
int militancy;
double lookX;
double lookY;
} GuardStateData;
typedef struct {
double left;
double top;
double right;
double bottom;
double speed;
} WanderStateData;
typedef struct {
double left;
double top;
double right;
double bottom;
} PlayStateData;
typedef struct {
UINT readWhat;
} ReadStateData;
typedef struct {
UINT action;
} WaitStateData;
typedef struct {
UINT with;
} TalkStateData;
typedef struct {
UINT what;
} SellStateData;
typedef struct {
UINT what;
} BuyStateData;
typedef struct {
UINT how;
} AttackStateData;
typedef struct {
UINT form;
UINT with;
} DanceStateData;
typedef struct {
UINT form;
UINT with;
} TaichiStateData;
typedef struct {
UINT form;
UINT with;
} FightStateData;
typedef struct {
UINT job;
} WorkStateData;
typedef struct {
UINT job;
} ProtectStateData;
typedef union {
MoveStateData moveData;
SleepStateData sleepData;
GuardStateData guardData;
WanderStateData wanderData;
EatStateData eatData;
PlayStateData playData;
ReadStateData readData;
WaitStateData waitData;
TalkStateData talkData;
SellStateData sellData;
BuyStateData buyData;
AttackStateData attackData;
DanceStateData danceData;
TaichiStateData taichiData;
FightStateData fightData;
WorkStateData workData;
ProtectStateData protectData;
} StateDataUnion;
typedef struct StateEntry{
int stateID;
STATETYPE stateType;
StateDataUnion stateData;
EventEntry *events;
StateEntry *next,*prev;
} StateEntry;
class AIStateTable
{
friend class AI;
private:
StateEntry *m_Root;
StateEntry *m_CurrentState;
public:
AIStateTable (void);
~AIStateTable (void);
};
#endif
@@ -0,0 +1,118 @@
#pragma warning (disable:4786)
#include "ai test.hpp"
#include "ai test wnd.hpp"
CAITestWindow::CAITestWindow (void)
{
m_MouseDown = false;
}
CAITestWindow::~CAITestWindow (void)
{
}
void CAITestWindow::Render (HDC thedc,LPPAINTSTRUCT data)
{
int i;
CDIBSurface& surf = GetSurface ();
surf.Blt (0,0,surf.GetWidth(),surf.GetHeight(),&m_Map,0,0);
for (i=0;i<MAXPERSON;i++)
{
const CPoint& fred = g_Person[i].Location ();
surf.Fill (fred.x*DRAWCELLSIZE,fred.y*DRAWCELLSIZE,(fred.x+1)*DRAWCELLSIZE,(fred.y+1)*DRAWCELLSIZE,RGB (255,0,0));
}
// RenderEdges (surf,0);
// g_MapTree->RenderData (surf,256*DRAWCELLSIZE+2);
CDIBWindow::Render (thedc,data);
}
void CAITestWindow::InitialUpdate(void)
{
int x,y;
m_Map.Create (MAPSIZE*DRAWCELLSIZE,MAPSIZE*DRAWCELLSIZE,16);
for (y=0;y<MAPSIZE;y++)
{
for (x=0;x<MAPSIZE;x++)
{
int color = 255.0 * ((g_Map[x][y].weight/5.0)-1.0);
// if (g_Map[x][y].passable)
{
m_Map.Fill (x*DRAWCELLSIZE,y*DRAWCELLSIZE,(x+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE,RGB (color,color,color));
}
// else
{
// m_Map.Fill (x*DRAWCELLSIZE,y*DRAWCELLSIZE,(x+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE,RGB (color,0,0));
}
/*
if (g_Map[x][y].passable)
{
m_Map.Fill (x*DRAWCELLSIZE,y*DRAWCELLSIZE,(x+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE,0);
}
else
{
m_Map.Fill (x*DRAWCELLSIZE,y*DRAWCELLSIZE,(x+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE,RGB (255,255,255));
}
*/
}
}
}
void CAITestWindow::LButtonDown (int x,int y)
{
x/=DRAWCELLSIZE;
y/=DRAWCELLSIZE;
g_Person[0].SetDestination (x,y);
}
void CAITestWindow::RButtonDown (int x,int y)
{
m_MouseDown = true;
if (g_Map[x>>2][y>>2].passable)
m_Adding = false;
else
m_Adding = true;
MouseMove (x,y);
}
void CAITestWindow::LButtonUp (int x,int y)
{
}
void CAITestWindow::RButtonUp (int x,int y)
{
x/=DRAWCELLSIZE;
y/=DRAWCELLSIZE;
m_MouseDown = false;
}
void CAITestWindow::MouseMove (int x,int y)
{
if (!m_MouseDown)
return;
x/=DRAWCELLSIZE;
y/=DRAWCELLSIZE;
g_Map[x][y].passable = m_Adding;
if (g_Map[x][y].passable)
{
m_Map.Fill (x*DRAWCELLSIZE,y*DRAWCELLSIZE,(x+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE,0);
}
else
{
m_Map.Fill (x*DRAWCELLSIZE,y*DRAWCELLSIZE,(x+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE,RGB (255,255,255));
}
InvalidateRect (Window(),&CRect (x*DRAWCELLSIZE,y*DRAWCELLSIZE,(x+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE),false);
}
LRESULT CAITestWindow::WndProc (HWND thewnd,UINT themsg,WPARAM wParam,LPARAM lParam)
{
switch (themsg)
{
case WM_CLOSE:
PostQuitMessage (0);
break;
}
return CDIBWindow::WndProc (thewnd,themsg,wParam,lParam);
}
@@ -0,0 +1,27 @@
#ifndef __AITESTWNDHPP__
#define __AITESTWNDHPP__
#include "windows.hpp"
class CAITestWindow : public CDIBWindow
{
private:
CDIBSurface m_Map;
bool m_Adding;
bool m_MouseDown;
public:
CAITestWindow (void);
~CAITestWindow (void);
virtual void Render (HDC thedc,LPPAINTSTRUCT data = NULL);
virtual void InitialUpdate(void);
virtual void LButtonDown (int x,int y);
virtual void RButtonDown (int x,int y);
virtual void LButtonUp (int x,int y);
virtual void RButtonUp (int x,int y);
virtual void MouseMove (int x,int y);
virtual LRESULT WndProc (HWND thewnd,UINT themsg,WPARAM wParam,LPARAM lParam);
};
#endif
@@ -0,0 +1,35 @@
#ifndef __STARHPP__
#define __STARHPP__
#include "ai.hpp"
class CPerson;
#include "map.hpp"
class CPerson : public AI
{
public:
CPerson (void);
~CPerson (void);
void DoTick (void);
void SetDestination (int x,int y);
};
#include <utils\utils.h>
//#include <table.hpp>
#include <dib surface\dibsection.hpp>
#include <file system\file system.hpp>
//#include <database.hpp>
using namespace std;
#include "windows.hpp"
#include "menuwnd.hpp"
#include "ai test wnd.hpp"
#include "prototype.hpp"
#include "globals.hpp"
#endif
+100
View File
@@ -0,0 +1,100 @@
#ifndef __AIHPP__
#define __AIHPP__
#pragma warning (disable:4291)
#include <windows.h>
#include <utils\utils.h>
class AI;
enum AIAREA { COMBAT_AREA, BARGAIN_AREA, CONVERSATION_AREA,
COMMUNICATION_AREA, AWARE_AREA, PLAYER_AREA, MOVE_AREA, MAX_AIAREA};
#include "ai command.hpp"
#include "ai nnet.hpp"
#include "ai priority.hpp"
#include "ai aware.hpp"
#include "ai combat.hpp"
#include "ai comm.hpp"
#include "ai conversation.hpp"
#include "ai move.hpp"
#define SORT_DEPTH 4
void InitAI (bool firstpass);
void KillAI (void);
class AI
{
friend class AIAwareness;
friend class AICombat;
friend class AIConverse;
friend class AIComm;
friend class AIMove;
protected:
enum SORTTYPE {SORT_NULL,SORT_PRIORITY,SORT_VALID,SORT_AREA};
private:
CommandEntry *m_RootCommand,*m_SortRoot;
SORTTYPE m_LastSort[SORT_DEPTH];
UINT m_AreaOrder[MAX_AIAREA];
#ifdef _DEBUG
bool CheckCommandValid (CommandEntry *cmd);
#else
bool CheckCommandValid (CommandEntry *cmd) {return true;}
#endif
protected:
CPoint m_Location;
CString m_Name;
AIAwareness *m_Awareness;
AICombat *m_Combat;
AIConverse *m_Converse;
AIComm *m_Comm;
AIMove *m_Move;
CommandEntry *m_AreaLastCommand[MAX_AIAREA];
void SetAreaOrder (const UINT neworder[MAX_AIAREA],bool resort = true);
int CompareArea (AIAREA c1,AIAREA c2) const
{
return m_AreaOrder[c1] - m_AreaOrder[c2];
}
void SortCommandList (const SORTTYPE on[SORT_DEPTH]);
void InsertCommand (CommandEntry *cmd);
CommandEntry *GetTopCommand (bool sorted=false) const
{
return sorted ? m_SortRoot : m_RootCommand;
}
void RemoveCommand (CommandEntry *cmd);
CommandEntry *GetNextCommand (CommandEntry *cmd,bool sorted=false) const
{
assert (cmd);
if (sorted)
return cmd->sort_next;
return cmd->next;
}
void ExecuteCommand (CommandEntry *command);
public:
AI (void);
~AI (void);
bool Think (double value);
const CPoint& Location (void) { return m_Location; }
AIAwareness *Awareness (void) { return m_Awareness; }
AICombat *Combat (void) { return m_Combat; }
AIConverse *Converse (void) { return m_Converse; }
AIComm *Comm (void) { return m_Comm; }
AIMove *Move (void) { return m_Move; }
};
#endif
@@ -0,0 +1,27 @@
#ifndef __AIHICOMHPP__
#define __AIHICOMHPP__
namespace AI
{
enum HIGH_LEVEL_COMMANDS {
PATROL_HIGH,
MOVE_HIGH,
DEFEND_HIGH,
ESCORT_HIGH,
ATTACK_HIGH,
CAPTURE_HIGH,
TELEPORT_HIGH,
FLEE_HIGH,
STARTUP_HIGH,
SHUTDOWN_HIGH,
ENDMISSION_HIGH,
EJECT_HIGH,
FORM_HIGH,
HOLDFIRE_HIGH,
FOLLOW_HIGH,
SETPROP_HIGH
}
}
#endif
@@ -0,0 +1,90 @@
#pragma warning (disable:4786)
#include "test.hpp"
#include "airailpath.hpp"
my_vector<int> fred;
my_vector<CRailLink *> fred1;
my_vector<CRailLink> fred2;
using namespace std;
CRailNode::CRailNode (CPoint loc)
{
m_Location = loc;
}
CRailNode::~CRailNode (void)
{
}
CRailGraph::CRailGraph (void)
{
m_Nodes.clear ();
m_Links.clear ();
}
CRailGraph::~CRailGraph (void)
{
vector<CRailLink *>::iterator iter1;
map<int,CRailNode *>::iterator iter2;
iter1 = m_Links.begin ();
while (iter1 != m_Links.end ())
{
delete (*iter1);
(*iter1) = NULL;
iter1++;
}
iter2 = m_Nodes.begin ();
while (iter2 != m_Nodes.end ())
{
delete (*iter2).second;
(*iter2).second = NULL;
iter2++;
}
}
void CRailGraph::AddNode (CRailNode *node,int id)
{
assert (m_Nodes.find (id) == m_Nodes.end ());
m_Nodes[id] = node;
}
void CRailGraph::AddLink (CRailLink *link)
{
m_Links.push_back (link);
}
float CRailGraph::Connect (CRailNode *src,CRailNode *dest) const
{
vector<CRailLink *>::const_iterator iter;
iter = m_Links.begin ();
while (iter != m_Links.end ())
{
if (((*iter)->Location(0) == dest) && ((*iter)->Location(1) == src))
return (*iter)->Weight ();
else if (((*iter)->Location(0) == src) && ((*iter)->Location(1) == dest))
return (*iter)->Weight ();
else
iter++;
}
return 0.0;
}
CRailPath::CRailPath (CPoint start,CPoint end)
{
m_Start = start;
m_End = end;
m_CurrentLink = 0;
}
CRailPath::~CRailPath (void)
{
m_Links.clear ();
}
void CRailPath::CalcPath (void)
{
}
@@ -0,0 +1,109 @@
#ifndef __AIRAILPATHHPP__
#define __AIRAILPATHHPP__
#pragma warning (disable:4786)
#include "utils\utils.h"
#include <vector>
#include <map>
class CRailNode;
class CRailLink
{
private:
CRailNode *m_Loc[2];
float m_Weight;
bool m_Jump;
public:
CRailLink (void)
{
m_Loc[0] = m_Loc[1] = NULL;
m_Weight = 0;
m_Jump = false;
}
CRailLink (CRailNode *loc1,CRailNode *loc2,float nweight,bool njump = false)
{
m_Loc[0] = loc1;
m_Loc[1] = loc2;
m_Weight = nweight;
m_Jump = njump;
}
float Weight (void) const
{ return m_Weight; }
bool Jump (void) const
{ return m_Jump; }
const CRailNode *Location (int id) const
{
assert ((id>=0) && (id<=1));
return m_Loc[id];
}
};
class CRailNode
{
private:
CPoint m_Location;
public:
CRailNode (CPoint loc);
~CRailNode (void);
CPoint Location (void) const
{ return m_Location; }
};
class CRailGraph
{
private:
std::map<int,CRailNode *> m_Nodes;
std::vector<CRailLink *> m_Links;
public:
CRailGraph (void);
~CRailGraph (void);
void AddNode (CRailNode *node,int id);
void AddLink (CRailLink *link);
void AddLink (int n1,int n2,float weight,bool jump=false)
{
assert (m_Nodes.find (n1) != m_Nodes.end ());
assert (m_Nodes.find (n2) != m_Nodes.end ());
AddLink (new CRailLink (m_Nodes[n1],m_Nodes[n2],weight,jump));
}
float Connect (CRailNode *src,CRailNode *dest) const;
};
class CRailPath
{
private:
CPoint m_Start;
CPoint m_End;
int m_CurrentLink;
std::vector<CRailLink *> m_Links;
public:
CRailPath (CPoint start,CPoint end);
~CRailPath (void);
void CalcPath (void);
const CRailLink *CurrentLink (void) const
{
assert (m_CurrentLink >= 0);
assert (m_CurrentLink < m_Links.size ());
return m_Links[m_CurrentLink];
}
bool NextLink (void) // true if path still exists
{
m_CurrentLink++;
return m_CurrentLink != m_Links.size ();
}
};
#endif
@@ -0,0 +1,44 @@
#pragma warning (disable:4786)
#define INITGUID
#define GLOBAL_EXTERN
#include "ai test.hpp"
void InitGlobals (void)
{
int i;
g_MainWindow = NULL;
g_Quitting = false;
g_Registry = NULL;
for (i=0;i<MAXPERSON;i++)
{
g_Person[i].SetDestination (i+1,i+1);
g_Person[i].Move ()->JoinFormation (g_Formation);
}
g_Graph.AddNode (new CRailNode(CPoint (15,60)),0);
g_Graph.AddNode (new CRailNode(CPoint (10,10)),1);
g_Graph.AddNode (new CRailNode(CPoint (20,10)),2);
g_Graph.AddNode (new CRailNode(CPoint (10,20)),3);
g_Graph.AddNode (new CRailNode(CPoint (20,20)),4);
g_Graph.AddNode (new CRailNode(CPoint (30,40)),5);
g_Graph.AddNode (new CRailNode(CPoint (10,50)),6);
g_Graph.AddNode (new CRailNode(CPoint (20,50)),7);
g_Graph.AddLink (1,3,5);
g_Graph.AddLink (1,4,6);
g_Graph.AddLink (2,4,10);
g_Graph.AddLink (3,4,3);
g_Graph.AddLink (3,6,4);
g_Graph.AddLink (4,5,30);
g_Graph.AddLink (4,6,1);
g_Graph.AddLink (4,7,7);
g_Graph.AddLink (6,0,5);
g_Graph.AddLink (7,0,9);
}
void KillGlobals (void)
{
}
@@ -0,0 +1,42 @@
#ifndef __GLOBALSHPP__
#define __GLOBALSHPP__
#pragma warning (disable:4786)
#include "windows.hpp"
#pragma warning (disable:4786)
#include "ai test.hpp"
#pragma warning (disable:4786)
#include "ai test wnd.hpp"
#pragma warning (disable:4786)
#include "airailpath.hpp"
#pragma warning (disable:4786)
#ifndef GLOBAL_EXTERN
#define GLOBAL_EXTERN extern
#endif
const int MAXPERSON = 1;
const int c_nDefaultRenderingHeight = 480; // default width of direct draw surface
const int c_nDefaultRenderingWidth = 640; // default height of direct draw surface
const int c_nDefaultRenderingBitsPerPixel = 16; // bits per pixel of direct draw surface
const DWORD c_dwWindowedStyle = WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_BORDER;
const DWORD c_dwWindowedStyleEx =0;
const CString WINDOW_NAME("AI Test");
const CString WINDOW_CLASS_NAME("AITESTWINDOWCLASS");
GLOBAL_EXTERN HINSTANCE g_hInstance;
GLOBAL_EXTERN CString g_szTitle;
GLOBAL_EXTERN CString g_szClassName;
GLOBAL_EXTERN bool g_Quitting;
GLOBAL_EXTERN CRegistry *g_Registry;
GLOBAL_EXTERN CAITestWindow *g_MainWindow;
GLOBAL_EXTERN CPerson g_Person[MAXPERSON];
GLOBAL_EXTERN AIFormation g_Formation;
GLOBAL_EXTERN CRailGraph g_Graph;
#endif
+47
View File
@@ -0,0 +1,47 @@
#pragma warning (disable:4786)
#include "ai test.hpp"
void DoTick (void);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
g_hInstance = hInstance;
InitGlobals ();
InitSystem ();
try // start our message processing, when there is now message waiting
{ // to our GameTick routine
MSG msg;
BOOL flag=TRUE;
while (flag)
{
if (PeekMessage (&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
flag = FALSE;
TranslateMessage (&msg);
DispatchMessage (&msg);
}
else
{
DoTick ();
}
}
g_Quitting = true;
KillSystem ();
if (g_Registry)
g_Registry->SaveData (); // tell the registery to save itself since we have normal exit
}
catch (exception except) // we had an exception so kill everything
{
cerr << except.what ();
KillSystem ();
KillGlobals ();
return 1;
}
return 0;
}
+867
View File
@@ -0,0 +1,867 @@
#pragma warning (disable:4786)
#include <utils\utils.h>
#include "map.hpp"
#include "move.hpp"
MAPELEMENT g_Map[MAPSIZE][MAPSIZE];
void GenMap (MAPELEMENT map[MAPSIZE][MAPSIZE],int x1,int y1,int x2,int y2);
void InitMap (void)
{
int x,y;
for (y=0;y<MAPSIZE;y++)
for (x=0;x<MAPSIZE;x++)
{
g_Map[x][y].passable = true;
g_Map[x][y].weight = 0.0;
}
for (y=0;y<MAPSIZE;y++)
{
g_Map[0][y].passable = false;
g_Map[MAPSIZE-1][y].passable = false;
}
for (x=0;x<MAPSIZE;x++)
{
g_Map[x][0].passable = false;
g_Map[x][MAPSIZE-1].passable = false;
}
g_Map[0][0].weight = 0.5f;
g_Map[MAPSIZE-1][0].weight = 0.5f;
g_Map[0][MAPSIZE-1].weight = 0.5f;
g_Map[MAPSIZE-1][MAPSIZE-1].weight = 0.5f;
GenMap (g_Map,0,0,MAPSIZE-1,MAPSIZE-1);
for (y=0;y<MAPSIZE;y++)
for (x=0;x<MAPSIZE;x++)
{
if (g_Map[x][y].weight > 0.75)
g_Map[x][y].passable = false;
g_Map[x][y].weight+=1.0;
g_Map[x][y].weight *= 5.0;
}
InitMoveData ();
}
void RenderEdges (CDIBSurface& dest,int dx)
{
int x,y;
for (y=0;y<MAPCELLCOUNT;y++)
for (x=0;x<MAPCELLCOUNT;x++)
{
g_MapCells[x][y].RenderEdges (dest,dx);
}
}
int SquareInfo (int x,int y)
{
return Passable (x,y);
}
void GenMap (MAPELEMENT map[MAPSIZE][MAPSIZE],int x1,int y1,int x2,int y2)
{
int midx,midy;
double v1,v2,v3,v4;
double rmax;
if (x2 <= x1)
return;
if (y2 <= y1)
return;
midx = (x1+x2)/2;
midy = (y1+y2)/2;
rmax = RAND_MAX;
if (map[midx][y1].weight == 0.0)
{
v1 = map[midx][y1].weight = ((map[x1][y1].weight + map[x2][y1].weight) / 2.0) + (((rand()/rmax)-0.5)*((x2-x1)/MAPX));
if (v1<0)
map[midx][y1].weight = 0;
if (v1 > 1.0)
map[midx][y1].weight = 1.0;
}
else v1 = map[midx][y1].weight;
if (map[midx][y2].weight ==0.0)
{
v2 = map[midx][y2].weight = ((map[x1][y2].weight + map[x2][y2].weight) / 2.0) + (((rand()/rmax)-0.5)*((x2-x1)/MAPX));
if (v2<0)
map[midx][y2].weight = 0;
if (v2 > 1.0)
map[midx][y2].weight = 1.0;
}
else v2 = map[midx][y2].weight;
if (map[x1][midy].weight == 0.0)
{
v3 = map[x1][midy].weight = ((map[x1][y1].weight + map[x1][y2].weight) / 2.0) + (((rand()/rmax)-0.5)*((y1-y2)/MAPY));
if (v3<0)
map[x1][midy].weight = 0;
if (v3 > 1.0)
map[x1][midy].weight = 1.0;
}
else v3 = map[x1][midy].weight;
if (map[x2][midy].weight == 0.0)
{
v4 = map[x2][midy].weight = ((map[x2][y1].weight + map[x2][y2].weight) / 2.0) + (((rand()/rmax)-0.5)*((y1-y2)/MAPY));
if (v4<0)
map[x2][midy].weight = 0;
if (v4 > 1.0)
map[x2][midy].weight = 1.0;
}
else v4 = map[x2][midy].weight;
if (map[midx][midy].weight == 0.0)
{
map[midx][midy].weight = ((v1+v2+v3+v4)/4.0) + 2*(((rand()/rmax)-0.5)*((y1-y2)/MAPY));
if (map[midx][midy].weight<0)
map[midx][midy].weight = 0;
if (map[midx][midy].weight > 1.0)
map[midx][midy].weight = 1.0;
}
/*
if (midx == x1)
return;
if (midx == x2)
return;
if (midy == y1)
return;
if (midy == y2)
return;
*/
if ((midx != x2) && (midx != x1))
{
GenMap (map,x1,y1,midx,midy);
GenMap (map,midx,y1,x2,midy);
}
if ((midy != y1) && (midy != y2))
{
GenMap (map,x1,midy,midx,y2);
GenMap (map,midx,midy,x2,y2);
}
}
/*
float GetOneCost (int sx,int sy,int dx,int dy)
{
int deltax,deltay;
float toret;
if (!Passable (dx,dy))
return -1;
toret = abs (g_Map[sx][sy].weight - g_Map[dx][dy].weight)+1;
// toret *= 0.5;
return toret;
deltax = dx - sx;
deltay = dy - sy;
if (deltax == 0)
return toret*0.5;
if (deltay == 0)
return toret*0.5;
return toret * 0.75;
}
*/
/*
CMapNode::CMapNode (void)
{
m_Left = NULL;
m_Right = NULL;
m_Bottom = NULL;
m_Top = NULL;
int i;
for (i=0;i<PASS_NUM;i++)
{
m_Passable[i] = true;
}
m_PassAverage = 0;
m_WeightAverage = 0;
m_MapQuad = NULL;
m_MapQuad = new CMapQuadNode (NULL,this);
m_MapQuad->Left (0);
m_MapQuad->Top (0);
m_MapQuad->Right (MAPSIZE-1);
m_MapQuad->Bottom (MAPSIZE-1);
m_MapQuad->SubDivide ();
}
CMapNode::~CMapNode (void)
{
delete m_Left;
delete m_Right;
delete m_Bottom;
delete m_Top;
}
void CMapNode::RenderData (CDIBSurface& dest,int dx)
{
m_MapQuad->RenderData (dest,dx);
}
void CMapNode::RenderEdges (CDIBSurface& dest,int dx)
{
m_MapQuad->RenderEdges (dest,dx);
}
CMapQuadNode::CMapQuadNode (CMapQuadNode *parent,CMapNode *root)
{
m_Root = root;
m_Parent = parent;
m_Left = m_Right = m_Bottom = m_Top = 0;
m_Child[0] = NULL;
m_Child[1] = NULL;
m_Child[2] = NULL;
m_Child[3] = NULL;
int i;
for (i=0;i<PASS_NUM;i++)
{
m_Passable[i] = true;
}
m_PassAverage = 0;
m_WeightAverage = 0;
}
CMapQuadNode::~CMapQuadNode (void)
{
}
void CMapQuadNode::RenderData (CDIBSurface& dest,int dx)
{
const int CELLSIZE=2;
if (m_Child[0])
{
m_Child[0]->RenderData (dest,dx);
m_Child[1]->RenderData (dest,dx);
m_Child[2]->RenderData (dest,dx);
m_Child[3]->RenderData (dest,dx);
}
else
{
int color = 255.0 * ((m_WeightAverage/5.0)-1.0);
dest.Fill (dx+m_Left*CELLSIZE,m_Top*CELLSIZE,dx+(m_Right+1)*CELLSIZE,(m_Bottom+1)*CELLSIZE,RGB (color,color,color));
}
}
void CMapQuadNode::RenderEdges (CDIBSurface& dest,int dx)
{
const int CELLSIZE=2;
if (m_Child[0])
{
m_Child[0]->RenderEdges (dest,dx);
m_Child[1]->RenderEdges (dest,dx);
m_Child[2]->RenderEdges (dest,dx);
m_Child[3]->RenderEdges (dest,dx);
}
else
{
int x,y;
for (x=m_Left;x<m_Right;x++)
{
dest.Fill (dx+x*CELLSIZE,m_Top*CELLSIZE,dx+(x+1)*CELLSIZE,(m_Top+1)*CELLSIZE,RGB (0,255,0));
// dest.Fill (x*CELLSIZE,m_Bottom*CELLSIZE,(x+1)*CELLSIZE,(m_Bottom+1)*CELLSIZE,RGB (0,255,0));
}
for (y=m_Top;y<m_Bottom;y++)
{
dest.Fill (dx+m_Left*CELLSIZE,y*CELLSIZE,dx+(m_Left+1)*CELLSIZE,(y+1)*CELLSIZE,RGB (0,255,0));
// dest.Fill (m_Right*CELLSIZE,y*CELLSIZE,(m_Right+1)*CELLSIZE,(y+1)*CELLSIZE,RGB (0,255,0));
}
}
}
bool CMapQuadNode::SubDivide (void)
{
int midx,midy,count;
bool flag;
flag = true;
if ((m_Right-m_Left)<=MAXDEPTH)
flag = false;
if ((m_Bottom-m_Top)<=MAXDEPTH)
flag = false;
assert (m_Left>=0);
assert (m_Top>=0);
assert (m_Right <=MAPSIZE);
assert (m_Bottom <= MAPSIZE);
assert (m_Left < m_Right);
assert (m_Bottom > m_Top);
midy = (m_Bottom-m_Top+1)/2;
midx = (m_Right-m_Left+1)/2;
if (flag)
{
m_Child[0] = new CMapQuadNode (this,m_Root);
m_Child[1] = new CMapQuadNode (this,m_Root);
m_Child[2] = new CMapQuadNode (this,m_Root);
m_Child[3] = new CMapQuadNode (this,m_Root);
m_Child[TOPLEFT_CHILD]->SetSize (m_Left,m_Top,m_Left+midx,m_Top+midy);
m_Child[BOTTOMLEFT_CHILD]->SetSize (m_Left,m_Top+midy+1,m_Left+midx,m_Bottom);
m_Child[TOPRIGHT_CHILD]->SetSize (m_Left+midx+1,m_Top,m_Right,m_Top+midy);
m_Child[BOTTOMRIGHT_CHILD]->SetSize (m_Left+midx+1,m_Top+midy+1,m_Right,m_Bottom);
m_Child[0]->SubDivide ();
m_Child[1]->SubDivide ();
m_Child[2]->SubDivide ();
m_Child[3]->SubDivide ();
}
else
{
m_Child[0] = NULL;
m_Child[1] = NULL;
m_Child[2] = NULL;
m_Child[3] = NULL;
}
m_PassAverage = 0;
m_WeightAverage = 0;
count = 0;
for (midx = m_Left;midx<=m_Right;midx++)
{
for (midy=m_Top;midy<=m_Bottom;midy++)
{
count++;
m_WeightAverage+=g_Map[midx][midy].weight;
if (g_Map[midx][midy].passable)
{
m_PassAverage++;
}
}
}
m_PassAverage /= count;
m_WeightAverage /= count;
return true;
}
*/
#if 0
double CMapQuadNode::CalcAverageCostSplit (int where,bool left )
{
int x,y,z;
int lx,hx,ly,hy;
double current;
int count;
assert (where < (m_LeftSplit?m_Bottom:m_Right));
assert (where > (m_LeftSplit?m_Top:m_Left));
assert (m_Left>=0);
assert (m_Top>=0);
assert (m_Right <=MAPSIZE);
assert (m_Bottom <= MAPSIZE);
assert (m_Left < m_Right);
assert (m_Bottom > m_Top);
if (m_LeftSplit)
{
lx = m_Left;
hx = m_Right;
if (left)
{
ly = m_Top;
hy = m_Top+where;
}
else
{
ly = m_Top+where+1;
hy = m_Bottom;
}
}
else
{
ly = m_Top;
hy = m_Bottom;
if (left)
{
lx = m_Left;
hx = m_Left+where;
}
else
{
lx = m_Left+where+1;
hx = m_Right;
}
}
count = 0;
current = 0.0;
for (x=lx;x<=hx;x++)
{
for (y=ly;y<=hy;y++)
{
for (z=0;z<OFFSIZE;z++)
{
double cost;
cost = g_MapTree->GetOneCost (x,y,x+offset[z][0],y+offset[z][1]);
if (cost < 0)
cost = 10000.0;
current+=cost;
count++;
}
}
}
return current / ((double)count);
}
double CMapQuadNode::AnalyzeSplit (int where,bool left)
{
double average;
int x,y,z;
int lx,hx,ly,hy;
double current;
int count;
assert (where < (m_LeftSplit?m_Bottom:m_Right));
assert (where > (m_LeftSplit?m_Top:m_Left));
assert (m_Left>=0);
assert (m_Top>=0);
assert (m_Right <=MAPSIZE);
assert (m_Bottom <= MAPSIZE);
assert (m_Left < m_Right);
assert (m_Bottom > m_Top);
average = CalcAverageCostSplit (where,left);
if (m_LeftSplit)
{
lx = m_Left;
hx = m_Right;
if (left)
{
ly = m_Top;
hy = m_Top+where;
}
else
{
ly = m_Top+where+1;
hy = m_Bottom;
}
}
else
{
ly = m_Top;
hy = m_Bottom;
if (left)
{
lx = m_Left;
hx = m_Left+where;
}
else
{
lx = m_Left+where+1;
hx = m_Right;
}
}
count = 0;
current = 0.0;
for (x=lx;x<=hx;x++)
{
for (y=ly;y<=hy;y++)
{
for (z=0;z<OFFSIZE;z++)
{
double cost = g_MapTree->GetOneCost (x,y,x+offset[z][0],y+offset[z][1]);
if (cost < 0)
cost = 10000.0;
current+= ((cost-average) * (cost-average));
count++;
}
}
}
return current / ((double)count);
}
int CMapQuadNode::ChooseSplit (void)
{
int mid,min;
double minvalue;
double temp;
double splits[MAPSIZE][2];
double cost[MAPSIZE];
assert (m_Left>=0);
assert (m_Top>=0);
assert (m_Right <=MAPSIZE);
assert (m_Bottom <= MAPSIZE);
assert (m_Left < m_Right);
assert (m_Bottom > m_Top);
for (mid = 0;mid<MAPSIZE;mid++)
{
splits[mid][0] = 0.0;
splits[mid][1] = 0.0;
}
min = -1;
minvalue = DBL_MAX;
if (m_LeftSplit)
{
for (mid = (m_Top+MAXDEPTH4);mid<=(m_Bottom-MAXDEPTH4);mid++)
{
splits[mid][0] = AnalyzeSplit (mid,0);
splits[mid][1] = AnalyzeSplit (mid,1);
cost[mid] = splits[mid][0] + splits[mid][1];
temp = ((double)(mid-m_Top)/(double) (m_Bottom - m_Top));
temp *= PI;
// temp -= (PI/2.0);
temp = sin(temp);
temp = 1.0 - temp;
cost[mid] *= temp;
if (cost[mid] < minvalue)
{
min = mid;
minvalue = cost[mid];
}
}
}
else
{
for (mid = (m_Left+MAXDEPTH4);mid<=(m_Right-MAXDEPTH4);mid++)
{
splits[mid][0] = AnalyzeSplit (mid,0);
splits[mid][1] = AnalyzeSplit (mid,1);
cost[mid] = splits[mid][0] + splits[mid][1];
temp = ((double)(mid-m_Left)/(double) (m_Right - m_Left));
temp *= PI;
// temp -= (PI/2.0);
temp = sin(temp);
temp = 1.0 - temp;
cost[mid] *= temp;
// temp = (((mid-m_Left)/(m_Right - m_Left)) * PI)-(PI/2.0);
// temp = 1.0 - sin (temp);
cost[mid] *= temp;
if (cost[mid] < minvalue)
{
min = mid;
minvalue = cost[mid];
}
}
}
if (min < 0)
{
if (m_LeftSplit)
mid = (m_Bottom-m_Top+1)/2;
else
mid = (m_Right-m_Left+1)/2;
}
else
mid = min;
assert (mid < (m_LeftSplit?m_Bottom:m_Right));
assert (mid > (m_LeftSplit?m_Top:m_Left));
return mid;
}
bool CMapNode::CalcPath (std::stack<PATHELEMENT> *dest,CPoint start,CPoint end,int depth,bool followshort)
{
int i,j;
FibHeap calc;
CALCELEMENT *temp;
CALCELEMENT *shortdes = NULL;
int lastdepth;
int x=-1,y=-1;
bool done;
while (!dest->empty ())
dest->pop ();
for (i=0;i<MAPSIZE;i++)
{
for (j=0;j<MAPSIZE;j++)
{
pathmap[i][j] = 0;
}
}
temp = new CALCELEMENT (start.x,start.y);
pathmap[start.x][start.y] = 1;
calc.Insert (temp);
done = false;
lastdepth = 0;
while (!done && ((depth == -1)||(depth<lastdepth)))
{
temp = (CALCELEMENT *) calc.ExtractMin ();
if (temp == NULL)
break;
lastdepth = pathmap[temp->x][temp->y];
for (i=0;i<OFFSIZE;i++)
{
x = offset[i][0] + temp->x;
y = offset[i][1] + temp->y;
float cost = GetOneCost (temp->x,temp->y,x,y);
if (cost == -1)
continue;
cost += PathCostGuess (x,y,end.x,end.y);
if ((pathmap[x][y] == 0) || (pathmap[x][y] > (pathmap[temp->x][temp->y]+cost)))
{
pathmap[x][y] = pathmap[temp->x][temp->y]+cost;
calc.Insert (new CALCELEMENT(x,y));
}
if ((x == end.x) && (y == end.y))
{
done = true;
break;
}
}
delete temp;
}
if ((!done) && (depth != -1) && (depth>=lastdepth) && followshort)
{
shortdes = (CALCELEMENT *) calc.ExtractMin ();
if (shortdes)
done = true;
}
while (temp = (CALCELEMENT *) calc.ExtractMin ())
delete temp;
if (!done)
return false;
done = false;
int curx,cury,min;
if (shortdes)
{
curx = shortdes->x;
cury = shortdes->y;
delete shortdes;
}
else
{
curx = end.x;
cury = end.y;
}
dest->push (PATHELEMENT (curx,cury));
min = -1;
while (!done)
{
min = -1;
assert (pathmap[curx][cury] != 0);
for (i=0;i<OFFSIZE;i++)
{
x = offset[i][0] + curx;
y = offset[i][1] + cury;
if (x < 0)
continue;
if (x >= MAPSIZE)
continue;
if (y < 0)
continue;
if (y >= MAPSIZE)
continue;
if (pathmap[x][y] == 0)
continue;
if (pathmap[x][y] < pathmap[curx][cury])
{
if (min == -1)
min = i;
else
{
if (pathmap[x][y] < pathmap[curx+offset[min][0]][cury+offset[min][1]])
min = i;
}
}
}
assert (min != -1);
dest->push (PATHELEMENT (curx+offset[min][0],cury+offset[min][1]));
if (((curx+offset[min][0]) == start.x) && ((cury+offset[min][1]) == start.y))
{
done = true;
continue;
}
curx += offset[min][0];
cury += offset[min][1];
}
// m_CurPath.push (PATHELEMENT (curdes.x,curdes.y));
return true;
}
#endif
#if 0
int i,j;
FibHeap calc;
CALCELEMENT *temp;
CALCELEMENT *shortdes = NULL;
int lastdepth;
int x=-1,y=-1;
bool done;
while (!dest->empty ())
dest->pop ();
for (i=0;i<MAPSIZE;i++)
{
for (j=0;j<MAPSIZE;j++)
{
pathmap[i][j] = 0;
}
}
temp = new CALCELEMENT (start.x,start.y);
pathmap[start.x][start.y] = 1;
calc.Insert (temp);
done = false;
lastdepth = 0;
while (!done && ((depth == -1)||(depth<lastdepth)))
{
temp = (CALCELEMENT *) calc.ExtractMin ();
if (temp == NULL)
break;
lastdepth = pathmap[temp->x][temp->y];
for (i=0;i<OFFSIZE;i++)
{
x = offset[i][0] + temp->x;
y = offset[i][1] + temp->y;
float cost = GetOneCost (temp->x,temp->y,x,y);
if (cost == -1)
continue;
cost += PathCostGuess (x,y,end.x,end.y);
if ((pathmap[x][y] == 0) || (pathmap[x][y] > (pathmap[temp->x][temp->y]+cost)))
{
pathmap[x][y] = pathmap[temp->x][temp->y]+cost;
calc.Insert (new CALCELEMENT(x,y));
}
if ((x == end.x) && (y == end.y))
{
done = true;
break;
}
}
delete temp;
}
if ((!done) && (depth != -1) && (depth>=lastdepth) && followshort)
{
shortdes = (CALCELEMENT *) calc.ExtractMin ();
if (shortdes)
done = true;
}
while (temp = (CALCELEMENT *) calc.ExtractMin ())
delete temp;
if (!done)
return false;
done = false;
int curx,cury,min;
if (shortdes)
{
curx = shortdes->x;
cury = shortdes->y;
delete shortdes;
}
else
{
curx = end.x;
cury = end.y;
}
dest->push (PATHELEMENT (curx,cury));
min = -1;
while (!done)
{
min = -1;
assert (pathmap[curx][cury] != 0);
for (i=0;i<OFFSIZE;i++)
{
x = offset[i][0] + curx;
y = offset[i][1] + cury;
if (x < 0)
continue;
if (x >= MAPSIZE)
continue;
if (y < 0)
continue;
if (y >= MAPSIZE)
continue;
if (pathmap[x][y] == 0)
continue;
if (pathmap[x][y] < pathmap[curx][cury])
{
if (min == -1)
min = i;
else
{
if (pathmap[x][y] < pathmap[curx+offset[min][0]][cury+offset[min][1]])
min = i;
}
}
}
assert (min != -1);
dest->push (PATHELEMENT (curx+offset[min][0],cury+offset[min][1]));
if (((curx+offset[min][0]) == start.x) && ((cury+offset[min][1]) == start.y))
{
done = true;
continue;
}
curx += offset[min][0];
cury += offset[min][1];
}
// m_CurPath.push (PATHELEMENT (curdes.x,curdes.y));
return true;
#endif
+142
View File
@@ -0,0 +1,142 @@
#ifndef __MAPHPP__
#define __MAPHPP__
#include "dib surface\dibsection.hpp"
class CPerson;
class CMapNode;
class CMapQuadNode;
struct MAPELEMENT
{
bool passable;
float weight;
};
int SquareInfo (int x,int y);
void RenderEdges (CDIBSurface& dest,int dx);
const double MAPX = 256.0;
const double MAPY = 256.0;
const int MAPSIZE = 256;
const int MAXDEPTH = 16;
const int MAXDEPTH2 = (MAXDEPTH/2);
const int MAXDEPTH4 = (MAXDEPTH/4);
extern MAPELEMENT g_Map[MAPSIZE][MAPSIZE];
extern CMapNode *g_MapTree;
inline bool Passable (int dx,int dy)
{
if (dx < 0)
return false;
if (dy < 0)
return false;
if (dx >= MAPSIZE)
return false;
if (dy >= MAPSIZE)
return false;
if (!g_Map[dx][dy].passable)
return false;
/*
for (i=0;i<MAXPERSON;i++)
{
if (who == &g_Person[i])
continue;
if ((dx == g_Person[i].Location().x) && (dy == g_Person[i].Location().y))
return false;
}
*/
return true;
}
/*
enum PASSFLAG {PASS_TB,PASS_LR,PASS_TL,PASS_TR,PASS_BL,PASS_BR,PASS_NUM};
class CMapQuadNode
{
friend class CMapNode;
private:
// enum SPLITID {LEFT_CHILD=0,RIGHT_CHILD,TOP_CHILD=0,BOTTOM_CHILD};
enum SPLITID {TOPLEFT_CHILD,TOPRIGHT_CHILD,BOTTOMLEFT_CHILD,BOTTOMRIGHT_CHILD};
CMapQuadNode *m_Parent;
CMapNode *m_Root;
// CMapQuadNode *m_Child[2];
CMapQuadNode *m_Child[4];
int m_Left,m_Right,m_Bottom,m_Top;
// bool m_LeftSplit; // true is left to right split, which means child are top bottom
bool m_Passable[PASS_NUM];
float m_PassAverage;
float m_WeightAverage;
// int ChooseSplit (void);
// double CalcAverageCostSplit (int where,bool left);
// double AnalyzeSplit (int where,bool left);
bool SubDivide (void);
void RenderEdges (CDIBSurface& dest,int dx);
void RenderData (CDIBSurface& dest,int dx);
void Left (int value) { m_Left = value; }
void Right (int value) { m_Right = value; }
void Top (int value) { m_Top = value; }
void Bottom (int value) { m_Bottom = value; }
void SetSize (int left,int top,int right,int bottom)
{
m_Left = left;
m_Top = top;
m_Right = right;
m_Bottom = bottom;
}
public:
CMapQuadNode (CMapQuadNode *parent,CMapNode *root);
~CMapQuadNode (void);
int Left (void) const { return m_Left; }
int Right (void) const { return m_Right; }
int Top (void) const { return m_Top; }
int Bottom (void) const { return m_Bottom; }
};
class CMapNode
{
private:
CMapNode *m_Left,*m_Top,*m_Right,*m_Bottom;
CMapQuadNode *m_MapQuad;
bool m_Passable[PASS_NUM];
float m_PassAverage;
float m_WeightAverage;
public:
CMapNode (void);
~CMapNode (void);
void RenderEdges (CDIBSurface& dest,int dx);
void RenderData (CDIBSurface& dest,int dx);
float GetOneCost (int sx,int sy,int dx,int dy);
float PathCostGuess (int sx,int sy,int dx,int dy);
};
*/
#endif
+93
View File
@@ -0,0 +1,93 @@
#pragma warning (disable:4786)
#include <utils\utils.h>
#include "map.hpp"
#include "move.hpp"
#include "movezone.hpp"
#include "movecell.hpp"
bool CalcPath (std::stack<PATHELEMENT> *dest,CPoint rstart,CPoint rend,int depth,bool followshort)
{
std::stack<PATHCELLELEMENT> one;
std::stack<PATHZONEELEMENT> zone;
CPoint curpoint;
CalcPathZone (&zone,rstart,rend);
curpoint = rstart;
while (!zone.empty ())
{
if (zone.size ()==1)
{
CCellPath *path;
CPoint start,end;
const PATHZONEELEMENT& temp = zone.top ();
start.x = temp.sx;
start.y = temp.sy;
path = new CCellPath (curpoint,start,temp.sarea,temp.darea,temp.dir);
path->CalcPath ();
dest->push (PATHELEMENT (temp,path));
curpoint = path->EndPoint ();
start.x = temp.dx;
start.y = temp.dy;
path = new CCellPath (curpoint,start,rend);
path->CalcPath ();
dest->push ((PATHELEMENT (PATHZONEELEMENT (start.x,start.y,start.x,start.y,0,0,-1),path)));
zone.pop ();
}
else
{
CCellPath *path;
CPoint start;
const PATHZONEELEMENT& temp = zone.top ();
start.x = temp.sx;
start.y = temp.sy;
path = new CCellPath (curpoint,start,temp.sarea,temp.darea,temp.dir);
path->CalcPath ();
dest->push (PATHELEMENT (temp,path));
zone.pop ();
curpoint = path->EndPoint ();
}
}
return true;
}
void DoPathTick (void)
{
}
void InitMoveData (void)
{
InitMoveCellData ();
InitMoveZoneData ();
}
#if 0
bool PATHELEMENT::operator< (const PATHELEMENT& p1) const
{
if (p1.x < x)
return false;
if (x < p1.x)
return true;
if (p1.y < y)
return false;
if (y < p1.y)
return true;
return true;
}
bool PATHELEMENT::operator== (const PATHELEMENT& p1) const
{
if ((p1.x == x) && (p1.y == y))
return true;
return false;
}
#endif
+69
View File
@@ -0,0 +1,69 @@
#ifndef __MOVEHPP__
#define __MOVEHPP__
#include <stack>
#include <queue>
#include "movezone.hpp"
#include "movecell.hpp"
struct PATHELEMENT
{
PATHZONEELEMENT cell;
CCellPath *cellpath;
PATHELEMENT (const PATHZONEELEMENT& ncell,CCellPath *npath) {cell = ncell;cellpath = npath;}
// ~PATHELEMENT (void)
// { delete cellpath; cellpath = NULL; }
};
void DoPathTick (void);
bool CalcPath (std::stack<PATHELEMENT> *dest,CPoint start,CPoint end,int depth,bool followshort);
void InitMoveData (void);
struct PATHQUEUEELEMENT
{
int sx,sy;
int dx,dy;
CPerson *who;
bool cell;
PATHQUEUEELEMENT (void)
{
sx = sy = dx = dy = -1;
cell = false;
who = NULL;
}
PATHQUEUEELEMENT (int p1,int p2,int p3,int p4,CPerson *p5,bool p6)
{
sx = p1;
sy = p2;
dx = p3;
dy = p4;
who = p5;
cell = p6;
}
~PATHQUEUEELEMENT (void)
{
sx = sy = dx = dy = -1;
who = NULL;
}
void operator= (PATHQUEUEELEMENT& rhs)
{
sx = rhs.sx;
sy = rhs.sy;
dx = rhs.dx;
dy = rhs.dy;
who = rhs.who;
cell = rhs.cell;
}
};
extern std::queue<PATHQUEUEELEMENT> g_PathQueue;
#endif
+311
View File
@@ -0,0 +1,311 @@
#pragma warning (disable:4786)
#include <utils\utils.h>
#include "map.hpp"
#include "move.hpp"
#include "movecell.hpp"
float pathmapcell[MAPCELLSIZE][MAPCELLSIZE];
FixedHeap<CALCCELLELEMENT> CALCCELLELEMENT::m_EmptyCalcCellElement(1);
void InitMoveCellData (void)
{
}
void CALCCELLELEMENT::operator =(FibHeapNode& RHS)
{
CALCCELLELEMENT& fred = (CALCCELLELEMENT&) RHS;
x = fred.x;
y = fred.y;
}
bool CALCCELLELEMENT::operator ==(FibHeapNode& RHS)
{
CALCCELLELEMENT& fred = (CALCCELLELEMENT&) RHS;
if (x != fred.x)
return false;
if (y != fred.y)
return false;
return true;
}
bool CALCCELLELEMENT::operator <(FibHeapNode& RHS)
{
CALCCELLELEMENT& fred = (CALCCELLELEMENT&) RHS;
if (pathmapcell[x][y] < pathmapcell[fred.x][fred.y])
return true;
if (pathmapcell[x][y] > pathmapcell[fred.x][fred.y])
return false;
if (fred.x < x)
return false;
if (x < fred.x)
return true;
if (fred.y < y)
return false;
if (y < fred.y)
return true;
return true;
}
float CCellPath::GetOneCost (int sx,int sy,int dx,int dy)
{
float toret;
if (dx<0)
return -1;
if (dy<0)
return -1;
if (dx>=MAPCELLSIZE)
return -1;
if (dy>=MAPCELLSIZE)
return -1;
sx += g_MapCells[m_Cell.x][m_Cell.y].Left ();
dx += g_MapCells[m_Cell.x][m_Cell.y].Left ();
sy += g_MapCells[m_Cell.x][m_Cell.y].Top ();
dy += g_MapCells[m_Cell.x][m_Cell.y].Top ();
if (!Passable (dx,dy))
return -1;
toret = abs (g_Map[sx][sy].weight - g_Map[dx][dy].weight)+1;
// toret *= 0.5;
return toret;
/*
int deltax,deltay;
deltax = dx - sx;
deltay = dy - sy;
if (deltax == 0)
return toret*0.5;
if (deltay == 0)
return toret*0.5;
return toret * 0.75;
*/
}
float CCellPath::PathCostGuess (int sx,int sy,int dx,int dy)
{
int t1,t2;
t1 = dx - sx;
t2 = dy - dx;
__asm
{
mov eax,t1
cdq
xor eax,edx
sub eax,edx
mov t1,eax
mov eax,t2
cdq
xor eax,edx
sub eax,edx
mov t2,eax
}
// return t1+t2;
return t2 < t1 ? (t1+(t2>>1)) : (t2+(t1>>1));
}
CCellPath::CCellPath (CPoint start,CPoint cell,CPoint end)
{
assert (start.x>=0);
assert (start.x<MAPCELLSIZE);
assert (start.y>=0);
assert (start.y<MAPCELLSIZE);
m_Start = start;
m_Start.x -= g_MapCells[cell.x][cell.y].Left ();
m_Start.y -= g_MapCells[cell.x][cell.y].Top ();
end.x -= g_MapCells[cell.x][cell.y].Left ();
end.y -= g_MapCells[cell.x][cell.y].Top ();
m_Cell = cell;
m_StartArea = g_MapCells[cell.x][cell.y].AreaLocal (start.x,start.y);
m_EndArea = g_MapCells[cell.x][cell.y].AreaLocal (end.x,end.y);
m_End.push_back (end);
m_EndAreaOther = 0;
}
CCellPath::CCellPath (CPoint start,CPoint cell,int endarea,int endareaother,int edge)
{
int x,y;
int dcx,dcy;
assert (start.x>=0);
assert (start.x<MAPCELLSIZE);
assert (start.y>=0);
assert (start.y<MAPCELLSIZE);
m_Start = start;
m_Start.x -= g_MapCells[cell.x][cell.y].Left ();
m_Start.y -= g_MapCells[cell.x][cell.y].Top ();
m_Cell = cell;
m_StartArea = g_MapCells[cell.x][cell.y].AreaLocal (start.x,start.y);
assert (endareaother != 0);
m_EndAreaOther = endareaother;
dcx = cell.x;
dcy = cell.y;
switch (edge)
{
case LEFTEDGE:
dcx--;
assert (dcx>=0);
for (y=0;y<MAPCELLSIZE;y++)
if ((g_MapCells[cell.x][cell.y].AreaLocal (0,y) == endarea) && (g_MapCells[dcx][dcy].AreaLocal (MAPCELLSIZE-1,y)==endareaother))
m_End.push_back (CPoint (0,y));
break;
case TOPEDGE:
dcy--;
assert (dcy>=0);
for (x=0;x<MAPCELLSIZE;x++)
if ((g_MapCells[cell.x][cell.y].AreaLocal (x,0) == endarea) && (g_MapCells[dcx][dcy].AreaLocal (x,MAPCELLSIZE-1)==endareaother))
m_End.push_back (CPoint (x,0));
break;
case RIGHTEDGE:
dcx++;
assert (dcx<MAPCELLCOUNT);
for (y=0;y<MAPCELLSIZE;y++)
if ((g_MapCells[cell.x][cell.y].AreaLocal (MAPCELLSIZE-1,y) == endarea) && (g_MapCells[dcx][dcy].AreaLocal (0,y)==endareaother))
m_End.push_back (CPoint (MAPCELLSIZE-1,y));
break;
case BOTTOMEDGE:
dcy++;
assert (dcy<MAPCELLCOUNT);
for (x=0;x<MAPCELLSIZE;x++)
if ((g_MapCells[cell.x][cell.y].AreaLocal (x,MAPCELLSIZE-1) == endarea) && (g_MapCells[dcx][dcy].AreaLocal (x,0)==endareaother))
m_End.push_back (CPoint (x,MAPCELLSIZE-1));
break;
default:
assert (false);
}
}
CCellPath::~CCellPath (void)
{
while (!m_Path.empty ())
m_Path.pop ();
}
bool CCellPath::CalcPath (void)
{
int i,j;
CPoint end;
FibHeap calc;
CALCCELLELEMENT *temp;
int x=-1,y=-1;
bool done;
while (!m_Path.empty ())
m_Path.pop ();
for (i=0;i<MAPCELLSIZE;i++)
for (j=0;j<MAPCELLSIZE;j++)
pathmapcell[i][j] = 0;
temp = new CALCCELLELEMENT (m_Start.x,m_Start.y);
pathmapcell[m_Start.x][m_Start.y] = 1;
calc.Insert (temp);
done = false;
while (!done)
{
temp = (CALCCELLELEMENT *) calc.ExtractMin ();
if (temp == NULL)
break;
for (i=0;i<OFFSIZECELL;i++)
{
x = offsetcell[i][0] + temp->x;
y = offsetcell[i][1] + temp->y;
float cost = GetOneCost (temp->x,temp->y,x,y);
if (cost == -1)
continue;
cost += PathCostGuess (x,y,m_End[0].x,m_End[0].y);
if ((pathmapcell[x][y] == 0) || (pathmapcell[x][y] > (pathmapcell[temp->x][temp->y]+cost)))
{
pathmapcell[x][y] = pathmapcell[temp->x][temp->y]+cost;
calc.Insert (new CALCCELLELEMENT(x,y));
}
if (ValidEnd (x,y))
{
end = CPoint (x,y);
done = true;
break;
}
}
delete temp;
}
while (temp = (CALCCELLELEMENT *) calc.ExtractMin ())
delete temp;
if (!done)
return false;
done = false;
int curx,cury,min;
curx = end.x;
cury = end.y;
m_RealEnd = end;
m_Path.push (PATHCELLELEMENT (curx,cury));
min = -1;
while (!done)
{
min = -1;
assert (pathmapcell[curx][cury] != 0);
for (i=0;i<OFFSIZECELL;i++)
{
x = offsetcell[i][0] + curx;
y = offsetcell[i][1] + cury;
if (x < 0)
continue;
if (x >= MAPCELLSIZE)
continue;
if (y < 0)
continue;
if (y >= MAPCELLSIZE)
continue;
if (pathmapcell[x][y] == 0)
continue;
if (pathmapcell[x][y] < pathmapcell[curx][cury])
{
if (min == -1)
min = i;
else
{
if (pathmapcell[x][y] < pathmapcell[curx+offsetcell[min][0]][cury+offsetcell[min][1]])
min = i;
}
}
}
assert (min != -1);
m_Path.push (PATHCELLELEMENT (curx+offsetcell[min][0],cury+offsetcell[min][1]));
if (((curx+offsetcell[min][0]) == m_Start.x) && ((cury+offsetcell[min][1]) == m_Start.y))
{
// m_RealEnd.x = curx+offsetcell[min][0];
// m_RealEnd.y = cury+offsetcell[min][1];
done = true;
continue;
}
curx += offsetcell[min][0];
cury += offsetcell[min][1];
}
return true;
}
+114
View File
@@ -0,0 +1,114 @@
#ifndef __MOVECELLHPP__
#define __MOVECELLHPP__
#include <stack>
#include <queue>
struct PATHCELLELEMENT
{
int x,y;
bool operator< (const PATHCELLELEMENT& p1) const;
bool operator== (const PATHCELLELEMENT& p1) const;
PATHCELLELEMENT (int nx,int ny) { x = nx; y = ny;}
PATHCELLELEMENT (void) { x = -1; y = -1; }
};
const int OFFSIZECELL = 8;
const int offsetcell[OFFSIZECELL][2] = {
{-1,-1},
{-1,0},
{-1,1},
{0,-1},
{0,1},
{1,-1},
{1,0},
{1,1}
};
class CALCCELLELEMENT : public FibHeapNode
{
private:
static FixedHeap<CALCCELLELEMENT> m_EmptyCalcCellElement;
public:
int x,y;
CALCCELLELEMENT (int nx,int ny) { x = nx; y = ny;}
CALCCELLELEMENT (void) { x = -1; y = -1; }
virtual void operator =(FibHeapNode& RHS);
virtual bool operator ==(FibHeapNode& RHS);
virtual bool operator <(FibHeapNode& RHS);
// static CALCELEMENT *GetBlankElement (void) { return (CALCELEMENT *) m_EmptyCalcElement.Alloc (); }
// static void DoneElement (CALCELEMENT *oldelem) { m_EmptyCalcElement.Free (oldelem); }
// void *operator new (size_t size) {return GetBlankElement (); }
// void operator delete (void *value,size_t size) { DoneElement ((CALCELEMENT *) value); }
};
class CCellPath
{
private:
std::stack<PATHCELLELEMENT> m_Path;
CPoint m_Start; // in local coordinates for start point, has to be within the cell
std::vector<CPoint> m_End; // in local coordinates for the end point, has to be within the cell, vector for edge valid cells
CPoint m_RealEnd;
int m_StartArea; // areaid for the start point in the cell list
int m_EndArea; // areaid for the end point in the cell list
int m_EndAreaOther; // the areaid for the next cell in the move list, if zero this is the last cell in the list
CPoint m_Cell; // what cell this path is within
bool ValidEnd (const CPoint& where)
{
std::vector<CPoint>::iterator iter;
iter = m_End.begin ();
while (iter != m_End.end ())
{
if ((*iter) == where)
return true;
iter++;
}
return false;
}
bool ValidEnd (int wx,int wy)
{ return ValidEnd (CPoint (wx,wy)); }
float GetOneCost (int sx,int sy,int dx,int dy);
float PathCostGuess (int sx,int sy,int dx,int dy);
public:
CCellPath (CPoint start,CPoint cell,int endarea,int endareaother,int edge); // for edge to edge movement, or inside to edge movement start is in global coordinates
CCellPath (CPoint start,CPoint cell,CPoint end); // for edge to inside movement // start and end are global coordinates
~CCellPath (void);
bool CalcPath (void);
CPoint StartPoint (void) const
{ return m_Start; }
CPoint EndPoint (void) const
{ return m_RealEnd; }
int StartArea (void) const
{ return m_StartArea; }
int EndArea (void) const
{ return m_EndArea; }
int EndAreaOther (void) const
{ return m_EndAreaOther; }
void operator =(const CCellPath& RHS)
{
m_Path = RHS.m_Path;
m_Start = RHS.m_Start;
m_End = RHS.m_End;
m_RealEnd = RHS.m_RealEnd;
m_StartArea = RHS.m_StartArea;
m_EndArea = RHS.m_EndArea;
m_EndAreaOther = RHS.m_EndAreaOther;
m_Cell = RHS.m_Cell;
}
};
void InitMoveCellData (void);
#endif
+727
View File
@@ -0,0 +1,727 @@
#pragma warning (disable:4786)
#include <utils\utils.h>
#include "map.hpp"
#include "move.hpp"
#include "movezone.hpp"
#include <map>
CMapCell g_MapCells[MAPCELLCOUNT][MAPCELLCOUNT];
std::map<int,float> pathmapzone[MAPCELLCOUNT][MAPCELLCOUNT][2]; // index is for the topleft cell of each src,dest pair the 2 is for the offset table-2
bool SetWeight (int sx,int sy,int offset,int areaentry,int areaexit,float newweight)
{
int ix,iy,io;
int index;
int temp;
std::map<int,float>::iterator iter;
ix = sx;
iy = sy;
io = offset;
switch (offsetzone[offset][2])
{
case 0:
ix--;
temp = areaentry;
areaentry = areaexit;
areaexit = temp;
break;
case 1:
iy--;
temp = areaentry;
areaentry = areaexit;
areaexit = temp;
break;
case 2:
io-=2;
break;
case 3:
io-=2;
break;
}
assert (ix>=0);
assert (ix<MAPCELLCOUNT);
assert (iy>=0);
assert (iy<MAPCELLCOUNT);
assert (io>=0);
assert (io<2);
index = areaentry<<4;
index += areaexit;
iter = pathmapzone[ix][iy][io].find (index);
if (iter == pathmapzone[ix][iy][io].end ())
{
pathmapzone[ix][iy][io][index] = newweight;
return true;
}
if ((*iter).second > newweight)
{
pathmapzone[ix][iy][io][index] = newweight;
return true;
}
return false;
}
float GetWeight (int sx,int sy,int dx,int dy,int areaentry,int areaexit)
{
if (abs (sx-dx))
{
if (sx > dx)
return GetWeight (sx,sy,0,areaentry,areaexit);
else
return GetWeight (sx,sy,2,areaentry,areaexit);
}
else if (abs(sy-dy))
{
if (sy > dy)
return GetWeight (sx,sy,1,areaentry,areaexit);
else
return GetWeight (sx,sy,3,areaentry,areaexit);
}
assert (false);
return -1.0;
}
float GetWeight (int sx,int sy,int offset,int areaentry,int areaexit)
{
int ix,iy,io;
int index;
int temp;
std::map<int,float>::iterator iter;
ix = sx;
iy = sy;
io = offset;
switch (offsetzone[offset][2])
{
case 0:
ix--;
temp = areaentry;
areaentry = areaexit;
areaexit = temp;
break;
case 1:
iy--;
temp = areaentry;
areaentry = areaexit;
areaexit = temp;
break;
case 2:
io-=2;
break;
case 3:
io-=2;
break;
}
if (ix<0)
return -1;
if (ix>=MAPCELLCOUNT)
return -1;
if (iy<0)
return -1;
if (iy>=MAPCELLCOUNT)
return -1;
assert (io>=0);
assert (io<2);
index = areaentry<<4;
index += areaexit;
iter = pathmapzone[ix][iy][io].find (index);
if (iter == pathmapzone[ix][iy][io].end ())
{
return -1.0;
}
return (*iter).second;
}
void InitMoveZoneData (void)
{
int curx,cury;
int x,y;
for (y=0,cury = 0;y<MAPCELLCOUNT;y++,cury+=(MAPCELLSIZE-1))
for (x=0,curx=0;x<MAPCELLCOUNT;x++,curx+=(MAPCELLSIZE-1))
{
int left,right,top,bottom;
left = clamp<int> (0,curx,MAPSIZE-1);
right = clamp<int> (0,left+MAPCELLSIZE-1,MAPSIZE-1);
top = clamp<int> (0,cury,MAPSIZE-1);
bottom = clamp<int> (0,top+MAPCELLSIZE-1,MAPSIZE-1);
g_MapCells[x][y].SetSize (left,top,right,bottom);
}
for (y=0;y<MAPCELLCOUNT;y++)
for (x=0;x<MAPCELLCOUNT;x++)
{
g_MapCells[x][y].CalcWeight ();
g_MapCells[x][y].CalcInterior ();
g_MapCells[x][y].CalcEdges ();
}
}
CMapCell::CMapCell (void)
{
m_WeightAverage = 0;
m_PassAverage = 0;
}
CMapCell::~CMapCell (void)
{
}
void CMapCell::CalcWeight (void)
{
int midx,midy,count;
m_PassAverage = 0;
m_WeightAverage = 0;
count = 0;
for (midx = m_Left;midx<=m_Right;midx++)
{
for (midy=m_Top;midy<=m_Bottom;midy++)
{
count++;
m_WeightAverage+=g_Map[midx][midy].weight;
if (g_Map[midx][midy].passable)
{
m_PassAverage++;
}
}
}
m_PassAverage /= count;
m_WeightAverage /= count;
}
void CMapCell::CalcEdges (void)
{
int x,y;
for (x=m_Left;x<=m_Right;x++)
{
m_AreaData[m_Areas[x-m_Left][0]].flags |= TOPEDGEMASK;
m_AreaData[m_Areas[x-m_Left][MAPCELLSIZE-1]].flags |= BOTTOMEDGEMASK;
}
for (y=m_Top;y<=m_Bottom;y++)
{
m_AreaData[m_Areas[0][y-m_Top]].flags |= LEFTEDGEMASK;
m_AreaData[m_Areas[MAPCELLSIZE-1][y-m_Top]].flags |= RIGHTEDGEMASK;
}
}
void CMapCell::CalcArea (int sx,int sy,int id,int info)
{
if (sx < 0)
return;
if (sy<0)
return;
if (sx>=MAPCELLSIZE)
return;
if (sy>=MAPCELLSIZE)
return;
if ((m_Areas[sx][sy] == 0) && (SquareInfo (sx+m_Left,sy+m_Top)==info))
{
m_Areas[sx][sy] = id;
CalcArea (sx-1,sy,id,info);
CalcArea (sx+1,sy,id,info);
CalcArea (sx,sy-1,id,info);
CalcArea (sx,sy+1,id,info);
}
}
void CMapCell::CalcInterior (void)
{
int x,y,id;
float count[MAXAREAS];
for (x=0;x<MAPCELLSIZE;x++)
{
for (y=0;y<MAPCELLSIZE;y++)
{
m_Areas[x][y] = 0;
}
}
id = 1;
for (x=0;x<MAPCELLSIZE;x++)
{
for (y=0;y<MAPCELLSIZE;y++)
{
if (m_Areas[x][y])
continue;
assert (id<MAXAREAS);
m_AreaData[id].info = SquareInfo (x+m_Left,y+m_Top);
if (Passable (x+m_Left,y+m_Top))
m_AreaData[id].passable = 1;
else
m_AreaData[id].passable = 0;
CalcArea (x,y,id++,SquareInfo (x+m_Left,y+m_Top));
}
}
memset (count,0,sizeof(int)*MAXAREAS);
for (id=0;id<MAXAREAS;id++)
m_AreaData[id].weight = 0;
for (x=0;x<MAPCELLSIZE;x++)
{
for (y=0;y<MAPCELLSIZE;y++)
{
m_AreaData[m_Areas[x][y]].weight += g_Map[x+m_Left][y+m_Top].weight;
count[m_Areas[x][y]]++;
}
}
for (id=1;id<MAXAREAS;id++)
{
if (count[id] != 0)
m_AreaData[id].weight /= count[id];
}
}
void CMapCell::RenderEdges (CDIBSurface& dest,int dx)
{
int x,y;
for (x=m_Left;x<=m_Right;x++)
{
dest.Fill (dx+x*DRAWCELLSIZE,m_Top*DRAWCELLSIZE,dx+(x+1)*DRAWCELLSIZE,(m_Top+1)*DRAWCELLSIZE,RGB (0,255,0));
dest.Fill (dx+x*DRAWCELLSIZE,m_Bottom*DRAWCELLSIZE,dx+(x+1)*DRAWCELLSIZE,(m_Bottom+1)*DRAWCELLSIZE,RGB (0,255,0));
}
for (y=m_Top;y<=m_Bottom;y++)
{
dest.Fill (dx+m_Left*DRAWCELLSIZE,y*DRAWCELLSIZE,dx+(m_Left+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE,RGB (0,255,0));
dest.Fill (dx+m_Right*DRAWCELLSIZE,y*DRAWCELLSIZE,dx+(m_Right+1)*DRAWCELLSIZE,(y+1)*DRAWCELLSIZE,RGB (0,255,0));
}
}
FixedHeap<CALCZONEELEMENT> CALCZONEELEMENT::m_EmptyCalcZoneElement(1);
void CALCZONEELEMENT::operator =(FibHeapNode& RHS)
{
CALCZONEELEMENT& fred = (CALCZONEELEMENT&) RHS;
sx = fred.sx;
sy = fred.sy;
dx = fred.dx;
dy = fred.dy;
sarea = fred.sarea;
darea = fred.darea;
dir = fred.dir;
}
bool CALCZONEELEMENT::operator ==(FibHeapNode& RHS)
{
CALCZONEELEMENT& fred = (CALCZONEELEMENT&) RHS;
if (sx != fred.sx)
return false;
if (sy != fred.sy)
return false;
if (dx != fred.dx)
return false;
if (dy != fred.dy)
return false;
if (sarea != fred.sarea)
return false;
if (darea != fred.darea)
return false;
if (dir != fred.dir)
return false;
return true;
}
bool CALCZONEELEMENT::operator <(FibHeapNode& RHS)
{
CALCZONEELEMENT& fred = (CALCZONEELEMENT&) RHS;
float sw,dw;
sw = GetWeight (sx,sy,dx,dy,sarea,darea);
dw = GetWeight (fred.sx,fred.sy,fred.dx,fred.dy,fred.sarea,fred.darea);
if (sw < dw)
return true;
if (dw < sw)
return false;
if (fred.sx < sx)
return false;
if (sx < fred.sx)
return true;
if (fred.dx < dx)
return false;
if (dx < fred.dx)
return true;
if (fred.sy < sy)
return false;
if (sy < fred.sy)
return true;
if (fred.dy < dy)
return false;
if (dy < fred.dy)
return true;
if (sarea < fred.sarea)
return true;
if (darea < fred.darea)
return true;
if (dir < fred.dir)
return true;
return true;
}
float GetOneCostZone (int sx,int sy,int offset,int areaentry,int areaexit,int newarea)
{
float toret;
int dx,dy;
dx = sx + offsetzone[offset][0];
dy = sy + offsetzone[offset][1];
if (dx<0)
return -1.0;
if (dy<0)
return -1.0;
if (dx>=MAPCELLCOUNT)
return -1.0;
if (dy>=MAPCELLCOUNT)
return -1.0;
if (areaentry == areaexit)
{
if (!g_MapCells[sx][sy].AreaData (areaentry).passable)
return -1.0;
toret = g_MapCells[sx][sy].AreaData (areaentry).weight;
}
else
{
if (!g_MapCells[sx][sy].AreaData (areaentry).passable)
return -1.0;
if (!g_MapCells[sx][sy].AreaData (areaexit).passable)
return -1.0;
toret = g_MapCells[sx][sy].AreaData (areaentry).weight/2.0 + g_MapCells[sx][sy].AreaData (areaexit).weight/2.0;
}
//TODO: add support for connection of areas within the zone
#if 0
int x,y;
bool flag;
switch (offsetzone[offset][2])
{
case 0:
for (y=0;y<MAPCELLSIZE;y++)
{
if (g_Map)
{
}
}
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
#endif
if (offsetzone[offset][3] != 4) // just and area change, no new zone
{
if (!g_MapCells[dx][dy].AreaData (newarea).passable)
return -1.0;
toret += g_MapCells[dx][dy].AreaData (newarea).weight;
toret *= 0.5;
}
return toret;
}
float PathCostGuessZone (int sx,int sy,int dx,int dy)
{
int t1,t2;
t1 = dx - sx;
t2 = dy - dx;
__asm
{
mov eax,t1
cdq
xor eax,edx
sub eax,edx
mov t1,eax
mov eax,t2
cdq
xor eax,edx
sub eax,edx
mov t2,eax
}
// return t1+t2;
return t2 < t1 ? (t1+(t2>>1)) : (t2+(t1>>1));
}
CPoint GlobalToCellIndex (CPoint src)
{
int i;
CPoint toret(-1,-1);
for (i=0;i<MAPCELLCOUNT;i++)
{
if (src.x >= g_MapCells[i][0].Left () && src.x <= g_MapCells[i][0].Right())
{
toret.x = i;
break;
}
}
for (i=0;i<MAPCELLCOUNT;i++)
{
if (src.y >= g_MapCells[0][i].Top () && src.y <= g_MapCells[0][i].Bottom())
{
toret.y = i;
break;
}
}
return toret;
}
void FindLowerEdge (int dx,int dy,int endarea,int& sx,int& sy,int& curarea,int& dir,int startx,int starty,int startarea)
{
int i,j;
float cost;
float minvalue;
minvalue = FLT_MAX;
for (j=1;j<MAXAREAS;j++)
{
for (i=0;i<OFFSIZEZONE;i++)
{
cost = GetWeight (dx,dy,i,j,endarea);
if (cost != -1)
{
if ((startx == dx+offsetzone[i][0]) && (starty == dy+offsetzone[i][1]) && (startarea == j))
{
sx = startx;
sy = starty;
curarea = j;
dir = (offsetzone[i][2]+2)& 0x03;
return;
}
if (cost<minvalue)
{
minvalue = cost;
sx = dx + offsetzone[i][0];
sy = dy + offsetzone[i][1];
curarea = j;
dir = (offsetzone[i][2]+2) & 0x03;
}
}
}
}
}
bool AddCalcElements (FibHeap& calc,int sx,int sy,int area,float startweight)
{
int i,j,temparea;
int x,y;
float cost;
CALCZONEELEMENT *temp;
AREADATA& tempdata = g_MapCells[sx][sy].AreaData (area);
if (tempdata.left_connect)
{
i = sx-1;
j = sy;
if (i>=0)
{
for (y=0;y<MAPCELLSIZE;y++)
{
if (g_MapCells[sx][sy].m_Areas[0][y] == area)
{
temparea = g_MapCells[i][j].m_Areas[MAPCELLSIZE-1][y];
cost = GetOneCostZone (sx,sy,0,area,area,temparea);
assert (cost != -1);
cost += startweight;
if (SetWeight (sx,sy,0,area,temparea,cost))
{
temp = new CALCZONEELEMENT (sx,sy,i,j,area,temparea,LEFTEDGE);
calc.Insert (temp);
}
}
}
}
}
if (tempdata.top_connect)
{
i = sx;
j = sy-1;
if (j>=0)
{
for (x=0;x<MAPCELLSIZE;x++)
{
if (g_MapCells[sx][sy].m_Areas[x][0] == area)
{
temparea = g_MapCells[i][j].m_Areas[x][MAPCELLSIZE-1];
cost = GetOneCostZone (sx,sy,1,area,area,temparea);
assert (cost != -1);
cost += startweight;
if (SetWeight (sx,sy,1,area,temparea,cost))
{
temp = new CALCZONEELEMENT (sx,sy,i,j,area,temparea,TOPEDGE);
calc.Insert (temp);
}
}
}
}
}
if (tempdata.right_connect)
{
i = sx+1;
j = sy;
if (i<MAPCELLCOUNT)
{
for (y=0;y<MAPCELLSIZE;y++)
{
if (g_MapCells[sx][sy].m_Areas[MAPCELLSIZE-1][y] == area)
{
temparea = g_MapCells[i][j].m_Areas[0][y];
cost = GetOneCostZone (sx,sy,2,area,area,temparea);
assert (cost != -1);
cost += startweight;
if (SetWeight (sx,sy,2,area,temparea,cost))
{
temp = new CALCZONEELEMENT (sx,sy,i,j,area,temparea,RIGHTEDGE);
calc.Insert (temp);
}
}
}
}
}
if (tempdata.bottom_connect)
{
i = sx;
j = sy+1;
if (j<MAPCELLCOUNT)
{
for (x=0;x<MAPCELLSIZE;x++)
{
if (g_MapCells[sx][sy].m_Areas[x][MAPCELLSIZE-1] == area)
{
temparea = g_MapCells[i][j].m_Areas[x][0];
cost = GetOneCostZone (sx,sy,3,area,area,temparea);
assert (cost != -1);
cost += startweight;
if (SetWeight (sx,sy,3,area,temparea,cost))
{
temp = new CALCZONEELEMENT (sx,sy,i,j,area,temparea,BOTTOMEDGE);
calc.Insert (temp);
}
}
}
}
}
return true;
}
bool CalcPathZone (std::stack<PATHZONEELEMENT> *dest,CPoint gstart,CPoint gend)
{
int curarea,endarea,startarea;
int i,j,k;
FibHeap calc;
CALCZONEELEMENT *temp;
CPoint start,end;
assert (gstart.x>=0);
assert (gstart.x<MAPSIZE);
assert (gstart.y>=0);
assert (gstart.y<MAPSIZE);
start = GlobalToCellIndex (gstart);
end = GlobalToCellIndex (gend);
assert (start.x != -1);
assert (start.y != -1);
assert (end.x != -1);
assert (end.y != -1);
if (start == end)
{
// TODO: need to update if start and end zones are the same yet can't get there
dest->push (PATHZONEELEMENT (start.x,start.y,end.x,end.y,g_MapCells[start.x][start.y].AreaGlobal (gstart.x,gstart.y),g_MapCells[end.x][end.y].AreaGlobal (gend.x,gend.y),-1));
return true;
}
int x=-1,y=-1;
bool done;
while (!dest->empty ())
dest->pop ();
for (i=0;i<MAPCELLSIZE;i++)
for (j=0;j<MAPCELLSIZE;j++)
for (k=0;k<OFFSIZEZONE;k++)
{
pathmapzone[i][j][k].clear ();
}
endarea = g_MapCells[end.x][end.y].AreaGlobal (gend.x,gend.y);
curarea = g_MapCells[start.x][start.y].AreaGlobal (gstart.x,gstart.y);
startarea = curarea;
AREADATA& tempdata = g_MapCells[start.x][start.y].AreaData (curarea);
AddCalcElements (calc,start.x,start.y,curarea,0);
done = false;
while (!done)
{
temp = (CALCZONEELEMENT *) calc.ExtractMin ();
if (temp == NULL)
break;
if ((temp->dx == end.x) && (temp->dy == end.y) && (temp->darea == endarea))
done = true;
else
AddCalcElements (calc,temp->dx,temp->dy,temp->darea,GetWeight (temp->sx,temp->sy,temp->dx,temp->dy,temp->sarea,temp->darea));
delete temp;
}
while (temp = (CALCZONEELEMENT *) calc.ExtractMin ())
delete temp;
if (!done)
return false;
done = false;
int curx,cury;
curx = end.x;
cury = end.y;
curarea = endarea;
while (!done)
{
int dx,dy,darea,dir;
FindLowerEdge (curx,cury,curarea,dx,dy,darea,dir,start.x,start.y,startarea);
dest->push (PATHZONEELEMENT (dx,dy,curx,cury,darea,curarea,dir));
curx = dx;
cury = dy;
curarea = darea;
if ((curx == start.x) && (cury == start.y) && (curarea == startarea))
{
done = true;
}
}
return true;
}
+185
View File
@@ -0,0 +1,185 @@
#ifndef __MOVEZONEHPP__
#define __MOVEZONEHPP__
#include <stack>
#include <queue>
const int OFFSIZEZONE = 4;
const int offsetzone[OFFSIZEZONE][3] = { // third number is the direction l,t,r,b 0,1,2,3
{-1,0,0},
{0,-1,1},
{1,0,2},
{0,1,3}
};
const int LEFTEDGEMASK=0x01;
const int TOPEDGEMASK=0x02;
const int RIGHTEDGEMASK=0x04;
const int BOTTOMEDGEMASK=0x08;
const int LEFTEDGE = 0;
const int TOPEDGE = 1;
const int RIGHTEDGE = 2;
const int BOTTOMEDGE = 3;
struct AREADATA
{
union
{
struct
{
unsigned left_connect:1;
unsigned top_connect:1;
unsigned right_connect:1;
unsigned bottom_connect:1;
unsigned passable:1;
};
unsigned char flags;
};
int info;
float weight;
bool operator< (const AREADATA& p1) const
{
return flags < p1.flags;
}
bool operator== (const AREADATA& p1) const
{
return flags == p1.flags;
}
bool operator!= (const AREADATA& p1) const
{
return flags != p1.flags;
}
};
struct PATHZONEELEMENT
{
int sx,sy; // cell id
int dx,dy; // cell id
int sarea,darea; // sarea is the start area for the edge, darea is the area for the edge on the other cell
// sarea may not be the area that you entered the cell on
int dir;
bool operator< (const PATHZONEELEMENT& p1) const;
bool operator== (const PATHZONEELEMENT& p1) const;
PATHZONEELEMENT (int nsx,int nsy,int ndx,int ndy,int nsarea,int ndarea,int ndir) {sx=nsx;sy=nsy;dx=ndx;dy=ndy;sarea=nsarea;darea=ndarea;dir=ndir;}
PATHZONEELEMENT (void) { sx = -1; sy = -1; dx = -1; dy = -1; sarea = 0;darea = 0;dir = -1;}
};
const int MAPCELLSIZE = 16;
const int DRAWCELLSIZE=2;
bool SetWeight (int sx,int sy,int offset,int areaentry,int areaexit,float newweight); // offset is the index into the offsetzone table
float GetWeight (int sx,int sy,int offset,int areaentry,int areaexit); // offset is the index into the offsetzone table
float GetWeight (int sx,int sy,int dx,int dy,int areaentry,int areaexit); // offset is the index into the offsetzone table
void FindLowerEdge (int dx,int dy,int endarea,int& sx,int& sy,int& curarea,int& dir,int startx,int starty,int startarea); // will get the lowest connection from dx,dy to sx,sy
// used to find path in reverse order
// will return startx,starty,startarea if there is a choice for this connection
CPoint GlobalToCellIndex (CPoint src);
bool CalcPathZone (std::stack<PATHZONEELEMENT> *dest,CPoint start,CPoint end); // in the zone
float GetOneCostZone (int sx,int sy,int offset,int areaentry,int areaexit,int newarea); // offset is the index into the offsetzone table
float PathCostGuessZone (int sx,int sy,int dx,int dy);
void InitMoveZoneData (void);
bool AddCalcElements (FibHeap& calc,int sx,int sy,int area,float startweight);
class CALCZONEELEMENT : public FibHeapNode
{
private:
static FixedHeap<CALCZONEELEMENT> m_EmptyCalcZoneElement;
public:
int sx,sy;
int dx,dy;
int sarea,darea;
int dir;
CALCZONEELEMENT (int nsx,int nsy,int ndx,int ndy,int nsarea,int ndarea,int ndir) {sx=nsx;sy=nsy;dx=ndx;dy=ndy;sarea=nsarea;darea=ndarea;dir = ndir;}
CALCZONEELEMENT (void) { sx = -1; sy = -1; dx = -1; dy = -1; sarea = 0;darea = 0;dir = -1;}
virtual void operator =(FibHeapNode& RHS);
virtual bool operator ==(FibHeapNode& RHS);
virtual bool operator <(FibHeapNode& RHS);
// static CALCELEMENT *GetBlankElement (void) { return (CALCELEMENT *) m_EmptyCalcElement.Alloc (); }
// static void DoneElement (CALCELEMENT *oldelem) { m_EmptyCalcElement.Free (oldelem); }
// void *operator new (size_t size) {return GetBlankElement (); }
// void operator delete (void *value,size_t size) { DoneElement ((CALCELEMENT *) value); }
};
//const int MAPCELLCOUNT = ((MAPSIZE/(MAPCELLSIZE-1))+((MAPSIZE%(MAPCELLSIZE-1))?1:0));
const int MAPCELLCOUNT = 17;
const int MAXAREAS=16;
class CMapCell
{
friend float GetOneCostZone (int sx,int sy,int offset,int areaentry,int areaexit,int newarea); // offset is the index into the offsetzone table
friend bool CalcPathZone (std::stack<PATHZONEELEMENT> *dest,CPoint start,CPoint end); // in the zone
friend bool AddCalcElements (FibHeap& calc,int sx,int sy,int area,float startweight);
private:
int m_Left,m_Right,m_Bottom,m_Top;
float m_WeightAverage;
float m_PassAverage;
int m_Areas[MAPCELLSIZE][MAPCELLSIZE];
AREADATA m_AreaData[MAXAREAS]; // first four bits are edge connection data l,t,r,b 0,1,2,3
void CalcArea (int sx,int sy,int id,int info);
public:
CMapCell (void);
~CMapCell (void);
/*
void Left (int value) { m_Left = value; }
void Right (int value) { m_Right = value; }
void Top (int value) { m_Top = value; }
void Bottom (int value) { m_Bottom = value; }
*/
int Left (void) { return m_Left; }
int Right (void) { return m_Right; }
int Top (void) { return m_Top; }
int Bottom (void) { return m_Bottom; }
float AverageWeight (void) { return m_WeightAverage; }
int AreaGlobal (int globalx,int globaly) // takes global coordinates
{ return m_Areas[globalx-m_Left][globaly-m_Top]; }
int AreaLocal (int localx,int localy) // takes coordinates local to this cell
{ return m_Areas[localx][localy]; }
AREADATA AreaData (int area)
{ return m_AreaData[area]; }
void CalcWeight (void);
void CalcEdges (void);
void CalcInterior (void);
void SetSize (int left,int top,int right,int bottom)
{
assert (left>=0);
assert (left<MAPSIZE);
assert (right>=0);
assert (right<MAPSIZE);
assert (top>=0);
assert (top<MAPSIZE);
assert (bottom>=0);
assert (bottom<MAPSIZE);
assert (left<right);
assert (top<bottom);
m_Left = left;
m_Top = top;
m_Right = right;
m_Bottom = bottom;
}
void RenderEdges (CDIBSurface& dest,int dx);
};
extern CMapCell g_MapCells[MAPCELLCOUNT][MAPCELLCOUNT];
#endif
@@ -0,0 +1,15 @@
#ifndef __PROTOTYPEHPP__
#define __PROTOTYPEHPP__
void InitGlobals (void);
void KillGlobals (void);
void InitSystem (void);
void KillSystem (void);
void InitWindows (bool);
void KillWindows (void);
void InitMap (void);
#endif
+34
View File
@@ -0,0 +1,34 @@
#pragma warning (disable:4786)
#include "ai test.hpp"
void InitSystem (void)
{
InitWindows (true);
try
{
srand (timeGetTime ());
InitAI (true);
InitWindows (true);
InitAI (false);
InitMap ();
InitWindows (false);
g_MainWindow = new CAITestWindow ();
g_MainWindow->Create ("AI Window",514,514);
ShowWindow (g_MainWindow->Window (),SW_SHOW);
}
catch (exception ex)
{
cerr << ex.what () << endl;
}
}
void KillSystem (void)
{
delete g_MainWindow;
// KillDatabase ();
KillWindows ();
}
+123
View File
@@ -0,0 +1,123 @@
// vector standard header
#pragma once
#ifndef _TESTHPP_
#define _TESTHPP_
template<class _Type>
class my_vector
{
private:
_Type *m_Front;
_Type *m_Tail;
_Type *m_End;
int m_grow_size;
public:
my_vector (int growsize=1)
{
m_Front = m_Tail = m_End;
m_grow_size = growsize;
}
~my_vector (void)
{
delete m_Front;
m_Front = m_Tail = m_End;
}
_Type& at (int index)
{
assert (index>=0);
assert (index < (m_Tail - m_Front));
return m_Front[index];
}
const _Type& at (int index) const
{
assert (index>=0);
assert (index < (m_Tail - m_Front));
return m_Front[index];
}
_Type& operator[] (int index)
{
assert (index>=0);
assert (index < (m_Tail - m_Front));
return m_Front[index];
}
const _Type& operator[] (int index) const
{
assert (index>=0);
assert (index < (m_Tail - m_Front));
return m_Front[index];
}
void clear (void)
{
erase (0,size);
}
bool empty (void)
{
return m_Front == m_Tail;
}
void erase (int index)
{
int i,count;
assert (index>=0);
assert (index < (m_Tail - m_Front));
count = m_Tail - m_Start;
for (i=index;i<count;i++)
{
m_Front[i] = m_Front[i+1];
}
m_Front[count].~_Type ();
m_Tail--;
}
void pop_back (void)
{
m_Tail->~_Type ();
m_Tail--;
}
void push_back (const _Type& element)
{
if (m_Tail == m_End)
{
reserve ((m_Tail - m_Front)+m_grow_size);
}
m_Tail++;
*m_Tail = element;
}
void reserve (int amount)
{
if (amount > (m_End-m_Front))
{
_Type *temp,*cur;
int i,count;
temp = new _Type[amount];
count = m_Tail - m_Front;
cur = temp;
for (i=0;i<count;i++)
{
*cur = m_Front[i];
cur++;
}
delete m_Front;
m_Front = temp;
m_Tail = m_Front+count;
m_End = temp+amount;
}
}
int size (void) const
{
return m_Tail - m_Front;
}
};
#endif /* _TESTHPP_ */
+364
View File
@@ -0,0 +1,364 @@
#pragma warning (disable:4786)
#include "ai test.hpp"
#include "windows.hpp"
#include "globals.hpp"
LRESULT WINAPI RootWndProc (HWND thewnd,UINT themsg,WPARAM wParam,LPARAM lParam);
void InitWindows (bool firstpass)
{
WNDCLASS rootclass;
if (firstpass) // on the first pass so set the global window to null
{
return;
}
rootclass.style = CS_OWNDC;
rootclass.lpfnWndProc = RootWndProc;
rootclass.cbClsExtra = 0;
rootclass.cbWndExtra = 4;
rootclass.hInstance = g_hInstance;
rootclass.hIcon = LoadIcon (NULL,IDI_APPLICATION);
rootclass.hCursor = LoadCursor (NULL,IDC_ARROW);
rootclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
rootclass.lpszMenuName = NULL;
rootclass.lpszClassName = WINDOW_CLASS_NAME;
if (!RegisterClass (&rootclass)) // register the class for the root window
throw std::runtime_error ("unable to register window class");
}
void KillWindows (void)
{
UnregisterClass (WINDOW_CLASS_NAME,g_hInstance);
}
LRESULT WINAPI RootWndProc (HWND thewnd,UINT themsg,WPARAM wParam,LPARAM lParam)
{
LPCREATESTRUCT cdata;
CWindow *window;
switch (themsg)
{
case WM_CREATE:
cdata = reinterpret_cast<LPCREATESTRUCT> (lParam);
window = reinterpret_cast<CWindow *> (cdata->lpCreateParams);
if (window != 0)
{
window->Window (thewnd);
SetWindowLong (thewnd,GWL_USERDATA,reinterpret_cast<long> (window));
return window->WndProc (thewnd,themsg,wParam,lParam);
}
break;
default:
window = reinterpret_cast<CWindow *> (GetWindowLong (thewnd,GWL_USERDATA));
if (window != NULL)
return window->WndProc (thewnd,themsg,wParam,lParam);
break;
}
return DefWindowProc (thewnd,themsg,wParam,lParam);
}
CWindow::CWindow (void)
{
m_Window = NULL;
}
CWindow::~CWindow (void)
{
}
void CWindow::Create (const CString& title,int width,int height,int offw,int offh,bool scale)
{
CRect arect;
DWORD style = c_dwWindowedStyle;
m_Scale = scale;
if (offw == 0)
offw = width;
if (offh == 0)
offh = height;
m_BackWidth = offw;
m_BackHeight = offh;
if (width != offw)
{
if (!m_Scale)
{
style |= WS_HSCROLL;
}
style |= WS_THICKFRAME;
style |= WS_MAXIMIZEBOX;
style |= WS_MINIMIZEBOX;
}
if (height != offh)
{
if (!m_Scale)
{
style |= WS_VSCROLL;
}
style |= WS_THICKFRAME;
style |= WS_MAXIMIZEBOX;
style |= WS_MINIMIZEBOX;
}
arect.left = 0;
arect.top = 0;
arect.right = width;
arect.bottom = height;
AdjustWindowRectEx (&arect,style,true,c_dwWindowedStyleEx);
Window( CreateWindowEx (c_dwWindowedStyleEx, // create our root/main window in the requested size
WINDOW_CLASS_NAME,WINDOW_NAME,
style,
CW_USEDEFAULT,CW_USEDEFAULT,arect.right - arect.left,arect.bottom - arect.top,
NULL,NULL,g_hInstance,this));
if (m_Window == NULL) // if we fail in creation then throw an exception
throw std::runtime_error ("root window did not create");
SetWindowText (m_Window,(LPCTSTR) title);
g_szTitle = (LPCSTR) title;
g_szClassName = WINDOW_CLASS_NAME;
InitialUpdate ();
}
void CDIBWindow::Create (const CString& title,int width,int height,int offw,int offh,bool scale)
{
if (offw == 0)
offw = width;
if (offh == 0)
offh = height;
m_Background.Create (offw,offh,16);
CWindow::Create (title,width,height,offw,offh,scale);
}
#if 0
void CDDWindow::Create (const CString& title,int width,int height,int offw,int offh,bool scale)
{
if (offw == 0)
offw = width;
if (offh == 0)
offh = height;
m_DirectBackground.Create (offw,offh,16,false,true);
CDIBWindow::Create (title,width,height,offw,offh,scale);
}
#endif
void CDIBWindow::Render (HDC thedc,LPPAINTSTRUCT data)
{
int xpos,ypos;
CRect b;
HDC src;
bool ret;
if (IsValid ())
{
xpos = GetScrollPos (m_Window,SB_HORZ);
ypos = GetScrollPos (m_Window,SB_VERT);
if (data)
{
b = data->rcPaint;
}
else
{
GetClientRect (m_Window,&b);
}
src = m_Background.GetDC ();
if (m_Scale)
{
ret = StretchBlt (thedc,0,0,b.Width (),b.Height (),src,0,0,m_BackWidth,m_BackHeight,SRCCOPY);
}
else
{
ret = BitBlt (thedc,b.left,b.top,b.Width (),b.Height(),src,b.left,b.top,SRCCOPY);
}
m_Background.ReleaseDC (src);
}
}
#if 0
void CDDWindow::Render (HDC thedc,LPPAINTSTRUCT data)
{
int xpos,ypos;
CRect bounds;
HDC src,dest;
if (IsValid ())
{
xpos = GetScrollPos (m_Window,SB_HORZ);
ypos = GetScrollPos (m_Window,SB_VERT);
if (data)
{
bounds = data->rcPaint;
}
else
{
GetClientRect (m_Window,&bounds);
}
src = m_DirectBackground.GetDC ();
dest = m_Background.GetDC ();
bool ret = BitBlt (dest,bounds.left,bounds.top,bounds.Width (),bounds.Height(),src,xpos,ypos,SRCCOPY);
m_Background.ReleaseDC (dest);
m_DirectBackground.ReleaseDC (src);
}
CDIBWindow::Render (thedc,data);
}
#endif
LRESULT CWindow::WndProc (HWND thewnd,UINT themsg,WPARAM wParam,LPARAM lParam)
{
int w,h;
CString fred;
SCROLLINFO sinfo;
LPMINMAXINFO data;
CRect client,window,offset;
int scrollcode,scrollpos;
HDC thedc;
PAINTSTRUCT paint;
assert (thewnd == m_Window);
switch (themsg)
{
case WM_PAINT:
thedc = BeginPaint (thewnd,&paint);
Render (thedc,&paint);
EndPaint (thewnd,&paint);
break;
case WM_SIZE:
if (!m_Scale)
{
w = m_BackWidth - LOWORD (lParam);
h = m_BackHeight - HIWORD (lParam);
if (w<0)
w = 0;
if (h<0)
h = 0;
sinfo.cbSize = sizeof (SCROLLINFO);
sinfo.fMask = SIF_RANGE + SIF_DISABLENOSCROLL;
sinfo.nMin = 0;
sinfo.nMax = h;
// sinfo.nPage = min (HIWORD (lParam),m_BackHeight - HIWORD (lParam));
SetScrollInfo (thewnd,SB_VERT,&sinfo,true);
sinfo.cbSize = sizeof (SCROLLINFO);
sinfo.fMask = SIF_RANGE + SIF_DISABLENOSCROLL;
sinfo.nMin = 0;
sinfo.nMax = w;
// sinfo.nPage = min (LOWORD (lParam),m_BackWidth - LOWORD (lParam));
SetScrollInfo (thewnd,SB_HORZ,&sinfo,true);
}
else
{
InvalidateRect (thewnd,NULL,false);
}
break;
case WM_VSCROLL:
scrollcode = LOWORD (wParam);
scrollpos = GetScrollPos (thewnd,SB_VERT);
switch (scrollcode)
{
case SB_BOTTOM:
scrollpos = m_BackHeight;
break;
case SB_LINEDOWN:
scrollpos += 10;
break;
case SB_LINEUP:
scrollpos -= 10;
break;
case SB_PAGEDOWN:
scrollpos += 100;
break;
case SB_PAGEUP:
scrollpos -= 100;
break;
case SB_THUMBPOSITION:
scrollpos = HIWORD (wParam);
break;
case SB_THUMBTRACK:
scrollpos = HIWORD (wParam);
break;
case SB_TOP:
scrollpos = 0;
break;
}
if (scrollpos < 0)
scrollpos = 0;
GetClientRect (thewnd,&client);
if (scrollpos > (m_BackHeight - client.Height ()))
scrollpos = m_BackHeight - client.Height ();
SetScrollPos (thewnd,SB_VERT,scrollpos,true);
break;
case WM_HSCROLL:
scrollcode = LOWORD (wParam);
scrollpos = GetScrollPos (thewnd,SB_HORZ);
switch (scrollcode)
{
case SB_BOTTOM:
scrollpos = m_BackWidth;
break;
case SB_LINEDOWN:
scrollpos += 10;
break;
case SB_LINEUP:
scrollpos -= 10;
break;
case SB_PAGEDOWN:
scrollpos += 100;
break;
case SB_PAGEUP:
scrollpos -= 100;
break;
case SB_THUMBPOSITION:
scrollpos = HIWORD (wParam);
break;
case SB_THUMBTRACK:
scrollpos = HIWORD (wParam);
break;
case SB_TOP:
scrollpos = 0;
break;
}
if (scrollpos < 0)
scrollpos = 0;
GetClientRect (thewnd,&client);
if (scrollpos > (m_BackWidth - client.Width ()))
scrollpos = m_BackWidth - client.Width ();
SetScrollPos (thewnd,SB_HORZ,scrollpos,true);
break;
case WM_GETMINMAXINFO:
GetClientRect (thewnd,&client);
GetWindowRect (thewnd,&window);
offset.left = client.left - window.left;
offset.right = window.right - client.right;
offset.top = client.top - window.top;
offset.bottom = window.bottom - client.bottom;
offset.left += offset.right;
offset.top += offset.bottom;
data = reinterpret_cast<LPMINMAXINFO> (lParam);
data->ptMinTrackSize.x = 50;
data->ptMinTrackSize.y = 50;
data->ptMaxTrackSize.x = m_BackWidth + offset.left;
data->ptMaxTrackSize.y = m_BackHeight + offset.top;
data->ptMaxSize.x = m_BackWidth + offset.left;
data->ptMaxSize.y = m_BackHeight + offset.top;
data->ptMaxPosition.x = 20;
data->ptMaxPosition.y = 20;
break;
case WM_LBUTTONDOWN:
LButtonDown (LOWORD (lParam),HIWORD (lParam));
break;
case WM_RBUTTONDOWN:
RButtonDown (LOWORD (lParam),HIWORD (lParam));
break;
case WM_LBUTTONUP:
LButtonUp (LOWORD (lParam),HIWORD (lParam));
break;
case WM_RBUTTONUP:
RButtonUp (LOWORD (lParam),HIWORD (lParam));
break;
case WM_MOUSEMOVE:
MouseMove (LOWORD (lParam),HIWORD (lParam));
break;
}
return DefWindowProc (thewnd,themsg,wParam,lParam);
}
@@ -0,0 +1,92 @@
#ifndef __WINDOWSHPP__
#define __WINDOWSHPP__
#include <windows.h>
#include <utils\utils.h>
#include <dib surface\dibsection.hpp>
class CWindow
{
protected:
int m_BackWidth,m_BackHeight;
HWND m_Window;
bool m_Scale;
public:
CWindow (void);
~CWindow (void);
virtual void Create (const CString& title,int width,int height,int offw=0,int offh=0,bool scale=false);
void Window (HWND newwnd)
{
m_Window = newwnd;
}
HWND Window (void) const
{
return m_Window;
}
bool IsValid (void) const
{
return m_Window != NULL;
}
operator HWND() const
{
return m_Window;
}
virtual LRESULT WndProc (HWND thewnd,UINT themsg,WPARAM wParam,LPARAM lParam);
virtual void Render (HDC thedc,LPPAINTSTRUCT data = NULL) {}
virtual void InitialUpdate(void) {};
virtual void LButtonDown (int x,int y) {}
virtual void RButtonDown (int x,int y) {}
virtual void LButtonUp (int x,int y) {}
virtual void RButtonUp (int x,int y) {}
virtual void MouseMove (int x,int y) {}
};
class CDIBWindow : public CWindow
{
protected:
CDIBSurface m_Background;
public:
CDIBWindow (void) {};
~CDIBWindow (void) {};
virtual void Create (const CString& title,int width,int height,int offw=0,int offh=0,bool scale=false);
bool IsValid (void) const
{
return (m_Background.IsValid () && CWindow::IsValid ());
}
CDIBSurface& GetSurface(void)
{
return m_Background;
}
virtual void Render (HDC thedc,LPPAINTSTRUCT data = NULL);
};
#if 0
class CDDWindow : public CDIBWindow
{
protected:
CDDRenderSurface m_DirectBackground;
public:
CDDWindow (void) {};
~CDDWindow (void) {};
virtual void Create (const CString& title,int width,int height,int offw=0,int offh=0,bool scale=false);
bool IsValid (void) const
{
return (m_DirectBackground.IsValid () && CDIBWindow::IsValid ());
}
CDDRenderSurface& GetSurface (void)
{
return m_DirectBackground;
}
virtual void Render (HDC thedc,LPPAINTSTRUCT data = NULL);
};
#endif
#endif
+43
View File
@@ -0,0 +1,43 @@
#pragma warning (disable:4786)
#include "ai test.hpp"
CPerson::CPerson (void)
{
m_Awareness = new AIAwareness (this);
m_Combat = new AICombat (this);
m_Converse = new AIConverse (this);
m_Comm = new AIComm (this);
m_Move = new AIMove (this);
}
CPerson::~CPerson (void)
{
}
void CPerson::SetDestination (int x,int y)
{
m_Move->SetDestination (x,y);
}
void CPerson::DoTick (void)
{
CRect arect;
Think (1);
arect.left = 0;
arect.top = 0;
arect.right = 514;
arect.bottom = 514;
InvalidateRect (g_MainWindow->Window (),&arect,false);
}
void DoTick (void)
{
int i;
DoPathTick ();
for (i=0;i<MAXPERSON;i++)
g_Person[i].DoTick ();
}
@@ -0,0 +1,18 @@
// This file is used to automatically update the build number for each nightly/weekly build
// that is done. The formatting is kept simple since the logic in the tool that works with this
// file is very simple. Use these defines anywhere in code and resources where you need the string
// or number format of the current version.
// Format for hardware builds
#if defined( BLACK_KNIGHT )
#define CURRENT_BUILD_FULL 45,30,04,1908
#define CURRENT_BUILD_FULL_STRING "45.30.04.1908"
#endif
// !!!must end the file with at least one carriage return
@@ -0,0 +1,82 @@
/* buildnum.h*/
#ifndef BUILDNUM_H
#define BUILDNUM_H
#include "..\buildnum\curver.h"
#ifndef CURRENT_BUILD_FULL
#error "Couldn't set CURRENT_BUILD_FULL"
#endif
// 08/13/99 This was updated to remove a few formats since the build version has changed to support
// the hardware groups build numbering version.
/*--------------------------------------------------------------*/
/* */
/* CHANGING VERSION? */
/* */
/* PLEASE READ! */
/* */
/* The version has BOTH hex and string representations. Take */
/* care that the string version components are PROPERLY */
/* CONVERTED TO HEX and that the hex values are INSERTED INTO */
/* THE CORRECT POSITION in the hex versions. */
/* */
/* Suppose the version was being defined as: */
/* */
/* #define VERSION "9.99.1234" */
/* */
/* The other string preresentations of the version would be: */
/* */
/* #define VER_PRODUCTVERSION_STR "9.99.1234\0" */
/* #define VER_PRODUCTVERSION 9,99,0,1234 */
/* */
/* */
/*--------------------------------------------------------------*/
#define VERSION CURRENT_BUILD_FULL_STRING
#define VER_PRODUCTVERSION_STR CURRENT_BUILD_FULL_STRING "\0"
#define VER_PRODUCTVERSION CURRENT_BUILD_FULL
//
// This version number is used to force a rebuild of the resources because of a code change rather
// than a data change. This is safer to use than bumping a number in the resource.build file
// because coders always to gets of code, but not always gets of content
//
#define VER_CONTENTVERSION 63
// For displaying, or including logic based on the current build
#define VERTYPE_DEBUG_INT 4
#define VERTYPE_ARMOR_INT 3
#define VERTYPE_PROFILE_INT 2
#define VERTYPE_RELEASE_INT 1
#ifdef DEBUG
#define VER_BUILDTYPE_STR "Debug"
#define VER_BUILDTYPE_INT VERTYPE_DEBUG_INT
#else
#ifdef ARMOR
#define VER_BUILDTYPE_STR "Armor"
#define VER_BUILDTYPE_INT VERTYPE_ARMOR_INT
#else
#ifdef PROFILE
#define VER_BUILDTYPE_STR "Profile"
#define VER_BUILDTYPE_INT VERTYPE_PROFILE_INT
#else
#define VER_BUILDTYPE_STR "Release"
#define VER_BUILDTYPE_INT VERTYPE_RELEASE_INT
#endif
#endif
#endif
#define VER_COMPANYNAME_STR "Virtual World Entertainment\0"
#define VER_PRODUCTNAME_STR "Battletech Firestorm\256\0"
#define VER_COPYRIGHT_STR "Copyright @ 2005 Virtual World Entertainment LLC\0"
#define VER_LEGALTRADEMARKS_STR \
"Microsoft\256 is a registered trademark of Microsoft Corporation. Windows(TM) is a trademark of Microsoft Corporation.\0"
#endif // BUILDNUM_H
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
// This file is used to automatically update the build number for each nightly/weekly build
// that is done. The formatting is kept simple since the logic in the tool that works with this
// file is very simple. Use these defines anywhere in code and resources where you need the string
// or number format of the current version.
// Format for hardware builds
//#define CURRENT_BUILD_FULL 01,20,07,240z
//#define CURRENT_BUILD_FULL_STRING "01.20.07.240z"
#define CURRENT_BUILD_FULL 05,07,00,00
#define CURRENT_BUILD_FULL_STRING "05.07.00.00"
// !!!must end the file with at least one carriage return
@@ -0,0 +1,18 @@
// This file is used to automatically update the build number for each nightly/weekly build
// that is done. The formatting is kept simple since the logic in the tool that works with this
// file is very simple. Use these defines anywhere in code and resources where you need the string
// or number format of the current version.
// Format for hardware builds
#if defined( MERCENARIES )
#define CURRENT_BUILD_FULL 50,03,04,1908
#define CURRENT_BUILD_FULL_STRING "50.03.04.1908"
#endif
// !!!must end the file with at least one carriage return
@@ -0,0 +1,4 @@
buildnumwithdate curver.h CURRENT_BUILD_FULL
buildnumwithdate curver.h CURRENT_BUILD_FULL_STRING
REM no longer three entries in the version file
pause
@@ -0,0 +1,18 @@
// This file is used to automatically update the build number for each nightly/weekly build
// that is done. The formatting is kept simple since the logic in the tool that works with this
// file is very simple. Use these defines anywhere in code and resources where you need the string
// or number format of the current version.
// Format for hardware builds
#if defined( VENGEANCE )
#define CURRENT_BUILD_FULL 01,30,04,1908
#define CURRENT_BUILD_FULL_STRING "01.30.04.1908"
#endif
// !!!must end the file with at least one carriage return
Binary file not shown.
@@ -0,0 +1,42 @@
[0]
Name=test4444
Type=2
Width=64
Height=64
[1]
Name=polar.lightmap01
Type=1
Width=512
Height=512
[2]
Name=0401a_grass_01
Type=1
Width=256
Height=256
[3]
Name=0202a_mask_256a_active
Type=3
Width=256
Height=256
[4]
Name=0202a_mask_256b_active
Type=3
Width=256
Height=256
[5]
Name=0202a_mask_256c_active
Type=5
Width=256
Height=256
[6]
Name=brb.color.01
Type=1
Width=256
Height=256
@@ -0,0 +1,228 @@
#include <Stuff\StuffHeaders.hpp>
#include <DLLPlatform\DLLPlatform.hpp>
#include <Compost\CompostHeaders.hpp>
#include "ImageLib\image.h"
void __stdcall InitializeGameEngine()
{
//
//---------------------
// Initialize libraries
//---------------------
//
Stuff::InitializeClasses();
Compost::TexturePool::Instance = new Compost::TexturePool;
Register_Pointer(Compost::TexturePool::Instance);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void __stdcall DoGameLogic()
{
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void __stdcall UpdateDisplay()
{
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void __stdcall TerminateGameEngine()
{
//
//-------------------
// Turn off libraries
//-------------------
//
Unregister_Pointer(Compost::TexturePool::Instance);
delete Compost::TexturePool::Instance;
Stuff::TerminateClasses();
}
//
// Setup the GameOS structure
//
void __stdcall GetGameOSEnvironment( char* CommandLine )
{
CommandLine = CommandLine;
Environment.applicationName = "CompostTest";
Environment.directoryPath = "";
Environment.screenWidth = 640;
Environment.screenHeight = 480;
Environment.fullScreen = FALSE;
Environment.bitDepth = 16;
Environment.debugLog = "CompostTest.txt";
Environment.spew = ""; //"GameOS*";
Environment.UpdateRenderers = UpdateDisplay;
Environment.DoGameLogic = DoGameLogic;
Environment.InitializeGameEngine = InitializeGameEngine;
Environment.TerminateGameEngine = TerminateGameEngine;
Environment.Renderer = 0;
Environment.FullScreenDevice = 0;
Environment.AntiAlias = 0; // true/false - Enable full screen antialiasing
//
// Texture infomation
//
Environment.Texture_S_256 = 0;
Environment.Texture_S_128 = 0;
Environment.Texture_S_64 = 0;
Environment.Texture_S_32 = 0;
Environment.Texture_S_16 = 0;
Environment.Texture_K_256 = 0;
Environment.Texture_K_128 = 0;
Environment.Texture_K_64 = 0;
Environment.Texture_K_32 = 0;
Environment.Texture_K_16 = 0;
Environment.Texture_A_256 = 0;
Environment.Texture_A_128 = 0;
Environment.Texture_A_64 = 0;
Environment.Texture_A_32 = 0;
Environment.Texture_A_16 = 0;
}
int
__cdecl main(int argc, char *argv[])
{
InitGameOS(NULL, NULL, "blabla");
InitializeGameEngine();
/* for(int i=1;i<argc;i++)
{
if(NULL!=strstr(argv[i], "-bsp") || NULL!=strstr(argv[i], "/bsp"))
{
// doBSP = true;
}
}
*/
Compost::TexturePool::Instance->SetTexturePath("Assets\\Graphics");
Image tmpimg;
tmpimg.LoadTga("Assets\\Graphics\\Test.tga");
Compost::FeaturePool *FPool = new Compost::FeaturePool();
Register_Pointer(FPool);
Check_Object(Stuff::FileStreamManager::Instance);
Stuff::FileStream *fstr = new Stuff::FileStream;
Register_Object(fstr);
fstr->Open("Assets\\Graphics\\Test.fgd", Stuff::FileStream::ReadOnly);
FPool->LoadIndex(fstr);
Compost::FeatureGrid *FGrid = new Compost::FeatureGrid(fstr, FPool);
Register_Pointer(FGrid);
Unregister_Object(fstr);
delete fstr;
BYTE *dest_pic = new BYTE [256*256*4];
tmpimg.MaskTo(RGBMask(0xff0000,0x00ff00,0x0000ff));
BYTE *dat=tmpimg.Lock();
int i, j, xp, yp, count=0;
for(i=0;i<FGrid->GetRows();i++)
{
for(j=0;j<FGrid->GetColumns();j++)
{
FGrid->ComposeGrid(j, i, dest_pic);
//----------------------------------------------------
// Verify that the produced picture is the correct one
//----------------------------------------------------
for(yp=0;yp<256;yp++)
{
for(xp=0;xp<256;xp++)
{
int dpc = (yp*256+xp)*4;
int dc = ( (j*256+yp)*256*FGrid->GetColumns()+i*256+xp)*3;
Verify(dest_pic[dpc]==dat[dc]);
Verify(dest_pic[dpc+1]==dat[dc+1]);
Verify(dest_pic[dpc+2]==dat[dc+2]);
}
}
}
}
tmpimg.UnLock();
for(int k=0;k<16;k++)
{
for(i=0;i<FGrid->GetRows();i++)
{
for(j=0;j<FGrid->GetColumns();j++)
{
FGrid->ComposeGrid(j, i, dest_pic);
}
}
}
Unregister_Pointer(FGrid);
delete FGrid;
Unregister_Pointer(FPool);
delete FPool;
TerminateGameEngine();
ExitGameOS();
return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
Compost::FetchTextureData(Compost::Feature_Texture *tex, int index, int type)
{
return;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
Compost::FetchTextureData(Compost::Feature_Texture *tex, const char *name, int type)
{
MString fname(name);
fname += ".bid";
HGOSFILE hfile;
gos_OpenFile(&hfile, fname, READONLY);
int size = (tex->width+2)*(tex->height+2)
+ (tex->width/2+2)*(tex->height/2+2)
+ (tex->width/4+2)*(tex->height/4+2);
if(type!=Compost::Feature_Texture::FTT_1)
{
size *= 2;
}
tex->data = new BYTE [size];
gos_ReadFile(hfile, tex->data, size);
gos_CloseFile(hfile);
return;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
Compost::DestroyTextureData(Compost::Feature_Texture *tex)
{
delete [] tex->data;
}
@@ -0,0 +1,125 @@
# Microsoft Developer Studio Project File - Name="CompostTest" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=CompostTest - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "CompostTest.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "CompostTest.mak" CFG="CompostTest - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "CompostTest - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "CompostTest - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE "CompostTest - Win32 Profile" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "CompostTest - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /Zp4 /MD /W3 /GX /Zi /O2 /I "." /I "..\..\code" /I "..\..\libraries" /I "..\..\..\coretech\libraries" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "STAND_ALONE" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "CompostTest - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /G6 /Zp4 /MDd /W3 /Gm /GR /GX /Zi /Od /I "." /I "..\..\code" /I "..\..\libraries" /I "..\..\..\coretech\libraries" /D "_ARMOR" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "STAND_ALONE" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ELSEIF "$(CFG)" == "CompostTest - Win32 Profile"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Profile"
# PROP BASE Intermediate_Dir "Profile"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Profile"
# PROP Intermediate_Dir "Profile"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /G6 /MD /W3 /GX /O2 /I "..\..\..\CoreTech\Libraries" /I "..\..\Libraries" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /opt:NOREF
# SUBTRACT LINK32 /pdb:none
!ENDIF
# Begin Target
# Name "CompostTest - Win32 Release"
# Name "CompostTest - Win32 Debug"
# Name "CompostTest - Win32 Profile"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\CompostTest.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
@@ -0,0 +1,104 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Compost"=..\..\Libraries\Compost\Compost.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "CompostTest"=.\CompostTest.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name Compost
End Project Dependency
Begin Project Dependency
Project_Dep_Name DLLPlatform
End Project Dependency
Begin Project Dependency
Project_Dep_Name GameOS
End Project Dependency
Begin Project Dependency
Project_Dep_Name ImageLib
End Project Dependency
Begin Project Dependency
Project_Dep_Name Stuff
End Project Dependency
}}}
###############################################################################
Project: "DLLPlatform"=..\..\..\Coretech\Libraries\DLLPlatform\DLLPlatform.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "GameOS"=..\..\..\Coretech\Libraries\GameOS\GameOS.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "ImageLib"=..\..\Libraries\ImageLib\ImageLib.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "Stuff"=..\..\Libraries\Stuff\Stuff.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################
@@ -0,0 +1,300 @@
// CameraStateEngine.cpp ********************************************//
// Copyright Microsoft Corporation, 2001 //
// Created Owner Modification //
// -------- ------ ------------- //
// 3/7/2001 sdemar class definition for spectator state engine //
//*******************************************************************//
#include "CameraStateEngine.h"
using namespace MSRSpectator;
#include "SpectatorDebug.h"
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;
#include "MW4.hpp"
#include "MWApplication.hpp"
#include "GameOS\GameOS.hpp"
#include "Mech.hpp"
CCameraStateEngine::CCameraStateEngine()
:
m_cameraState(STATE_STD_OBSERVERMODE),
m_cameraDist(NO_RANGE),
m_fSelectState(false),
m_distanceBetween(0.0f),
m_fNewShot(true),
m_fPrevWasOverShoulder(false)
{
m_stateTimer.Initialize(3);
m_dampTimer.Expire();
}
CCameraStateEngine::~CCameraStateEngine()
{
// stubbed
}
void CCameraStateEngine::TestInstance(void) const
{
// stubbed, required for Check_Object()
}
void CCameraStateEngine::ForceStateChange()
{
m_stateTimer.Expire();
m_fSelectState = true;
NullSpectatorState();
}
void CCameraStateEngine::NullSpectatorState()
{
if (m_stateTimer.CheckExpired())
m_stateTimer.Initialize(1.5);
m_cameraState = STATE_STD_OBSERVERMODE;
m_cameraDist = NO_RANGE;
}
void CCameraStateEngine::BumpStateTimer(double addAmt)
{
double timeRemaining = m_stateTimer.GetTimeRemaining();
if (timeRemaining > 0.0 && timeRemaining < addAmt)
m_stateTimer.Initialize(timeRemaining + addAmt);
else
m_stateTimer.Initialize(addAmt);
m_fSelectState = false;
}
double CCameraStateEngine::GetDampTimerRemaining()
{
return m_dampTimer.GetTimeRemaining();
}
void CCameraStateEngine::InitDampTimer(double inTime)
{
m_dampTimer.Initialize(inTime);
}
void CCameraStateEngine::ExpireDampTimer()
{
m_dampTimer.Expire();
}
int CCameraStateEngine::GetCameraStateToExecute(bool& stateChanged, int& cameraDist)
{
// NOTE, normally in a state engine, code would execute here per state.
// However we want to keep the game specific code in the game components.
// In our case that is camera work. So all we do here is monitor the
// state timer condition as to whether its time for a new state.
if (m_stateTimer.CheckExpired())
{
m_fSelectState = true;
}
stateChanged = m_fSelectState;
// And we return the camera state to the game engine so it can deal with
// executing the current MW4 Spectator specific cameras.
// NOTE: We execute once more on current camera because we may need to store
// game parameters to transition between this and the upcoming camera.
cameraDist = m_cameraDist;
return m_cameraState;
}
void CCameraStateEngine::StateTransitionExecute(bool fIsSamePairing, float distanceBetween)
{
// Here is where we do some basic camera choosing based on distance. We also
// randomly choose between cameras good at a given distance to break things up
// a little more. Since we are depending on indeterminate action you will adjust this
// section as appropriate for the kind of action you will encounter in your game.
// If the spectator mode ever becomes a cached-time process this section will change
// dramatically as you will be able to include logic for predictive decision making.
// Such as being able to look ahead in the data stream to see an event of interest about to
// happen somewhere in the world. In those situations you may want to deliberately move
// or place a camera before the event occurs to get a more interesting shot.
if (m_fSelectState == true)
{
m_fSelectState = false;
if (distanceBetween <= MAX_SIDE_DIST)
{
if (rand() % 3 == 0)
{ // 33.3%
m_stateTimer.Initialize(1.5);
m_cameraState = STATE_FIXED_TRACKING_SHOT;
m_cameraDist = MEDIUMSHOT;
}
else
{ // 66.6%
m_stateTimer.Initialize(2.0);
m_cameraState = STATE_SIDE_SHOT;
m_cameraDist = NO_RANGE;
}
}
else if ((MAX_SIDE_DIST < distanceBetween) && (distanceBetween <= 210.0f))
{
// over shoulder shots require some attention. Its possible for our hero
// to be engaging two or more enemys in random order. To keep the camera
// from radically jogging from one to another enemy, we use a transitioning
// shot.
if (m_fPrevWasOverShoulder || ((rand() % 3) != 0))
{ // 66.6%
m_fPrevWasOverShoulder = false;
m_stateTimer.Initialize(1.0);
m_cameraState = STATE_FRONT_SHOT;
m_cameraDist = CLOSESHOT;
}
else
{ // 33.3%
m_fPrevWasOverShoulder = true;
m_stateTimer.Initialize(3.0);
m_cameraState = STATE_OVERSHOULDER_SHOT;
m_cameraDist = MEDIUMSHOT;
}
}
else if ((210.0f < distanceBetween) && (distanceBetween <= 290.0f))
{
int cameraState, cameraDist;
do {
switch(rand() % 3) {
case 0:
cameraState = STATE_FRONT_SHOT;
break;
case 1:
cameraState = STATE_OVERSHOULDER_SHOT;
break;
default:
cameraState = STATE_FIXED_TRACKING_SHOT;
break;
}
switch(rand() % 3) {
case 0:
cameraDist = CLOSESHOT;
break;
case 1:
cameraDist = MEDIUMSHOT;
break;
default:
cameraDist = LONGSHOT;
break;
}
} while(((cameraState == m_cameraState) && (cameraDist == m_cameraDist)) || ((cameraState == STATE_OVERSHOULDER_SHOT) && m_fPrevWasOverShoulder));
switch(cameraState) {
default:
m_fPrevWasOverShoulder = false;
m_stateTimer.Initialize(2.0);
break;
case STATE_STD_OBSERVERMODE:
m_fPrevWasOverShoulder = true;
m_stateTimer.Initialize(3.0);
break;
}
m_cameraState = cameraState;
//m_cameraDist = cameraDist;
if (cameraState == STATE_FRONT_SHOT) {
m_cameraDist = MEDIUMSHOT;
} else {
m_cameraDist = LONGSHOT;
}
}
else
{
int cameraState, cameraDist;
do {
switch(rand() % 3) {
case 0:
cameraState = STATE_FRONT_SHOT;
break;
case 1:
cameraState = STATE_OVERSHOULDER_SHOT;
break;
case 2:
cameraState = STATE_FIXED_TRACKING_SHOT;
default:
cameraState = STATE_STD_OBSERVERMODE;
break;
}
if (cameraState == STATE_STD_OBSERVERMODE) {
cameraDist = NO_RANGE;
} else {
switch(rand() % 3) {
case 0:
cameraDist = CLOSESHOT;
break;
case 1:
cameraDist = MEDIUMSHOT;
break;
default:
cameraDist = LONGSHOT;
break;
}
}
} while(((cameraState == m_cameraState) && (cameraDist == m_cameraDist)) || ((cameraState == STATE_OVERSHOULDER_SHOT) && m_fPrevWasOverShoulder));
switch(cameraState) {
default:
m_fPrevWasOverShoulder = false;
m_stateTimer.Initialize(1.5);
break;
case STATE_FIXED_TRACKING_SHOT:
m_fPrevWasOverShoulder = false;
m_stateTimer.Initialize(2.0);
break;
case STATE_STD_OBSERVERMODE:
m_fPrevWasOverShoulder = true;
m_stateTimer.Initialize(3.0);
break;
}
m_cameraState = cameraState;
//m_cameraDist = cameraDist;
switch (cameraState)
{
case STATE_FIXED_TRACKING_SHOT:
m_cameraDist = LONGSHOT;
break;
case STATE_FRONT_SHOT:
m_cameraDist = CLOSESHOT;
break;
case STATE_OVERSHOULDER_SHOT:
m_cameraDist = CLOSESHOT;
break;
case STATE_STD_OBSERVERMODE:
m_cameraDist = NO_RANGE;
break;
}
}
}
}
bool CCameraStateEngine::GetIsTimeToSelectNewShot()
{
return m_fSelectState;
}
bool CCameraStateEngine::fIsValidSideDistance(float dist) const
{
return (dist >= 4.0f && dist <= MAX_SIDE_DIST);
}
@@ -0,0 +1,85 @@
// CameraStateEngine.h **********************************************//
// Created Owner Modification //
// Copyright Microsoft Corporation, 2002 //
// -------- ------ ------------- //
// 3/7/2002 sdemar provides FSM for spectator camera mgt //
//*******************************************************************//
#if !defined(MSR_CAMERA_STATE_ENGINE_)
#define MSR_CAMERA_STATE_ENGINE_
#include "SpectatorTimer.hpp"
#include "MW4\MW4Headers.hpp"
#include "Adept\GlobalPointerManager.hpp"
using namespace Adept;
#include <GameOS\GameOS.hpp>
//**************************************************
namespace MSRSpectator
{
class CCameraStateEngine
{
public:
// public methods
CCameraStateEngine(); // ctor
~CCameraStateEngine(); // dtor
int GetCameraStateToExecute(bool& stateChanged, int& cameraDist); // returns camera shot specific state to game engine
void StateTransitionExecute(bool fIsSamePairing, float distanceBetween); // fIsSamePairing is an overide condition for overShoulder stuff
bool GetIsTimeToSelectNewShot(); // gets boolean if new shot initialized
void ForceStateChange(); // triggers an overidden state change for special cases
void BumpStateTimer(double addAmt); // when transitioning in overshoulder shots, may need to add time to complete transition
double GetDampTimerRemaining(); // returns the amount of time remaining for current camera transition
void InitDampTimer(double); // initializes the current camera transition timer
void ExpireDampTimer(); // expires the current camera transition timer
bool fIsValidSideDistance(float dist) const; // true if distance value legal for side camera aspect view
void NullSpectatorState(); // shifts camera state to std observermode when no enemy of interest
static CCameraStateEngine* GetInstance() // required to support MW4's global pointer manager
{
return reinterpret_cast<CCameraStateEngine*>( GlobalPointers::GetGlobalPointer(CameraStateEnginePointerIndex));
};
void TestInstance(void) const; // required to support MW4'S Check_Object()
// public data
enum // exposed state constants
{
STATE_FRONT_SHOT,
STATE_OVERSHOULDER_SHOT,
STATE_FIXED_TRACKING_SHOT,
STATE_SIDE_SHOT,
STATE_STD_OBSERVERMODE,
STATE_DEATH_SEQUENCE_START,
STATE_DEATH_SEQUENCE_TRANS,
STATE_DEATH_SEQUENCE_SHOT,
};
enum
{
NO_RANGE = -1,
CLOSESHOT = 0,
MEDIUMSHOT = 1,
LONGSHOT = 2,
};
private:
// private data
CSpectatorTimer m_stateTimer; // determines when to transition to new camera state
CSpectatorTimer m_dampTimer; // used for camera damping transitions in overshoulder shots
int m_cameraState; // current camera state
int m_cameraDist;
bool m_fSelectState; // true if need to get new state
bool m_fNewShot; // true only when shot is first initialized
bool m_fPrevWasOverShoulder; // true if last camera was an over shoulder shot type
float m_distanceBetween; // distance between entities, used to determine camera shots
enum {MAX_SIDE_DIST = 90}; // maximum distance between hero and enemy for side shots
char bigThing[256]; // MW4 memory allocation doesn't like small things
};
}
#endif // !defined(MSR_CAMERA_STATE_ENGINE_)
@@ -0,0 +1,151 @@
# Microsoft Developer Studio Project File - Name="MSRSpectator" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=MSRSpectator - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "MSRSpectator.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "MSRSpectator.mak" CFG="MSRSpectator - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "MSRSpectator - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "MSRSpectator - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "MSRSpectator - Win32 Profile" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "MSRSpectator - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\Content" /I "." /I "..\..\Code" /I "..\..\Libraries" /I "..\..\..\CoreTech\Libraries" /I "..\..\Libraries\stlport" /I "..\MW4" /I "..\..\..\CoreTech\Libraries\GameOS" /D "_MBCS" /D "_LIB" /D "NDEBUG" /D "WIN32" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"../../../rel.bin\MSRSpectator.lib"
!ELSEIF "$(CFG)" == "MSRSpectator - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\Content" /I "." /I "..\..\Code" /I "..\..\Libraries" /I "..\..\..\CoreTech\Libraries" /I "..\..\Libraries\stlport" /I "..\MW4" /I "..\..\..\CoreTech\Libraries\GameOS" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"../../../dbg.bin\MSRSpectator.lib"
!ELSEIF "$(CFG)" == "MSRSpectator - Win32 Profile"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "MSRSpectator___Win32_Profile"
# PROP BASE Intermediate_Dir "MSRSpectator___Win32_Profile"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "MSRSpectator___Win32_Profile"
# PROP Intermediate_Dir "MSRSpectator___Win32_Profile"
# PROP Target_Dir ""
MTL=midl.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /I "..\..\Content" /I "." /I "..\..\Code" /I "..\..\Libraries" /I "..\..\..\CoreTech\Libraries" /I "..\..\Libraries\stlport" /I "..\MW4" /I "..\..\..\CoreTech\Libraries\GameOS" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\Content" /I "." /I "..\..\Code" /I "..\..\Libraries" /I "..\..\..\CoreTech\Libraries" /I "..\..\Libraries\stlport" /I "..\MW4" /I "..\..\..\CoreTech\Libraries\GameOS" /D "LAB_ONLY" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"../../../rel.bin\MSRSpectator.lib"
# ADD LIB32 /nologo /out:"../../../rel.bin\MSRSpectator.lib"
!ENDIF
# Begin Target
# Name "MSRSpectator - Win32 Release"
# Name "MSRSpectator - Win32 Debug"
# Name "MSRSpectator - Win32 Profile"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\CameraStateEngine.cpp
# End Source File
# Begin Source File
SOURCE=.\SpectatorDebug.cpp
# End Source File
# Begin Source File
SOURCE=.\SpectatorStateEngine.cpp
# End Source File
# Begin Source File
SOURCE=.\SpectatorTimer.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\CameraStateEngine.h
# End Source File
# Begin Source File
SOURCE=.\SpectatorDebug.h
# End Source File
# Begin Source File
SOURCE=.\SpectatorStateEngine.hpp
# End Source File
# Begin Source File
SOURCE=.\SpectatorTimer.hpp
# End Source File
# End Group
# End Target
# End Project
@@ -0,0 +1,57 @@
// SpectatorDebug.cpp ***********************************************//
// Copyright Microsoft Corporation, 2001 //
// Created Owner Modification //
// -------- ------ ------------- //
// 3/29/2001 sdemar provide some output window debugging //
//*******************************************************************//
#include "SpectatorDebug.h"
#include <stdlib.h>
#include <string>
using namespace std;
extern "C" void __stdcall OutputDebugStringA( const char * String );
void SpecDebug1(const char* x)
{
#if _DEBUG
OutputDebugStringA(x);
OutputDebugStringA("\n");
#endif
}
void SpecDebug2(const char* x, const char* y)
{
#if _DEBUG
OutputDebugStringA(x);
OutputDebugStringA(y);
OutputDebugStringA("\n");
#endif
}
void SpecDebugInt(const char* x, int y)
{
#if _DEBUG
OutputDebugStringA(x);
char num[80];
_itoa( y, num, 10 );
OutputDebugStringA(num);
OutputDebugStringA("\n");
#endif
}
void SpecDebugFlt(const char* x, double y)
{
#if _DEBUG
OutputDebugStringA(x);
char num[80];
_gcvt( y, 12, num );
OutputDebugStringA(num);
OutputDebugStringA("\n");
#endif
}
@@ -0,0 +1,17 @@
// SpectatorDebug.h *************************************************//
// Created Owner Modification //
// Copyright Microsoft Corporation, 2002 //
// -------- ------ ------------- //
// 3/25/2002 sdemar provides debug messaging //
//*******************************************************************//
#if !defined(MSR_SPECTATOR_DEBUG_)
#define MSR_SPECTATOR_DEBUG_
// general purpose IDE output window functions
void SpecDebug1(const char* x); // outputs a string, inserts newline at end
void SpecDebug2(const char* x, const char* y); // outputs 2 strings, inserts newline at end
void SpecDebugInt(const char* x, int y); // outputs string and integer, inserts newline at end
void SpecDebugFlt(const char* x, double y); // outputs string and scalar, inserts newline at end
#endif // !defined(MSR_SPECTATOR_DEBUG_)
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More