summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp110
1 files changed, 58 insertions, 52 deletions
diff --git a/src/game.cpp b/src/game.cpp
index ec5e6b13..9035ba6a 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -21,14 +21,15 @@
#include "game.h"
-#include "beingmanager.h"
+#include "actorspritemanager.h"
+#include "actorsprite.h"
#include "channelmanager.h"
#include "client.h"
#include "commandhandler.h"
#include "configuration.h"
#include "effectmanager.h"
+#include "event.h"
#include "emoteshortcut.h"
-#include "flooritemmanager.h"
#include "graphics.h"
#include "itemshortcut.h"
#include "joystick.h"
@@ -36,7 +37,6 @@
#include "localplayer.h"
#include "log.h"
#include "map.h"
-#include "npc.h"
#include "particle.h"
#include "playerrelations.h"
#include "sound.h"
@@ -115,8 +115,7 @@ OutfitWindow *outfitWindow;
SpecialsWindow *specialsWindow;
SocialWindow *socialWindow;
-BeingManager *beingManager = NULL;
-FloorItemManager *floorItemManager = NULL;
+ActorSpriteManager *actorSpriteManager = NULL;
ChannelManager *channelManager = NULL;
CommandHandler *commandHandler = NULL;
Particle *particleEngine = NULL;
@@ -130,14 +129,17 @@ ChatTab *localChatTab = NULL;
*/
static void initEngines()
{
- beingManager = new BeingManager;
+ Mana::Event::trigger("Game", "EnginesInitalizing");
+
+ actorSpriteManager = new ActorSpriteManager;
commandHandler = new CommandHandler;
- floorItemManager = new FloorItemManager;
channelManager = new ChannelManager;
effectManager = new EffectManager;
particleEngine = new Particle(NULL);
particleEngine->setupEngine();
+
+ Mana::Event::trigger("Game", "EnginesInitalized");
}
/**
@@ -145,15 +147,17 @@ static void initEngines()
*/
static void createGuiWindows()
{
+ Mana::Event::trigger("Game", "GuiWindowsLoading");
+
setupWindow->clearWindowsForReset();
// Create dialogs
chatWindow = new ChatWindow;
tradeWindow = new TradeWindow;
- equipmentWindow = new EquipmentWindow(player_node->mEquipment.get());
+ equipmentWindow = new EquipmentWindow(PlayerInfo::getEquipment());
statusWindow = new StatusWindow;
miniStatusWindow = new MiniStatusWindow;
- inventoryWindow = new InventoryWindow(player_node->getInventory());
+ inventoryWindow = new InventoryWindow(PlayerInfo::getInventory());
skillDialog = new SkillDialog;
minimap = new Minimap;
helpWindow = new HelpWindow;
@@ -168,12 +172,9 @@ static void createGuiWindows()
localChatTab = new ChatTab(_("General"));
- if (config.getValue("logToChat", 0))
- {
- logger->setChatWindow(chatWindow);
- }
+ NpcDialog::setup();
- Net::getGeneralHandler()->guiWindowsLoaded();
+ Mana::Event::trigger("Game", "GuiWindowsLoaded");
}
#define del_0(X) { delete X; X = 0; }
@@ -183,8 +184,8 @@ static void createGuiWindows()
*/
static void destroyGuiWindows()
{
- Net::getGeneralHandler()->guiWindowsUnloaded();
- logger->setChatWindow(NULL);
+ Mana::Event::trigger("Game", "GuiWindowsUnloading");
+
del_0(localChatTab) // Need to do this first, so it can remove itself
del_0(chatWindow)
del_0(statusWindow)
@@ -201,12 +202,16 @@ static void destroyGuiWindows()
del_0(outfitWindow)
del_0(specialsWindow)
del_0(socialWindow)
+
+ Mana::Event::trigger("NPC", "CloseAll"); // Cleanup remaining NPC dialogs
+
+ Mana::Event::trigger("Game", "GuiWindowsUnloaded");
}
Game *Game::mInstance = 0;
Game::Game():
- mLastTarget(Being::UNKNOWN),
+ mLastTarget(ActorSprite::UNKNOWN),
mCurrentMap(0), mMapName("")
{
assert(!mInstance);
@@ -230,10 +235,8 @@ Game::Game():
initEngines();
- Net::getGameHandler()->inGame();
-
// Initialize beings
- beingManager->setPlayer(player_node);
+ actorSpriteManager->setPlayer(player_node);
/*
* To prevent the server from sending data before the client
@@ -253,18 +256,21 @@ Game::Game():
joystick = new Joystick(0);
setupWindow->setInGame(true);
+
+ Mana::Event::trigger("Game", "Constructed");
}
Game::~Game()
{
+ Mana::Event::trigger("Game", "Destructing");
+
delete mWindowMenu;
destroyGuiWindows();
- del_0(beingManager)
+ del_0(actorSpriteManager)
if (Client::getState() != STATE_CHANGE_MAP)
del_0(player_node)
- del_0(floorItemManager)
del_0(channelManager)
del_0(commandHandler)
del_0(joystick)
@@ -273,6 +279,8 @@ Game::~Game()
del_0(mCurrentMap)
mInstance = 0;
+
+ Mana::Event::trigger("Game", "Destructed");
}
static bool saveScreenshot()
@@ -316,11 +324,11 @@ static bool saveScreenshot()
std::stringstream chatlogentry;
// TODO: Make it one complete gettext string below
chatlogentry << _("Screenshot saved as ") << filenameSuffix.str();
- localChatTab->chatLog(chatlogentry.str(), BY_SERVER);
+ SERVER_NOTICE(chatlogentry.str())
}
else
{
- localChatTab->chatLog(_("Saving screenshot failed!"), BY_SERVER);
+ SERVER_NOTICE(_("Saving screenshot failed!"))
logger->log("Error: could not save screenshot.");
}
@@ -334,7 +342,8 @@ void Game::logic()
handleInput();
// Handle all necessary game logic
- beingManager->logic();
+ ActorSprite::actorLogic();
+ actorSpriteManager->logic();
particleEngine->update();
if (mCurrentMap)
mCurrentMap->update();
@@ -392,7 +401,7 @@ void Game::handleInput()
// send straight to gui for certain windows
if (quitDialog || TextDialog::isActive() ||
- NpcPostDialog::isActive())
+ PlayerInfo::getNPCPostCount() > 0)
{
try
{
@@ -449,7 +458,8 @@ void Game::handleInput()
}
- if (!chatWindow->isInputFocused() || (event.key.keysym.mod & KMOD_ALT))
+ if (!chatWindow->isInputFocused() || (event.key.keysym.mod &
+ KMOD_ALT))
{
if (keyboard.isKeyActive(keyboard.KEY_PREV_CHAT_TAB))
{
@@ -601,7 +611,7 @@ void Game::handleInput()
// off under eAthena.
FloorItem *item =
- floorItemManager->findByCoordinates(x, y);
+ actorSpriteManager->findItem(x, y);
// If none below the player, try the tile in front
// of the player
@@ -618,8 +628,7 @@ void Game::handleInput()
default: break;
}
- item = floorItemManager->findByCoordinates(
- x, y);
+ item = actorSpriteManager->findItem(x, y);
}
if (item)
@@ -698,16 +707,12 @@ void Game::handleInput()
unsigned int deflt = player_relations.getDefault();
if (deflt & PlayerRelation::TRADE)
{
- localChatTab->chatLog(
- _("Ignoring incoming trade requests"),
- BY_SERVER);
+ SERVER_NOTICE(_("Ignoring incoming trade requests"))
deflt &= ~PlayerRelation::TRADE;
}
else
{
- localChatTab->chatLog(
- _("Accepting incoming trade requests"),
- BY_SERVER);
+ SERVER_NOTICE(_("Accepting incoming trade requests"))
deflt |= PlayerRelation::TRADE;
}
@@ -753,7 +758,7 @@ void Game::handleInput()
return;
// Moving player around
- if (player_node->isAlive() && !NPC::isTalking() &&
+ if (player_node->isAlive() && !PlayerInfo::isTalking() &&
!chatWindow->isInputFocused() && !quitDialog)
{
// Get the state of the keyboard keys
@@ -831,8 +836,8 @@ void Game::handleInput()
if (!player_node->getTarget())
{
// Only auto target Monsters
- target = beingManager->findNearestLivingBeing(player_node,
- 20, Being::MONSTER);
+ target = actorSpriteManager->findNearestLivingBeing(player_node,
+ 20, ActorSprite::MONSTER);
}
player_node->attack(target, newTarget);
}
@@ -844,16 +849,16 @@ void Game::handleInput()
(joystick && joystick->buttonPressed(3))) &&
!keyboard.isKeyActive(keyboard.KEY_TARGET))
{
- Being::Type currentTarget = Being::UNKNOWN;
+ ActorSprite::Type currentTarget = ActorSprite::UNKNOWN;
if (keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) ||
(joystick && joystick->buttonPressed(3)))
- currentTarget = Being::MONSTER;
+ currentTarget = ActorSprite::MONSTER;
else if (keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER))
- currentTarget = Being::PLAYER;
+ currentTarget = ActorSprite::PLAYER;
else if (keyboard.isKeyActive(keyboard.KEY_TARGET_NPC))
- currentTarget = Being::NPC;
+ currentTarget = ActorSprite::NPC;
- Being *target = beingManager->findNearestLivingBeing(player_node,
+ Being *target = actorSpriteManager->findNearestLivingBeing(player_node,
20, currentTarget);
if (target && (target != player_node->getTarget() ||
@@ -865,7 +870,7 @@ void Game::handleInput()
}
else
{
- mLastTarget = Being::UNKNOWN; // Reset last target
+ mLastTarget = ActorSprite::UNKNOWN; // Reset last target
}
// Talk to the nearest NPC if 't' pressed
@@ -876,8 +881,8 @@ void Game::handleInput()
if (target)
{
- if (target->getType() == Being::NPC)
- static_cast<NPC*>(target)->talk();
+ if (target->canTalk())
+ target->talkTo();
}
}
@@ -892,7 +897,7 @@ void Game::handleInput()
{
if (joystick->buttonPressed(1))
{
- FloorItem *item = floorItemManager->findByCoordinates(x, y);
+ FloorItem *item = actorSpriteManager->findItem(x, y);
if (item)
player_node->pickUp(item);
@@ -912,8 +917,7 @@ void Game::handleInput()
void Game::changeMap(const std::string &mapPath)
{
// Clean up floor items, beings and particles
- floorItemManager->clear();
- beingManager->clear();
+ actorSpriteManager->clear();
// Close the popup menu on map change so that invalid options can't be
// executed.
@@ -946,7 +950,7 @@ void Game::changeMap(const std::string &mapPath)
// Notify the minimap and beingManager about the map change
minimap->setMap(newMap);
- beingManager->setMap(newMap);
+ actorSpriteManager->setMap(newMap);
particleEngine->setMap(newMap);
viewport->setMap(newMap);
@@ -963,5 +967,7 @@ void Game::changeMap(const std::string &mapPath)
delete mCurrentMap;
mCurrentMap = newMap;
- Net::getGameHandler()->mapLoaded(mapPath);
+ Mana::Event event("MapLoaded");
+ event.setString("mapPath", mapPath);
+ event.trigger("Game");
}