2014-10-14 13:11:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
|
|
|
|
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
|
|
|
|
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see http://gnu.org/licenses
|
|
|
|
|
*/
|
2013-03-31 08:21:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2015-06-20 18:02:40 +00:00
|
|
|
|
* \file object/object_manager.h
|
2014-12-20 18:09:53 +00:00
|
|
|
|
* \brief Object manager
|
2013-03-31 08:21:22 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "common/singleton.h"
|
|
|
|
|
|
2015-06-20 17:27:43 +00:00
|
|
|
|
#include "math/const.h"
|
|
|
|
|
#include "math/vector.h"
|
|
|
|
|
|
|
|
|
|
#include "object/object_type.h"
|
|
|
|
|
|
2015-01-08 17:56:26 +00:00
|
|
|
|
#include <map>
|
2015-06-20 17:27:43 +00:00
|
|
|
|
#include <vector>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
class CEngine;
|
|
|
|
|
class CModelManager;
|
|
|
|
|
class CParticle;
|
|
|
|
|
class CTerrain;
|
|
|
|
|
} // namespace Gfx
|
|
|
|
|
|
|
|
|
|
class CObject;
|
|
|
|
|
class CRobotMain;
|
|
|
|
|
class CObjectFactory;
|
|
|
|
|
|
|
|
|
|
enum RadarFilter
|
|
|
|
|
{
|
|
|
|
|
FILTER_NONE = 0,
|
|
|
|
|
FILTER_ONLYLANDING = 1,
|
|
|
|
|
FILTER_ONLYFLYING = 2,
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-21 09:16:09 +00:00
|
|
|
|
using CObjectMap = std::map<int, std::unique_ptr<CObject>>;
|
2013-03-31 08:21:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \class ObjectManager
|
2014-12-20 18:09:53 +00:00
|
|
|
|
* \brief Manages CObject instances
|
2013-03-31 08:21:22 +00:00
|
|
|
|
*/
|
|
|
|
|
class CObjectManager : public CSingleton<CObjectManager>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-06-20 17:27:43 +00:00
|
|
|
|
CObjectManager(Gfx::CEngine* engine,
|
|
|
|
|
Gfx::CTerrain* terrain,
|
|
|
|
|
Gfx::CModelManager* modelManager,
|
|
|
|
|
Gfx::CParticle* particle,
|
|
|
|
|
CRobotMain* main);
|
2013-03-31 08:21:22 +00:00
|
|
|
|
virtual ~CObjectManager();
|
|
|
|
|
|
2015-06-21 09:16:09 +00:00
|
|
|
|
//! Creates an object
|
|
|
|
|
CObject* CreateObject(Math::Vector pos,
|
|
|
|
|
float angle,
|
|
|
|
|
ObjectType type,
|
|
|
|
|
float power = -1.f,
|
|
|
|
|
float zoom = 1.f,
|
|
|
|
|
float height = 0.f,
|
|
|
|
|
bool trainer = false,
|
|
|
|
|
bool toy = false,
|
|
|
|
|
int option = 0,
|
|
|
|
|
int id = -1);
|
|
|
|
|
|
|
|
|
|
//! Deletes the object
|
2014-12-20 18:09:53 +00:00
|
|
|
|
bool DeleteObject(CObject* instance);
|
2015-06-21 09:16:09 +00:00
|
|
|
|
//! Deletes all objects
|
|
|
|
|
void DeleteAllObjects();
|
|
|
|
|
|
2014-12-21 16:06:55 +00:00
|
|
|
|
//! Finds object by id (CObject::GetID())
|
|
|
|
|
CObject* GetObjectById(unsigned int id);
|
2015-06-21 09:16:09 +00:00
|
|
|
|
|
|
|
|
|
//! Gets object by id in range <0; number of objects - 1)
|
2014-12-21 16:06:55 +00:00
|
|
|
|
CObject* GetObjectByRank(unsigned int id);
|
2015-06-21 09:16:09 +00:00
|
|
|
|
|
2014-12-20 19:36:09 +00:00
|
|
|
|
//! Returns all objects
|
2015-06-21 09:16:09 +00:00
|
|
|
|
inline const CObjectMap& GetAllObjects()
|
|
|
|
|
{
|
|
|
|
|
return m_table;
|
|
|
|
|
}
|
2015-06-20 17:27:43 +00:00
|
|
|
|
|
2014-12-20 19:36:09 +00:00
|
|
|
|
//! Finds an object, like radar() in CBot
|
|
|
|
|
//@{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CObject* Radar(CObject* pThis,
|
|
|
|
|
ObjectType type = OBJECT_NULL,
|
|
|
|
|
float angle = 0.0f,
|
|
|
|
|
float focus = Math::PI*2.0f,
|
|
|
|
|
float minDist = 0.0f,
|
|
|
|
|
float maxDist = 1000.0f,
|
|
|
|
|
bool furthest = false,
|
|
|
|
|
RadarFilter filter = FILTER_NONE,
|
|
|
|
|
bool cbotTypes = false);
|
|
|
|
|
CObject* Radar(CObject* pThis,
|
|
|
|
|
std::vector<ObjectType> type = std::vector<ObjectType>(),
|
|
|
|
|
float angle = 0.0f,
|
|
|
|
|
float focus = Math::PI*2.0f,
|
|
|
|
|
float minDist = 0.0f,
|
|
|
|
|
float maxDist = 1000.0f,
|
|
|
|
|
bool furthest = false,
|
|
|
|
|
RadarFilter filter = FILTER_NONE,
|
|
|
|
|
bool cbotTypes = false);
|
|
|
|
|
CObject* Radar(CObject* pThis,
|
|
|
|
|
Math::Vector thisPosition,
|
|
|
|
|
float thisAngle,
|
|
|
|
|
ObjectType type = OBJECT_NULL,
|
|
|
|
|
float angle = 0.0f,
|
|
|
|
|
float focus = Math::PI*2.0f,
|
|
|
|
|
float minDist = 0.0f,
|
|
|
|
|
float maxDist = 1000.0f,
|
|
|
|
|
bool furthest = false,
|
|
|
|
|
RadarFilter filter = FILTER_NONE,
|
|
|
|
|
bool cbotTypes = false);
|
|
|
|
|
CObject* Radar(CObject* pThis,
|
|
|
|
|
Math::Vector thisPosition,
|
|
|
|
|
float thisAngle,
|
|
|
|
|
std::vector<ObjectType> type = std::vector<ObjectType>(),
|
|
|
|
|
float angle = 0.0f,
|
|
|
|
|
float focus = Math::PI*2.0f,
|
|
|
|
|
float minDist = 0.0f,
|
|
|
|
|
float maxDist = 1000.0f,
|
|
|
|
|
bool furthest = false,
|
|
|
|
|
RadarFilter filter = FILTER_NONE,
|
|
|
|
|
bool cbotTypes = false);
|
2014-12-20 19:36:09 +00:00
|
|
|
|
//@}
|
2014-12-21 16:06:55 +00:00
|
|
|
|
//! Returns nearest object that's closer than maxDist
|
|
|
|
|
//@{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CObject* FindNearest(CObject* pThis,
|
|
|
|
|
ObjectType type = OBJECT_NULL,
|
|
|
|
|
float maxDist = 1000.0f,
|
|
|
|
|
bool cbotTypes = false);
|
|
|
|
|
CObject* FindNearest(CObject* pThis,
|
|
|
|
|
std::vector<ObjectType> type = std::vector<ObjectType>(),
|
|
|
|
|
float maxDist = 1000.0f,
|
|
|
|
|
bool cbotTypes = false);
|
|
|
|
|
CObject* FindNearest(CObject* pThis,
|
|
|
|
|
Math::Vector thisPosition,
|
|
|
|
|
ObjectType type = OBJECT_NULL,
|
|
|
|
|
float maxDist = 1000.0f,
|
|
|
|
|
bool cbotTypes = false);
|
|
|
|
|
CObject* FindNearest(CObject* pThis,
|
|
|
|
|
Math::Vector thisPosition,
|
|
|
|
|
std::vector<ObjectType> type = std::vector<ObjectType>(),
|
|
|
|
|
float maxDist = 1000.0f,
|
|
|
|
|
bool cbotTypes = false);
|
2014-12-21 16:06:55 +00:00
|
|
|
|
//@}
|
2013-03-31 08:21:22 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CObjectMap m_table;
|
2015-06-20 17:27:43 +00:00
|
|
|
|
std::unique_ptr<CObjectFactory> m_objectFactory;
|
2015-06-21 09:16:09 +00:00
|
|
|
|
int m_nextId;
|
2013-03-31 08:21:22 +00:00
|
|
|
|
};
|