Browse Source

Started reimplementing game engine commands

Thomas Buck 10 years ago
parent
commit
841824229e
4 changed files with 77 additions and 10 deletions
  1. 2
    0
      include/Game.h
  2. 62
    3
      src/Game.cpp
  3. 12
    5
      src/OpenRaider.cpp
  4. 1
    2
      src/Texture.cpp

+ 2
- 0
include/Game.h View File

@@ -42,6 +42,8 @@ public:
42 42
 
43 43
     void display();
44 44
 
45
+    int command(std::vector<char *> *args);
46
+
45 47
     World mWorld;
46 48
     entity_t *mLara;
47 49
     Render *mRender;

+ 62
- 3
src/Game.cpp View File

@@ -16,6 +16,7 @@
16 16
 #include <algorithm>
17 17
 #include <map>
18 18
 #include <vector>
19
+#include <cstdlib>
19 20
 
20 21
 #include "main.h"
21 22
 #include "Console.h"
@@ -111,7 +112,8 @@ int Game::loadLevel(const char *level) {
111 112
                 break;
112 113
             }
113 114
         }
114
-        strcpy(tmp + dir, "MAIN.SFX\0"); // overwrite the name itself with MAIN.SFX
115
+        strcpy(tmp + dir, "MAIN.SFX"); // overwrite the name itself with MAIN.SFX
116
+        tmp[dir + 8] = '\0';
115 117
         error = mTombRaider.loadSFX(tmp);
