00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SCOURGE_H
00019 #define SCOURGE_H
00020
00021 #include <iostream>
00022 #include <string>
00023 #include <map>
00024 #include "constants.h"
00025 #include "sdlhandler.h"
00026 #include "sdleventhandler.h"
00027 #include "sdlscreenview.h"
00028 #include "calendar.h"
00029 #include "minimap.h"
00030 #include "map.h"
00031 #include "dungeongenerator.h"
00032 #include "creature.h"
00033 #include "mainmenu.h"
00034 #include "optionsmenu.h"
00035 #include "inventory.h"
00036 #include "item.h"
00037 #include "rpg/character.h"
00038 #include "rpg/monster.h"
00039 #include "rpg/spell.h"
00040 #include "gui/window.h"
00041 #include "gui/button.h"
00042 #include "userconfiguration.h"
00043 #include "effect.h"
00044 #include "containergui.h"
00045 #include "board.h"
00046 #include "battle.h"
00047 #include "party.h"
00048 #include "projectile.h"
00049 #include "multiplayer.h"
00050 #include "net/server.h"
00051 #include "net/client.h"
00052 #include "net/gamestatehandler.h"
00053 #include "netplay.h"
00054 #include "gui/progress.h"
00055 #include "gameadapter.h"
00056 #include "session.h"
00057 #include "infogui.h"
00058 #include "conversationgui.h"
00059 #include "gui/guitheme.h"
00060 #include "gui/scrollinglabel.h"
00061
00062 using namespace std;
00063
00064 class Creature;
00065 class Calendar;
00066 class MiniMap;
00067 class Map;
00068 class DungeonGenerator;
00069 class ShapePalette;
00070 class Location;
00071 class MainMenu;
00072 class OptionsMenu;
00073 class Inventory;
00074 class UserConfiguration;
00075 class Effect;
00076 class DungeonGenerator;
00077 class Window;
00078 class ContainerGui;
00079 class Board;
00080 class Battle;
00081 class Party;
00082 class Projectile;
00083 class Mission;
00084 class MultiplayerDialog;
00085 #ifdef HAVE_SDL_NET
00086 class Server;
00087 class Client;
00088 #endif
00089 class GameStateHandler;
00090 class NetPlay;
00091 class Progress;
00092 class GameAdapter;
00093 class InfoGui;
00094 class ConversationGui;
00095 class GuiTheme;
00096 class ScrollingLabel;
00097
00098 #define IMAGES_DIR "images/"
00099 #define RESOURCES_DIR "resources/"
00100 #define DEFAULT_IMAGES_DIR "default/"
00101 #define CREATURES_DIR "creatures/"
00102 #define MAX_BATTLE_COUNT 200
00103
00104 class InfoMessage {
00105 public:
00106 char message[300];
00107 void *obj;
00108 int x, y, z;
00109
00110 InfoMessage( char *s, void *obj, int x, int y, int z ) {
00111 strcpy( this->message, s );
00112 this->obj = obj;
00113 this->x = x;
00114 this->y = y;
00115 this->z = z;
00116 }
00117
00118 ~InfoMessage() {
00119 }
00120 };
00121
00128 class Scourge : public GameAdapter,SDLEventHandler,SDLScreenView,WidgetView,DragAndDropHandler {
00129 private:
00130 Party *party;
00131 Map *levelMap;
00132 MiniMap * miniMap;
00133 DungeonGenerator *dg;
00134
00135 int level;
00136 MainMenu *mainMenu;
00137 OptionsMenu *optionsMenu;
00138 MultiplayerDialog *multiplayer;
00139 bool isInfoShowing;
00140 bool info_dialog_showing;
00141 Board *board;
00142 int nextMission;
00143 bool teleportFailure;
00144 bool inHq;
00145 bool missionWillAwardExpPoints;
00146 char infoMessage[2000];
00147 Inventory *inventory;
00148 Window *messageWin, *exitConfirmationDialog;
00149 InfoGui *infoGui;
00150 ConversationGui *conversationGui;
00151 Label *exitLabel;
00152 ScrollingList *messageList;
00153 Button *yesExitConfirm, *noExitConfirm;
00154 int movingX, movingY, movingZ;
00155 Uint16 cursorMapX, cursorMapY, cursorMapZ;
00156 Item *movingItem;
00157 bool needToCheckDropLocation;
00158 Uint16 move;
00159 GLint lastTick;
00160 int battleCount;
00161 Battle *battle[MAX_BATTLE_COUNT];
00162
00163
00164 int currentStory, oldStory;
00165 bool changingStory;
00166
00167 static const int MAX_CONTAINER_GUI = 100;
00168 int containerGuiCount;
00169 ContainerGui *containerGui[MAX_CONTAINER_GUI];
00170
00171 GLint dragStartTime;
00172 static const int ACTION_CLICK_TIME = 200;
00173
00174 int lastMapX, lastMapY, lastMapZ, lastX, lastY;
00175
00176
00177 static const int POSITION_SAMPLE_DELTA = 10;
00178
00179 bool teleporting;
00180
00181 vector<Battle *> battleRound;
00182 int battleTurn, rtStartTurn;
00183
00184 bool mouseMoveScreen;
00185 Creature *targetSelectionFor;
00186
00187 int layoutMode;
00188 NetPlay *netPlay;
00189
00190 float targetWidth, targetWidthDelta;
00191 Uint32 lastTargetTick;
00192
00193
00194 bool lastEffectOn;
00195 int oldX;
00196 char version[100], min_version[20];
00197 Window *mainWin;
00198 Button *inventoryButton;
00199 Button *endTurnButton;
00200 Button *optionsButton;
00201 Button *quitButton;
00202 Button *roundButton;
00203 Button *player1Button;
00204 Button *player2Button;
00205 Button *player3Button;
00206 Button *player4Button;
00207 Button *groupButton;
00208 CardContainer *cards;
00209 Canvas *minPartyInfo;
00210 Canvas *playerInfo[MAX_PARTY_SIZE], *playerHpMp[MAX_PARTY_SIZE];
00211 Canvas *quickSpell[12];
00212
00213
00214 ScrollingList *missionList;
00215 ScrollingLabel *missionDescriptionLabel;
00216 Button *playMission, *closeBoard;
00217 Window *boardWin;
00218
00219 Progress *progress;
00220 bool inBattle;
00221 Progress *turnProgress;
00222 bool mouseRot, mouseZoom;
00223
00224 bool willStartDrag;
00225 int willStartDragX, willStartDragY;
00226 GLUquadric *quadric;
00227
00228 bool needToCheckInfo;
00229 map<InfoMessage *, Uint32> infos;
00230
00231 protected:
00232 SDLHandler *sdlHandler;
00233 ShapePalette *shapePal;
00234
00235 void processGameMouseDown(Uint16 x, Uint16 y, Uint8 button);
00236 void processGameMouseClick(Uint16 x, Uint16 y, Uint8 button);
00237 void getMapXYZAtScreenXY(Uint16 x, Uint16 y, Uint16 *mapx, Uint16 *mapy, Uint16 *mapz);
00238 void getMapXYAtScreenXY(Uint16 x, Uint16 y, Uint16 *mapx, Uint16 *mapy);
00239 void processGameMouseMove(Uint16 x, Uint16 y);
00240 void describeLocation(int mapx, int mapy, int mapz);
00241
00242
00243 bool getItem(Location *pos);
00244
00245 int dropItem(int x, int y);
00246 bool useLever(Location *pos);
00247 bool useDoor(Location *pos);
00248 void destroyDoor( Sint16 ox, Sint16 oy, Shape *shape );
00249 bool useBoard(Location *pos);
00250 bool useTeleporter(Location *pos);
00251 bool useGate(Location *pos);
00252
00253 public:
00254 #define TOP_GUI_WIDTH 400
00255 #define TOP_GUI_HEIGHT 100
00256 #define GUI_PLAYER_INFO_W 250
00257 #define GUI_PLAYER_INFO_H 350
00258 #define MINIMAP_WINDOW_WIDTH 200
00259 #define MINIMAP_WINDOW_HEIGHT 150
00260
00261 static const int PARTY_GUI_WIDTH=500;
00262 static const int PARTY_GUI_HEIGHT=145;
00263 static const int PARTY_MIN_GUI_WIDTH=100;
00264 static const int INVENTORY_WIDTH = 420;
00265 static const int INVENTORY_HEIGHT = 460;
00266
00267 static int blendA, blendB;
00268 static int blend[];
00269 void setBlendFunc();
00270
00271 Scourge(UserConfiguration *config);
00272 ~Scourge();
00273
00277 void receive(Widget *widget);
00278
00283 inline bool startDrag(Widget *widget, int x=0, int y=0) {
00284 return false;
00285 }
00286
00287
00288 inline int getCurrentDepth() { return currentStory; }
00289
00290 inline bool isHeadless() { return false; }
00291
00292 inline Session *getSession() { return session; }
00293
00294 int getScreenWidth();
00295 int getScreenHeight();
00296
00300 inline Board *getBoard() { return board; }
00301
00306 inline void setMove(Uint16 n) { move |= n; };
00307
00312 inline void removeMove(Uint16 n) { move &= (0xffff - n); }
00313
00318 void playRound();
00319
00320 Battle *getBattle(Creature *creature);
00321
00325 inline Party *getParty() { return party; }
00326
00330 inline Map *getMap() { return levelMap; }
00331
00335 inline MiniMap *getMiniMap() { return miniMap; }
00336
00337 void colorMiniMapPoint(int x, int y, Shape *shape, Location *pos=NULL);
00338 void eraseMiniMapPoint(int x, int y);
00339
00350 void setMovingItem(Item *item, int x, int y, int z);
00351
00355 inline Item *getMovingItem() { return movingItem; }
00356
00360 inline MainMenu *getMainMenu() { return mainMenu; }
00361
00365 inline OptionsMenu *getOptionsMenu() { return optionsMenu; }
00366
00370 inline MultiplayerDialog *getMultiplayerDialog() { return multiplayer; }
00371
00375 inline Inventory *getInventory() { return inventory; }
00376
00383 void drawView();
00384
00389 void drawAfter();
00390
00391 void drawDraggedItem();
00392
00393 void drawBorder();
00394
00395 void drawOutsideMap();
00396
00397 void showCreatureInfo(Creature *creature, bool player, bool selected, bool groupMode);
00398
00404 bool handleEvent(SDL_Event *event);
00405
00412 bool handleEvent(Widget *widget, SDL_Event *event);
00413
00418 void addGameSpeed(int speedFactor);
00419
00424 void startItemDragFromGui(Item *item);
00425
00432 bool startItemDrag(int x, int y, int z);
00433
00437 void endItemDrag();
00438
00448 bool useItem(int x, int y, int z);
00449
00457 void startMission();
00458
00463 void endMission();
00464
00468 inline ShapePalette *getShapePalette() { return shapePal; }
00469
00473 inline SDLHandler *getSDLHandler() { return sdlHandler; }
00474
00475
00476
00477
00482 void openContainerGui(Item *container);
00483
00487 void closeContainerGui(ContainerGui *gui);
00488
00492 void closeAllContainerGuis();
00493
00501 void creatureDeath(Creature *creature);
00502
00506 void showMessageDialog(char *message);
00507
00508 void togglePlayerOnly();
00509
00510 void toggleInventoryWindow();
00511
00512 void toggleOptionsWindow();
00513
00517 void showExitConfirmationDialog();
00518
00527 Window *createWoodWindow(int x, int y, int w, int h, char *title);
00528
00537 Window *createWindow(int x, int y, int w, int h, char *title);
00538
00543 void missionCompleted();
00544
00548 inline void setTargetSelectionFor(Creature *c) { targetSelectionFor = c; sdlHandler->setCursorMode(targetSelectionFor ? SDLHandler::CURSOR_CROSSHAIR : SDLHandler::CURSOR_NORMAL); }
00549
00553 inline Creature *getTargetSelectionFor() { return targetSelectionFor; }
00554
00558 void setUILayout();
00559
00566 void setUILayout(int mode);
00567
00571 int getLayoutMode() { return layoutMode; }
00572
00573
00574 void initStart(int statusCount, char *message);
00575 void initUpdate(char *message);
00576 void initEnd();
00577
00578 void initVideo(ShapePalette *shapePal);
00579 void initUI();
00580 void start();
00581
00582 inline double getFps() { return getSDLHandler()->getFPS(); }
00583
00584 inline void playSound(const char *sound) { sdlHandler->getSound()->playSound(sound); }
00585
00586 inline void loadMonsterSounds( char *type, map<int, vector<string>*> *soundMap ) {
00587 sdlHandler->getSound()->loadMonsterSounds( type, soundMap, getUserConfiguration() );
00588 }
00589
00590 inline void unloadMonsterSounds( char *type, map<int, vector<string>*> *soundMap ) {
00591 sdlHandler->getSound()->unloadMonsterSounds( type, soundMap );
00592 }
00593
00594 inline void setDebugStr(char *s) { sdlHandler->setDebugStr(s); }
00595
00596 void fightProjectileHitTurn(Projectile *proj, Creature *creature);
00597
00598 void fightProjectileHitTurn(Projectile *proj, int x, int y);
00599
00600 void drawWidget(Widget *w);
00601
00602 void resetPartyUI();
00603
00604 void refreshInventoryUI(int playerIndex);
00605
00606 void refreshInventoryUI();
00607
00608 void toggleRoundUI(bool startRound);
00609
00610 void setFormationUI(int formation, bool playerOnly);
00611
00612 void togglePlayerOnlyUI(bool playerOnly);
00613
00614 void setPlayerUI(int index);
00615
00616 void setPlayer(int n);
00617
00618 void createBoardUI();
00619
00620 void updateBoardUI(int count, const char **missionText, Color *missionColor);
00621
00622 int handleBoardEvent(Widget *widget, SDL_Event *event);
00623
00624 void setMissionDescriptionUI(char *s);
00625
00626
00627 void moveMonster(Creature *monster);
00628
00629 void removeBattle(Battle *battle);
00630
00631 inline bool inTurnBasedCombat() {
00632 return (battleTurn < (int)battleRound.size() &&
00633 getUserConfiguration()->isBattleTurnBased());
00634 }
00635
00636 bool inTurnBasedCombatPlayerTurn();
00637
00638 inline InfoGui *getInfoGui() { return infoGui; }
00639
00640 inline ConversationGui *getConversationGui() { return conversationGui; }
00641
00642 void showItemInfoUI(Item *item, int level);
00643
00644 void resetInfos();
00645
00646 void createParty( Creature **pc, int *partySize );
00647
00648 bool handleTargetSelectionOfCreature( Creature *potentialTarget );
00649 bool handleTargetSelectionOfItem( Item *item, int x=0, int y=0, int z=0 );
00650 bool handleTargetSelectionOfLocation( Uint16 mapx, Uint16 mapy, Uint16 mapz );
00651
00652 void teleport( bool toHQ=true );
00653
00654 inline Window *getPartyWindow() { return mainWin; }
00655
00656 protected:
00657
00658 void drawPortrait( Widget *w, Creature *p );
00659
00660 void resetBattles();
00661
00662 int initMultiplayer();
00663
00664 void decodeName(int name, Uint16* mapx, Uint16* mapy, Uint16* mapz);
00665 void createUI();
00666
00667 void handleKeyboardMovement();
00668
00669 void decideMonsterAction(Creature *monster);
00670
00671 void refreshContainerGui(Item *container);
00672
00673 void createPartyUI();
00674
00675 bool handlePartyEvent(Widget *widget, SDL_Event *event);
00676
00677 void updatePartyUI();
00678
00679 void moveProjectiles();
00680 bool fightCurrentBattleTurn();
00681 void resetNonParticipantAnimation( Battle *battle );
00682 bool createBattleTurns();
00683 void resetUIAfterBattle();
00684 void moveCreatures();
00685
00686 void checkForDropTarget();
00687 void checkForInfo();
00688 void drawInfos();
00689
00690 void quickSpellAction( int index );
00691 };
00692
00693 #endif