Skip to content

Commit 34edf01

Browse files
luciusDXLpsi29a
authored andcommitted
initial drop from LuciusDXL
1 parent 19143bc commit 34edf01

File tree

291 files changed

+49367
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

291 files changed

+49367
-1
lines changed

BloodXL/BloodXL_Game.cpp

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#include "BloodXL_Game.h"
2+
#include "BloodXL_Player.h"
3+
#include "../fileformats/ArchiveTypes.h"
4+
#include "../fileformats/CellTypes.h"
5+
#include "../ui/Console.h"
6+
7+
//Game instance used for console commands.
8+
BloodXL_Game *BloodXL_Game::s_pGame_Console=NULL;
9+
10+
BloodXL_Game::BloodXL_Game(const XLEngine_Plugin_API *API)
11+
{
12+
m_pAPI = API;
13+
14+
m_nVersionMajor = 0;
15+
m_nVersionMinor = 10;
16+
17+
m_pAPI->SetConsoleColor(0.20f, 0.025f, 0.025f, 0.85f);
18+
19+
m_pAPI->SetGameData("BloodXL", m_nVersionMajor, m_nVersionMinor);
20+
m_pAPI->PrintToConsole("Starting BloodXL version %d.%03d", m_nVersionMajor, m_nVersionMinor);
21+
22+
//Add game specific console commands.
23+
s_pGame_Console = this;
24+
m_pAPI->RegisterConsoleCmd("g_version", (void *)CC_GameVersion, Console::CTYPE_FUNCTION, "Prints out the name and version of the currently loaded game.", this);
25+
m_pAPI->RegisterConsoleCmd("g_loadmap", (void *)CC_LoadMap, Console::CTYPE_FUNCTION, "Load a map, for example: g_loadmap e1m1", this);
26+
m_pAPI->RegisterConsoleCmd("g_passThruAdjoins", (void *)CC_PassThruAdjoins, Console::CTYPE_FUNCTION, "Always pass through adjoins, 0 = default.", this);
27+
28+
m_pAPI->RegisterScriptFunc("void Game_NewGame(int, int)", asFUNCTION(SC_Game_NewGameSettings));
29+
m_pAPI->RegisterScriptFunc("void Game_LoadMap(string &in)", asFUNCTION(SC_Game_LoadMap));
30+
31+
//We only worry about the UI scripts, palettes, color maps and so on if we're running a client.
32+
if ( m_pAPI->IsServer() == XL_FALSE )
33+
{
34+
//Start the UI script for title screen.
35+
m_pAPI->Start_UI_Script( "BloodXL/CoreUI.as" );
36+
37+
//load the game palette so that the UI is correct.
38+
u8 *pal = xlNew u8[768*3+1];
39+
u8 *new_pal = xlNew u8[768*3+1];
40+
if ( m_pAPI->GameFile_Open(ARCHIVETYPE_RFF, "BLOOD.RFF", "BLOOD.PAL") )
41+
{
42+
u32 len = m_pAPI->GameFile_GetLength();
43+
m_pAPI->GameFile_Read(pal, len);
44+
m_pAPI->GameFile_Close();
45+
46+
m_pAPI->SetGamePalette( 0, pal, 768, 255 );
47+
}
48+
49+
static const char *aszPLU_Files[]=
50+
{
51+
"NORMAL.PLU",
52+
"SATURATE.PLU",
53+
"BEAST.PLU",
54+
"TOMMY.PLU",
55+
"SPIDER3.PLU",
56+
"GRAY.PLU",
57+
"GRAYISH.PLU",
58+
"SPIDER1.PLU",
59+
"SPIDER2.PLU",
60+
"FLAME.PLU",
61+
"COLD.PLU",
62+
"P1.PLU",
63+
"P2.PLU",
64+
"P3.PLU",
65+
"P4.PLU"
66+
};
67+
//load the "PLU" files for different palettes.
68+
u8 *pData = xlNew u8[16385];
69+
for (u32 i=1; i<14; i++)
70+
{
71+
if ( m_pAPI->GameFile_Open(ARCHIVETYPE_RFF, "BLOOD.RFF", aszPLU_Files[i]) )
72+
{
73+
u32 len = m_pAPI->GameFile_GetLength();
74+
m_pAPI->GameFile_Read(pData, len);
75+
m_pAPI->GameFile_Close();
76+
77+
for (u32 c=0; c<256; c++)
78+
{
79+
new_pal[ c*3 + 0 ] = pal[ pData[c]*3 + 0 ];
80+
new_pal[ c*3 + 1 ] = pal[ pData[c]*3 + 1 ];
81+
new_pal[ c*3 + 2 ] = pal[ pData[c]*3 + 2 ];
82+
}
83+
84+
m_pAPI->SetGamePalette( i, new_pal, 768, 255 );
85+
}
86+
}
87+
xlDelete [] pData;
88+
xlDelete [] pal;
89+
xlDelete [] new_pal;
90+
}
91+
92+
m_Player = xlNew BloodXL_Player(API);
93+
94+
//If we are running a server, then just load the startup map.
95+
if ( m_pAPI->IsServer() == XL_TRUE )
96+
{
97+
SC_Game_LoadMap( m_pAPI->Startup_GetStartMap() );
98+
}
99+
}
100+
101+
BloodXL_Game::~BloodXL_Game(void)
102+
{
103+
if ( m_Player )
104+
{
105+
xlDelete m_Player;
106+
m_Player = NULL;
107+
}
108+
}
109+
110+
void BloodXL_Game::FixedUpdate()
111+
{
112+
}
113+
114+
void BloodXL_Game::VariableUpdate(float dt)
115+
{
116+
}
117+
118+
void BloodXL_Game::PreRender(float dt)
119+
{
120+
}
121+
122+
void BloodXL_Game::PostRender(float dt)
123+
{
124+
}
125+
126+
void BloodXL_Game::KeyDown(s32 key)
127+
{
128+
m_Player->KeyDown(key);
129+
}
130+
131+
void BloodXL_Game::NewGame(s32 episode, s32 difficulty)
132+
{
133+
char szMapName[32];
134+
sprintf(szMapName, "E%dM1.MAP", episode+1);
135+
136+
m_pAPI->World_UnloadAllCells();
137+
m_pAPI->World_LoadCell( CELLTYPE_BLOOD_MAP, ARCHIVETYPE_RFF, "BLOOD.RFF", szMapName, 0, 0 );
138+
}
139+
140+
/************************
141+
*** Script Commands ***
142+
************************/
143+
void BloodXL_Game::SC_Game_NewGameSettings(int episode, int difficulty)
144+
{
145+
s_pGame_Console->NewGame(episode, difficulty);
146+
}
147+
148+
void BloodXL_Game::SC_Game_LoadMap(const string& mapName)
149+
{
150+
string mapNameFinal = mapName + ".MAP";
151+
s_pGame_Console->m_pAPI->World_UnloadAllCells();
152+
s_pGame_Console->m_pAPI->World_LoadCell( CELLTYPE_BLOOD_MAP, ARCHIVETYPE_RFF, "BLOOD.RFF", mapNameFinal.c_str(), 0, 0 );
153+
}
154+
155+
/************************
156+
*** Console commands ***
157+
************************/
158+
void BloodXL_Game::CC_GameVersion(const vector<string>& args, void *pUserData)
159+
{
160+
s_pGame_Console->m_pAPI->PrintToConsole("BloodXL version %d.%03d", s_pGame_Console->m_nVersionMajor, s_pGame_Console->m_nVersionMinor);
161+
}
162+
163+
void BloodXL_Game::CC_LoadMap(const vector<string>& args, void *pUserData)
164+
{
165+
BloodXL_Game *pGame = (BloodXL_Game *)pUserData;
166+
if ( args.size() < 2 )
167+
{
168+
s_pGame_Console->m_pAPI->PrintToConsole("Usage: g_loadmap mapName");
169+
}
170+
else
171+
{
172+
string mapName = args[1] + ".MAP";
173+
pGame->m_pAPI->World_UnloadAllCells();
174+
pGame->m_pAPI->World_LoadCell( CELLTYPE_BLOOD_MAP, ARCHIVETYPE_RFF, "BLOOD.RFF", mapName.c_str(), 0, 0 );
175+
}
176+
}
177+
178+
void BloodXL_Game::CC_PassThruAdjoins(const vector<string>& args, void *pUserData)
179+
{
180+
BloodXL_Game *pGame = (BloodXL_Game *)pUserData;
181+
182+
bool bPassThru = false; //if there are no arguments then just disable (the "default")
183+
if ( args.size() > 1 )
184+
{
185+
const char *arg = args[1].c_str();
186+
if ( arg[0] == '1' )
187+
bPassThru = true;
188+
}
189+
190+
pGame->m_Player->SetPassthruAdjoins( bPassThru );
191+
}

