diff options
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 172 |
1 files changed, 73 insertions, 99 deletions
diff --git a/src/game.cpp b/src/game.cpp index 7f0186d1..3ca8f5ae 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,9 +1,8 @@ /* - * Aethyra + * The Mana World * Copyright (C) 2004 The Mana World Development Team * - * This file is part of Aethyra based on original code - * from The Mana World. + * This file is part of The Mana World. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -191,24 +190,24 @@ void createGuiWindows(Network *network) { // Create dialogs chatWindow = new ChatWindow(network); - menuWindow = new MenuWindow(); + menuWindow = new MenuWindow; statusWindow = new StatusWindow(player_node); - miniStatusWindow = new MiniStatusWindow(); + miniStatusWindow = new MiniStatusWindow; buyDialog = new BuyDialog(network); sellDialog = new SellDialog(network); buySellDialog = new BuySellDialog(network); - inventoryWindow = new InventoryWindow(); - emoteWindow = new EmoteWindow(); + inventoryWindow = new InventoryWindow; + emoteWindow = new EmoteWindow; npcTextDialog = new NpcTextDialog(network); npcIntegerDialog = new NpcIntegerDialog(network); npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); - skillDialog = new SkillDialog(); - minimap = new Minimap(); - equipmentWindow = new EquipmentWindow(); + skillDialog = new SkillDialog; + minimap = new Minimap; + equipmentWindow = new EquipmentWindow; tradeWindow = new TradeWindow(network); - helpWindow = new HelpWindow(); - debugWindow = new DebugWindow(); + helpWindow = new HelpWindow; + debugWindow = new DebugWindow; itemShortcutWindow = new ShortcutWindow("ItemShortcut", new ItemShortcutContainer); emoteShortcutWindow = new ShortcutWindow("emoteShortcut", @@ -222,6 +221,8 @@ void createGuiWindows(Network *network) miniStatusWindow->getPopupName() + "Visible", true)); buyDialog->setVisible(false); sellDialog->setVisible(false); + minimap->setVisible((bool) config.getValue( + minimap->getWindowName() + "Visible", true)); tradeWindow->setVisible(false); menuWindow->setVisible((bool) config.getValue( menuWindow->getPopupName() + "Visible", true)); @@ -272,22 +273,23 @@ void destroyGuiWindows() Game::Game(Network *network): mNetwork(network), mBeingHandler(new BeingHandler(config.getValue("EnableSync", 0) == 1)), - mBuySellHandler(new BuySellHandler()), - mChatHandler(new ChatHandler()), - mEquipmentHandler(new EquipmentHandler()), - mInventoryHandler(new InventoryHandler()), - mItemHandler(new ItemHandler()), - mNpcHandler(new NPCHandler()), - mPlayerHandler(new PlayerHandler()), - mSkillHandler(new SkillHandler()), - mTradeHandler(new TradeHandler()) + mBuySellHandler(new BuySellHandler), + mChatHandler(new ChatHandler), + mEquipmentHandler(new EquipmentHandler), + mInventoryHandler(new InventoryHandler), + mItemHandler(new ItemHandler), + mNpcHandler(new NPCHandler), + mPlayerHandler(new PlayerHandler), + mSkillHandler(new SkillHandler), + mTradeHandler(new TradeHandler), + mLastTarget(Being::UNKNOWN) { createGuiWindows(network); engine = new Engine(network); beingManager = new BeingManager(network); - floorItemManager = new FloorItemManager(); - effectManager = new EffectManager(); + floorItemManager = new FloorItemManager; + effectManager = new EffectManager; particleEngine = new Particle(NULL); particleEngine->setupEngine(); @@ -342,10 +344,10 @@ Game::Game(Network *network): Game::~Game() { - delete player_node; destroyGuiWindows(); delete beingManager; + delete player_node; delete floorItemManager; delete joystick; delete particleEngine; @@ -374,11 +376,11 @@ static bool saveScreenshot() filenameSuffix.str(""); filename << PHYSFS_getUserDir(); #if (defined __USE_UNIX98 || defined __FreeBSD__) - filenameSuffix << ".aethyra/"; + filenameSuffix << ".tmw/"; #elif defined __APPLE__ filenameSuffix << "Desktop/"; #endif - filenameSuffix << "Ae_Screenshot_" << screenshotCount << ".png"; + filenameSuffix << "TMW_Screenshot_" << screenshotCount << ".png"; filename << filenameSuffix.str(); testExists.open(filename.str().c_str(), std::ios::in); found = !testExists.is_open(); @@ -523,58 +525,42 @@ void Game::handleInput() } } - if (keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT) || - keyboard.isKeyActive(keyboard.KEY_OK)) - { - // Input chat window - if (!(chatWindow->isInputFocused() || - deathNotice || - weightNotice)) + if (!(chatWindow->isInputFocused() || deathNotice || weightNotice)) + if (keyboard.isKeyActive(keyboard.KEY_OK)) { - // Quit by pressing Enter if the exit confirm is there if (exitConfirm && keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT)) done = true; // Close the Browser if opened else if (helpWindow->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) helpWindow->setVisible(false); // Close the config window, cancelling changes if opened else if (setupWindow->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) setupWindow->action(gcn::ActionEvent(NULL, "cancel")); // Submits the text and proceeds to the next dialog else if (npcStringDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcStringDialog->action(gcn::ActionEvent(NULL, "ok")); // Proceed to the next dialog option, or close the window else if (npcTextDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcTextDialog->action(gcn::ActionEvent(NULL, "ok")); // Choose the currently highlighted dialogue option else if (npcListDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcListDialog->action(gcn::ActionEvent(NULL, "ok")); // Submits the text and proceeds to the next dialog else if (npcIntegerDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcIntegerDialog->action(gcn::ActionEvent(NULL, "ok")); - else if (!(keyboard.getKeyValue( - KeyboardConfig::KEY_TOGGLE_CHAT) == - keyboard.getKeyValue( - KeyboardConfig::KEY_OK) && - (helpWindow->isVisible() || - setupWindow->isVisible() || - npcStringDialog->isVisible() || - npcTextDialog->isVisible() || - npcListDialog->isVisible() || - npcIntegerDialog->isVisible()))) - { - chatWindow->requestChatFocus(); + } + if (keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT)) + { + if (chatWindow->requestChatFocus()) used = true; - } } - } const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); switch (tKey) @@ -649,9 +635,9 @@ void Game::handleInput() { case KeyboardConfig::KEY_PICKUP: { - FloorItem *item = floorItemManager->findByCoordinates( - player_node->mX, - player_node->mY); + FloorItem *item = + floorItemManager->findByCoordinates( + player_node->mX, player_node->mY); // If none below the player, try the tile in front // of the player @@ -667,7 +653,9 @@ void Game::handleInput() x--; if (player_node->getDirection() & Being::RIGHT) x++; - item = floorItemManager->findByCoordinates(x, y); + + item = floorItemManager->findByCoordinates( + x, y); } if (item) @@ -846,8 +834,7 @@ void Game::handleInput() if (keyboard.isKeyActive(keyboard.KEY_ATTACK) || (joystick && joystick->buttonPressed(0))) { - Being *target = beingManager->findNearestLivingBeing(x, y, 20, - Being::MONSTER); + Being *target = NULL; bool newTarget = !keyboard.isKeyActive(keyboard.KEY_TARGET); // A set target has highest priority @@ -864,47 +851,40 @@ void Game::handleInput() default: break; } - // Attack priorioty is: Monster, Player, auto target - target = beingManager->findBeing(targetX, targetY, - Being::MONSTER); - if (!target) - target = beingManager->findBeing(targetX, targetY, - Being::PLAYER); + // Only auto target Monsters + target = beingManager->findNearestLivingBeing(targetX, targetY, + 20, Being::MONSTER); } player_node->attack(target, newTarget); } - // Target the nearest player if 'q' is pressed - if ( keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) && - !keyboard.isKeyActive(keyboard.KEY_TARGET) ) - { - Being *target = beingManager->findNearestLivingBeing(player_node, - 20, Being::PLAYER); - - player_node->setTarget(target); - } - - // Target the nearest monster if 'a' pressed - if ((keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || - (joystick && joystick->buttonPressed(3))) && - !keyboard.isKeyActive(keyboard.KEY_TARGET)) + // Target the nearest player/monster/npc + if ((keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) || + keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || + keyboard.isKeyActive(keyboard.KEY_TARGET_NPC) || + (joystick && joystick->buttonPressed(3))) && + !keyboard.isKeyActive(keyboard.KEY_TARGET)) { - Being *target = beingManager->findNearestLivingBeing( - x, y, 20, Being::MONSTER); + Being::Type currentTarget = Being::UNKNOWN; + if (keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || + (joystick && joystick->buttonPressed(3))) + currentTarget = Being::MONSTER; + else if (keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER)) + currentTarget = Being::PLAYER; + else if (keyboard.isKeyActive(keyboard.KEY_TARGET_NPC)) + currentTarget = Being::NPC; - player_node->setTarget(target); - } - - // Target the nearest npc if 'n' pressed - if ( keyboard.isKeyActive(keyboard.KEY_TARGET_NPC) && - !keyboard.isKeyActive(keyboard.KEY_TARGET) ) - { - Being *target = beingManager->findNearestLivingBeing( - x, y, 20, Being::NPC); + Being *target = beingManager->findNearestLivingBeing(player_node, + 20, currentTarget); - player_node->setTarget(target); - } + if (target && (target != player_node->getTarget() || + currentTarget != mLastTarget)) + { + player_node->setTarget(target); + mLastTarget = currentTarget; + } + } else mLastTarget = Being::UNKNOWN; // Reset last target // Talk to the nearest NPC if 't' pressed if ( keyboard.isKeyActive(keyboard.KEY_TALK) ) @@ -914,12 +894,6 @@ void Game::handleInput() { Being *target = player_node->getTarget(); - if (!target) - { - target = beingManager->findNearestLivingBeing( - x, y, 20, Being::NPC); - } - if (target) { if (target->getType() == Being::NPC) |