Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// FSM.cpp: implementation of the CFSM2 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <algorithm>
|
||||
#include "FSM.h"
|
||||
#include "FSMState.h"
|
||||
|
||||
CFSM CFSM::ms_this;
|
||||
|
||||
CFSM::CFSM(void)
|
||||
: m_nStateNum(0)
|
||||
{
|
||||
std::fill_n(m_lpFSMState, int(MAX_STATE), reinterpret_cast<CFSMState*>(0));
|
||||
}
|
||||
|
||||
CFSM::~CFSM()
|
||||
{
|
||||
CFSMState** lppFSMPastEnd = m_lpFSMState + MAX_STATE;
|
||||
for(CFSMState** lppFSM = m_lpFSMState; lppFSM != lppFSMPastEnd; ++lppFSM)
|
||||
{
|
||||
delete *lppFSM;
|
||||
*lppFSM = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CFSM::StateTransition(int nCrurrentState, int Input)
|
||||
{
|
||||
if (!nCrurrentState)
|
||||
{
|
||||
return nCrurrentState;
|
||||
}
|
||||
|
||||
CFSMState* lpState = GetState(nCrurrentState);
|
||||
if (NULL == lpState)
|
||||
{
|
||||
return nCrurrentState;
|
||||
}
|
||||
|
||||
nCrurrentState = lpState->GetOutput(Input);
|
||||
return nCrurrentState;
|
||||
}
|
||||
|
||||
|
||||
CFSMState* CFSM::GetState(int StateID)
|
||||
{
|
||||
CFSMState** lppFSMPastEnd = m_lpFSMState + MAX_STATE;
|
||||
for(CFSMState** lppFSM = m_lpFSMState; lppFSM != lppFSMPastEnd; ++lppFSM)
|
||||
{
|
||||
if(NULL == *lppFSM)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(StateID == (*lppFSM)->GetID())
|
||||
{
|
||||
return *lppFSM;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool CFSM::AddState(CFSMState* lpNewState)
|
||||
{
|
||||
if(m_nStateNum >= MAX_STATE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_lpFSMState[m_nStateNum++] = lpNewState;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// FSM.h: interface for the CFSM class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_FSM_H__5BDFA770_7869_4B08_B0BC_D7C6AC789C9D__INCLUDED_)
|
||||
#define AFX_FSM_H__5BDFA770_7869_4B08_B0BC_D7C6AC789C9D__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
#include <Pattern/Singleton.h>
|
||||
#include "FSMState.h"
|
||||
|
||||
|
||||
enum MONSTER_STATE_OR_INPUT
|
||||
{
|
||||
STATE_ID_NULL = 0,
|
||||
STATE_ID_NORMAL,
|
||||
STATE_ID_ATTACK,
|
||||
STATE_ID_RETURN,
|
||||
STATE_ID_ESCAPE,
|
||||
STATE_ID_DIE,
|
||||
|
||||
INPUT_ID_SEEN_PLAYER = 100,
|
||||
INPUT_ID_LOW_HP,
|
||||
INPUT_ID_ZERO_HP,
|
||||
INPUT_ID_LEAVE_PLAYER,
|
||||
INPUT_ID_ARRIVAL_SITE,
|
||||
INPUT_ID_ATTACKED_PLAYER,
|
||||
INPUT_ID_CMD_ATTACK,
|
||||
INPUT_ID_CMD_ESCAPE
|
||||
};
|
||||
|
||||
|
||||
class CFSM : public CSingleton<CFSM>
|
||||
{
|
||||
public:
|
||||
|
||||
enum { MAX_STATE = 8 };
|
||||
|
||||
~CFSM(void); // clean up memory usage
|
||||
|
||||
bool AddState(CFSMState* lpNewState); // add a FSMstate object pointer to the map
|
||||
CFSMState* GetState(int StateID); // return the FSMstate object pointer
|
||||
|
||||
int StateTransition(int nCrurrentState, int Input); // perform a state transition based on input and current state
|
||||
|
||||
protected:
|
||||
|
||||
CFSM(void); // set initial state of the FSM
|
||||
|
||||
int m_nStateNum;
|
||||
CFSMState* m_lpFSMState[MAX_STATE]; // map containing all states of this FSM
|
||||
|
||||
static CFSM ms_this;
|
||||
};
|
||||
|
||||
|
||||
#endif // !defined(AFX_FSM_H__5BDFA770_7869_4B08_B0BC_D7C6AC789C9D__INCLUDED_)
|
||||
@@ -0,0 +1,130 @@
|
||||
// FSMState.cpp: implementation of the CFSMState2 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "FSMState.h"
|
||||
|
||||
|
||||
CFSMState::CFSMState(int StateID, int Transitions)
|
||||
: m_dwStateID(StateID), m_dwNumberOfTransistions((Transitions) ? Transitions : 1)
|
||||
{
|
||||
m_pdwInputs = new int[m_dwNumberOfTransistions];
|
||||
if (NULL == m_pdwInputs)
|
||||
{
|
||||
ERRLOG1(g_Log, "m_pdwInputs<EFBFBD><EFBFBD> <20><EFBFBD><DEB8><EFBFBD> <20>Ҵ翡 <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ϴ<EFBFBD>. <20>Ҵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d<><64> <20>Դϴ<D4B4>.",
|
||||
m_dwNumberOfTransistions);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::fill_n(m_pdwInputs, m_dwNumberOfTransistions, 0);
|
||||
|
||||
m_pdwOutputState = new int[m_dwNumberOfTransistions];
|
||||
if (NULL == m_pdwOutputState)
|
||||
{
|
||||
ERRLOG1(g_Log, "m_pdwOutputState<EFBFBD><EFBFBD> <20><EFBFBD><DEB8><EFBFBD> <20>Ҵ翡 <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ϴ<EFBFBD>. <20>Ҵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d<><64> <20>Դϴ<D4B4>.",
|
||||
m_dwNumberOfTransistions);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::fill_n(m_pdwOutputState, m_dwNumberOfTransistions, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CFSMState::~CFSMState()
|
||||
{
|
||||
if(NULL != m_pdwInputs)
|
||||
{
|
||||
delete m_pdwInputs;
|
||||
m_pdwInputs = NULL;
|
||||
}
|
||||
|
||||
if(NULL != m_pdwOutputState)
|
||||
{
|
||||
delete m_pdwOutputState;
|
||||
m_pdwOutputState = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CFSMState::AddTransition(int Input, int OutputID)
|
||||
{
|
||||
int nTransition = 0;
|
||||
for(; nTransition < m_dwNumberOfTransistions; ++nTransition)
|
||||
{
|
||||
if(0 == m_pdwOutputState[nTransition])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(nTransition >= m_dwNumberOfTransistions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_pdwInputs[nTransition] = Input;
|
||||
m_pdwOutputState[nTransition] = OutputID;
|
||||
}
|
||||
|
||||
|
||||
int CFSMState::GetOutput(int Input)
|
||||
{
|
||||
int OutputID = m_dwStateID; // output state to be returned
|
||||
|
||||
for(int nTransition = 0;
|
||||
nTransition < m_dwNumberOfTransistions; ++nTransition)
|
||||
{
|
||||
if(0 == m_pdwOutputState[nTransition])
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if(Input == m_pdwInputs[nTransition])
|
||||
{
|
||||
OutputID = m_pdwOutputState[nTransition]; // output state id
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return OutputID;
|
||||
}
|
||||
|
||||
|
||||
void CFSMState::DeleteTransition(int OutputID)
|
||||
{
|
||||
int nTransition = 0;
|
||||
for(;nTransition < m_dwNumberOfTransistions; ++nTransition)
|
||||
{
|
||||
if(OutputID == m_pdwOutputState[nTransition])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(nTransition >= m_dwNumberOfTransistions)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_pdwInputs[nTransition] = 0;
|
||||
m_pdwOutputState[nTransition] = 0;
|
||||
|
||||
for(;nTransition < (m_dwNumberOfTransistions - 1); ++nTransition)
|
||||
{
|
||||
if (!m_pdwOutputState[nTransition])
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
m_pdwInputs[nTransition] = m_pdwInputs[nTransition+1];
|
||||
m_pdwOutputState[nTransition] = m_pdwOutputState[nTransition+1];
|
||||
}
|
||||
|
||||
m_pdwInputs[nTransition] = 0;
|
||||
m_pdwOutputState[nTransition] = 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// FSMState.h: interface for the CFSMState class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_FSMSTATE_H__4D5ECC39_C7A5_47E7_A774_9E79707B18D8__INCLUDED_)
|
||||
#define AFX_FSMSTATE_H__4D5ECC39_C7A5_47E7_A774_9E79707B18D8__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
class CFSMState
|
||||
{
|
||||
private:
|
||||
|
||||
int m_dwNumberOfTransistions; // maximum number of states supported by this state
|
||||
int *m_pdwInputs; // input array for tranistions
|
||||
int *m_pdwOutputState; // output state array
|
||||
int m_dwStateID; // the unique ID of this state
|
||||
|
||||
int FindTransitionIndex(int nID);
|
||||
|
||||
public:
|
||||
|
||||
explicit CFSMState(int StateID, int Transitions);
|
||||
~CFSMState(void);
|
||||
|
||||
void AddTransition(int Input, int OutputID);
|
||||
void DeleteTransition(int OutputID);
|
||||
|
||||
int GetOutput(int Input);
|
||||
|
||||
inline int GetID(void) { return m_dwStateID; }
|
||||
};
|
||||
|
||||
|
||||
#endif // !defined(AFX_FSMSTATE_H__4D5ECC39_C7A5_47E7_A774_9E79707B18D8__INCLUDED_)
|
||||
Reference in New Issue
Block a user