2010-03-18 21:26:40 +00:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2010-04-30 18:16:54 +00:00
|
|
|
// Copyright (C) 2001-2008 Martio Figueroa
|
2010-03-18 21:26:40 +00:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_COMMANDER_H_
|
|
|
|
#define _GLEST_GAME_COMMANDER_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "vec.h"
|
|
|
|
#include "selection.h"
|
|
|
|
#include "command_type.h"
|
2010-04-15 01:19:00 +00:00
|
|
|
#include "platform_util.h"
|
2011-01-11 08:45:58 +00:00
|
|
|
#include "base_thread.h"
|
2010-09-07 05:25:40 +00:00
|
|
|
#include "leak_dumper.h"
|
2010-03-18 21:26:40 +00:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
using Shared::Graphics::Vec2i;
|
2010-04-30 18:16:54 +00:00
|
|
|
using Shared::PlatformCommon::Chrono;
|
2010-03-18 21:26:40 +00:00
|
|
|
|
|
|
|
class World;
|
|
|
|
class Unit;
|
|
|
|
class Command;
|
|
|
|
class CommandType;
|
|
|
|
class NetworkCommand;
|
2011-01-11 08:45:58 +00:00
|
|
|
class Game;
|
2010-03-18 21:26:40 +00:00
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Commander
|
|
|
|
//
|
|
|
|
/// Gives commands to the units
|
|
|
|
// =====================================================
|
|
|
|
|
2011-01-11 08:45:58 +00:00
|
|
|
//
|
|
|
|
// This interface describes the methods a callback object must implement
|
|
|
|
//
|
|
|
|
class CommanderNetworkCallbackInterface {
|
|
|
|
public:
|
|
|
|
virtual void commanderNetworkUpdateTask(int id) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CommanderNetworkThread : public BaseThread
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
CommanderNetworkCallbackInterface *commanderInterface;
|
|
|
|
Semaphore semTaskSignalled;
|
|
|
|
|
|
|
|
virtual void setQuitStatus(bool value);
|
|
|
|
virtual void setTaskCompleted(int id);
|
|
|
|
Mutex idMutex;
|
|
|
|
std::pair<int,bool> idStatus;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CommanderNetworkThread();
|
|
|
|
CommanderNetworkThread(CommanderNetworkCallbackInterface *commanderInterface);
|
|
|
|
virtual void execute();
|
|
|
|
void signalUpdate(int id);
|
|
|
|
bool isSignalCompleted(int id);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Commander : public CommanderNetworkCallbackInterface {
|
2010-03-18 21:26:40 +00:00
|
|
|
private:
|
|
|
|
typedef vector<CommandResult> CommandResultContainer;
|
|
|
|
|
|
|
|
private:
|
|
|
|
World *world;
|
2010-04-15 01:19:00 +00:00
|
|
|
Chrono perfTimer;
|
2010-03-18 21:26:40 +00:00
|
|
|
|
2011-01-11 22:09:46 +00:00
|
|
|
//CommanderNetworkThread *networkThread;
|
|
|
|
//Game *game;
|
2011-01-11 08:45:58 +00:00
|
|
|
|
2010-03-18 21:26:40 +00:00
|
|
|
public:
|
2011-01-11 08:45:58 +00:00
|
|
|
Commander();
|
|
|
|
~Commander();
|
|
|
|
|
|
|
|
void signalNetworkUpdate(Game *game);
|
2010-03-18 21:26:40 +00:00
|
|
|
void init(World *world);
|
2011-01-11 08:45:58 +00:00
|
|
|
void updateNetwork(Game *game);
|
2010-03-18 21:26:40 +00:00
|
|
|
|
2010-08-28 01:46:26 +00:00
|
|
|
CommandResult tryGiveCommand(const Selection *selection, const CommandType *commandType,
|
|
|
|
const Vec2i &pos, const UnitType* unitType,
|
|
|
|
CardinalDir facing, bool tryQueue,Unit *targetUnit=NULL) const;
|
|
|
|
|
2010-06-08 07:40:32 +00:00
|
|
|
CommandResult tryGiveCommand(const Unit* unit, const CommandType *commandType, const Vec2i &pos, const UnitType* unitType, CardinalDir facing, bool tryQueue = false,Unit *targetUnit=NULL) const;
|
2010-04-18 07:35:48 +00:00
|
|
|
CommandResult tryGiveCommand(const Selection *selection, CommandClass commandClass, const Vec2i &pos= Vec2i(0), const Unit *targetUnit= NULL, bool tryQueue = false) const;
|
|
|
|
CommandResult tryGiveCommand(const Selection *selection, const CommandType *commandType, const Vec2i &pos= Vec2i(0), const Unit *targetUnit= NULL, bool tryQueue = false) const;
|
|
|
|
CommandResult tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit= NULL, bool tryQueue = false) const;
|
2010-03-18 21:26:40 +00:00
|
|
|
CommandResult tryCancelCommand(const Selection *selection) const;
|
|
|
|
void trySetMeetingPoint(const Unit* unit, const Vec2i &pos) const;
|
|
|
|
CommandResult pushNetworkCommand(const NetworkCommand* networkCommand) const;
|
2010-03-22 04:47:16 +00:00
|
|
|
//void giveNetworkCommandSpecial(const NetworkCommand* networkCommand) const;
|
2010-03-18 21:26:40 +00:00
|
|
|
|
2011-01-20 07:56:02 +00:00
|
|
|
Command* buildCommand(const NetworkCommand* networkCommand) const;
|
|
|
|
|
2010-03-18 21:26:40 +00:00
|
|
|
private:
|
|
|
|
CommandResult computeResult(const CommandResultContainer &results) const;
|
2010-03-22 04:47:16 +00:00
|
|
|
void giveNetworkCommand(NetworkCommand* networkCommand) const;
|
2011-01-11 08:45:58 +00:00
|
|
|
|
|
|
|
virtual void commanderNetworkUpdateTask(int id);
|
2011-02-10 21:02:07 +00:00
|
|
|
bool canSubmitCommandType(const Unit *unit, const CommandType *commandType) const;
|
2010-03-18 21:26:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}} //end namespace
|
|
|
|
|
|
|
|
#endif
|