BloodXL/BloodXL_Game.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef BLOODXL_GAME_H
2+
#define BLOODXL_GAME_H
3+
4+
#include "../plugin_framework/plugin.h"
5+
#include <string>
6+
7+
using namespace std;
8+
class BloodXL_Player;
9+
10+
class BloodXL_Game
11+
{
12+
public:
13+
BloodXL_Game(const XLEngine_Plugin_API *API);
14+
~BloodXL_Game(void);
15+
16+
void FixedUpdate();
17+
void VariableUpdate(float dt);
18+
void PreRender(float dt);
19+
void PostRender(float dt);
20+
21+
void KeyDown(s32 key);
22+
23+
void GetVersion(s32& major, s32& minor) { major = m_nVersionMajor; minor = m_nVersionMinor; }
24+
25+
void NewGame(s32 episode, s32 difficulty);
26+
27+
private:
28+
const XLEngine_Plugin_API *m_pAPI;
29+
s32 m_nVersionMajor;
30+
s32 m_nVersionMinor;
31+
BloodXL_Player *m_Player;
32+
33+
//Script commands
34+
static void SC_Game_NewGameSettings(int episode, int difficulty);
35+
static void SC_Game_LoadMap(const string& mapName);
36+
37+
//Console commands
38+
static BloodXL_Game *s_pGame_Console;
39+
static void CC_GameVersion(const vector<string>& args, void *pUserData);
40+
static void CC_LoadMap(const vector<string>& args, void *pUserData);
41+
static void CC_PassThruAdjoins(const vector<string>& args, void *pUserData);
42+
};
43+
44+
#endif //BLOODXL_GAME_H

0 commit comments

Comments
 (0)