116 118
         if (error != 0) {
117 119
             gOpenRaider->mConsole->print("Could not load %s", tmp);
@@ -130,6 +132,12 @@ int Game::loadLevel(const char *level) {
130 132
     // Free pak file
131 133
     mTombRaider.reset();
132 134
 
135
+    // Check if the level contains Lara
136
+    if (mLara == NULL) {
137
+        gOpenRaider->mConsole->print("Can't find Lara entity in level pak!");
138
+        return -1;
139
+    }
140
+
133 141
     mLoaded = true;
134 142
     mRender->setMode(Render::modeVertexLight);
135 143
     return 0;
@@ -151,6 +159,7 @@ void Game::handleAction(ActionEvents action, bool isFinished) {
151 159
 
152 160
 void Game::handleMouseMotion(int xrel, int yrel) {
153 161
     if (mLoaded) {
162
+        // Move Camera on X Axis
154 163
         if (xrel > 0)
155 164
             while (xrel-- > 0)
156 165
                 mCamera->command(CAMERA_ROTATE_RIGHT);
@@ -158,6 +167,7 @@ void Game::handleMouseMotion(int xrel, int yrel) {
158 167
             while (xrel++ < 0)
159 168
                 mCamera->command(CAMERA_ROTATE_LEFT);
160 169
 
170
+        // Move Camera on Y Axis
161 171
         if (yrel > 0)
162 172
             while (yrel-- > 0)
163 173
                 mCamera->command(CAMERA_ROTATE_UP);
@@ -165,6 +175,7 @@ void Game::handleMouseMotion(int xrel, int yrel) {
165 175
             while (yrel++ < 0)
166 176
                 mCamera->command(CAMERA_ROTATE_DOWN);
167 177
 
178
+        // Fix Laras rotation
168 179
         if (mLara) {
169 180
             mLara->angles[1] = mCamera->getRadianYaw();
170 181
             mLara->angles[2] = mCamera->getRadianPitch();
@@ -176,6 +187,54 @@ void Game::display() {
176 187
     mRender->Display();
177 188
 }
178 189
 
190
+int Game::command(std::vector<char *> *args) {
191
+    if (args->size() < 1) {
192
+        gOpenRaider->mConsole->print("Invalid use of game-command!");
193
+        return -1;
194
+    }
195
+
196
+    char *cmd = args->at(0);
197
+    if (strcmp(cmd, "noclip") == 0) {
198
+        mLara->moveType = worldMoveType_noClipping;
199
+        gOpenRaider->mConsole->print("Lara is noclipping...");
200
+    } else if (strcmp(cmd, "fly") == 0) {
201
+        mLara->moveType = worldMoveType_fly;
202
+        gOpenRaider->mConsole->print("Lara is flying...");
203
+    } else if (strcmp(cmd, "walk") == 0) {
204
+        mLara->moveType = worldMoveType_walk;
205
+        gOpenRaider->mConsole->print("Lara is walking...");
206
+    } else if (strcmp(cmd, "sound") == 0) {
207
+        if (args->size() > 1) {
208
+            gOpenRaider->mSound->play(atoi(args->at(1)));
209
+        } else {
210
+            gOpenRaider->mConsole->print("Invalid use of sound command!");
211
+            return -2;
212
+        }
213
+    } else if (strcmp(cmd, "help") == 0) {
214
+        if (args->size() < 2) {
215
+            gOpenRaider->mConsole->print("game-command Usage:");
216
+            gOpenRaider->mConsole->print("  game COMMAND");
217
+            gOpenRaider->mConsole->print("Available commands:");
218
+            gOpenRaider->mConsole->print("  walk");
219
+            gOpenRaider->mConsole->print("  fly");
220
+            gOpenRaider->mConsole->print("  noclip");
221
+            gOpenRaider->mConsole->print("  sound INT");
222
+        } else if (strcmp(args->at(1), "sound") == 0) {
223
+            gOpenRaider->mConsole->print("game-sound-command Usage:");
224
+            gOpenRaider->mConsole->print("  game sound INT");
225
+            gOpenRaider->mConsole->print("Where INT is a valid sound ID integer");
226
+        } else {
227
+            gOpenRaider->mConsole->print("No help available for game %s.", args->at(1));
228
+            return -3;
229
+        }
230
+    } else {
231
+        gOpenRaider->mConsole->print("Invalid use of game-command (%s)!", cmd);
232
+        return -4;
233
+    }
234
+
235
+    return 0;
236
+}
237
+
179 238
 void Game::processPakSounds()
180 239
 {
181 240
     unsigned char *riff;
@@ -700,7 +759,7 @@ void Game::processMoveable(int index, int i, int *ent,
700 759
                     r_model->ponyOff2 = 0;
701 760
 
702 761
                     mRender->setFlags(Render::fRenderPonytail);
703
-                    gOpenRaider->mConsole->print("Found ponytail?\n");
762
+                    gOpenRaider->mConsole->print("Found ponytail?");
704 763
                 }
705 764
                 break;
706 765
         }
@@ -822,7 +881,7 @@ void Game::processMoveable(int index, int i, int *ent,
822 881
             //   if (frame_offset + 8 > _tombraider.NumFrames())
823 882
             if (frame_offset > mTombRaider.NumFrames())
824 883
             {
825
-                gOpenRaider->mConsole->print("WARNING: Bad animation frame %i > %i\n",
884
+                gOpenRaider->mConsole->print("WARNING: Bad animation frame %i > %i",
826 885
                         frame_offset, mTombRaider.NumFrames());
827 886
 
828 887
                 // Mongoose 2002.08.15, Attempt to skip more likely bad animation data

+ 12
- 5
src/OpenRaider.cpp View File

@@ -166,11 +166,12 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
166 166
     } else if (strcmp(command, "help") == 0) {
167 167
         if (args->size() == 0) {
168 168
             mConsole->print("Available commands:");
169
-            mConsole->print("  load");
170
-            mConsole->print("  set");
171
-            mConsole->print("  bind");
172
-            mConsole->print("  help");
173
-            mConsole->print("  quit");
169
+            mConsole->print("  load - load a level");
170
+            mConsole->print("  set  - set a parameter");
171
+            mConsole->print("  bind - bind a keyboard/mouse action");
172
+            mConsole->print("  game - send a command to the game engine");
173
+            mConsole->print("  help - print command help");
174
+            mConsole->print("  quit - exit OpenRaider");
174 175
             mConsole->print("Use help COMMAND to get additional info");
175 176
         } else if (args->size() == 1) {
176 177
             return help(args->at(0));
@@ -183,6 +184,8 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
183 184
         int error = mGame->loadLevel(tmp);
184 185
         delete [] tmp;
185 186
         return error;
187
+    } else if (strcmp(command, "game") == 0) {
188
+        return mGame->command(args);
186 189
     } else {
187 190
         mConsole->print("Unknown command: %s ", command);
188 191
         return -1;
@@ -192,6 +195,8 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
192 195
 }
193 196
 
194 197
 int OpenRaider::help(const char *cmd) {
198
+    assert(cmd != NULL);
199
+
195 200
     if (strcmp(cmd, "set") == 0) {
196 201
         mConsole->print("set-Command Usage:");
197 202
         mConsole->print("  set VAR VAL");
@@ -230,6 +235,8 @@ int OpenRaider::help(const char *cmd) {
230 235
     } else if (strcmp(cmd, "load") == 0) {
231 236
         mConsole->print("load-Command Usage:");
232 237
         mConsole->print("  load levelfile.name");
238
+    } else if (strcmp(cmd, "game") == 0) {
239
+        mConsole->print("Use \"game help\" for more info");
233 240
     } else {
234 241
         mConsole->print("No help available for %s", cmd);
235 242
         return -1;

+ 1
- 2
src/Texture.cpp View File

@@ -72,8 +72,7 @@ void Texture::setFlag(TextureFlag flag) {
72 72
 }
73 73
 
74 74
 void Texture::clearFlag(TextureFlag flag) {
75
-    mFlags |= flag;
76
-    mFlags ^= flag;
75
+    mFlags &= ~flag;
77 76
 }
78 77
 
79 78
 void Texture::reset() {

Loading…
Cancel
Save