Some CRobotMain cleanup

* improved documentation
* renamed cheat variables to include the word "cheat" to make it clearer what they do
* removed some useless members
dev-buzzingcars
krzys-h 2016-12-27 23:38:57 +01:00
parent 6a382830a9
commit 46aa6fc907
9 changed files with 499 additions and 478 deletions

View File

@ -351,7 +351,7 @@ IDL_PROPERTY_SUPPORT = YES
# all members of a group must be documented explicitly. # all members of a group must be documented explicitly.
# The default value is: NO. # The default value is: NO.
DISTRIBUTE_GROUP_DOC = NO DISTRIBUTE_GROUP_DOC = YES
# Set the SUBGROUPING tag to YES to allow class member groups of the same type # Set the SUBGROUPING tag to YES to allow class member groups of the same type
# (for instance a group of public functions) to be put as a subgroup of that # (for instance a group of public functions) to be put as a subgroup of that

View File

@ -19,6 +19,10 @@
#pragma once #pragma once
/**
* \file common/error.h
* \brief Definition of the Error enum
*/
/** /**
* \enum Error * \enum Error

View File

@ -202,8 +202,8 @@ CRobotMain::CRobotMain()
m_editLock = false; m_editLock = false;
m_editFull = false; m_editFull = false;
m_hilite = false; m_hilite = false;
m_selectInsect = false; m_cheatSelectInsect = false;
m_showSoluce = false; m_cheatShowSoluce = false;
m_codeBattleInit = false; m_codeBattleInit = false;
m_codeBattleStarted = false; m_codeBattleStarted = false;
@ -211,14 +211,14 @@ CRobotMain::CRobotMain()
m_teamNames.clear(); m_teamNames.clear();
#if DEV_BUILD #if DEV_BUILD
m_showAll = true; // for development m_cheatAllMission = true; // for development
#else #else
m_showAll = false; m_cheatAllMission = false;
#endif #endif
m_cheatRadar = false; m_cheatRadar = false;
m_fixScene = false; m_fixScene = false;
m_trainerPilot = false; m_cheatTrainerPilot = false;
m_friendAim = false; m_friendAim = false;
m_resetCreate = false; m_resetCreate = false;
m_shortCut = true; m_shortCut = true;
@ -451,7 +451,7 @@ void CRobotMain::ChangePhase(Phase phase)
m_lightning->Flush(); m_lightning->Flush();
m_planet->Flush(); m_planet->Flush();
m_interface->Flush(); m_interface->Flush();
FlushNewScriptName(); m_newScriptName.clear();
m_sound->SetListener(Math::Vector(0.0f, 0.0f, 0.0f), Math::Vector(0.0f, 0.0f, 1.0f)); m_sound->SetListener(Math::Vector(0.0f, 0.0f, 0.0f), Math::Vector(0.0f, 0.0f, 1.0f));
m_sound->StopAll(); m_sound->StopAll();
m_camera->SetType(Gfx::CAM_TYPE_NULL); m_camera->SetType(Gfx::CAM_TYPE_NULL);
@ -922,7 +922,7 @@ bool CRobotMain::ProcessEvent(Event &event)
} }
if (data->slot == INPUT_SLOT_HUMAN) if (data->slot == INPUT_SLOT_HUMAN)
{ {
SelectHuman(); SelectObject(SearchHuman());
} }
if (data->slot == INPUT_SLOT_NEXT && ((event.kmodState & KEY_MOD(CTRL)) != 0)) if (data->slot == INPUT_SLOT_NEXT && ((event.kmodState & KEY_MOD(CTRL)) != 0))
{ {
@ -1159,7 +1159,7 @@ void CRobotMain::ExecuteCmd(const std::string& cmd)
if (cmd == "trainerpilot") if (cmd == "trainerpilot")
{ {
m_trainerPilot = !m_trainerPilot; m_cheatTrainerPilot = !m_cheatTrainerPilot;
return; return;
} }
@ -1410,20 +1410,20 @@ void CRobotMain::ExecuteCmd(const std::string& cmd)
if (cmd == "selectinsect") if (cmd == "selectinsect")
{ {
m_selectInsect = !m_selectInsect; m_cheatSelectInsect = !m_cheatSelectInsect;
return; return;
} }
if (cmd == "showsoluce") if (cmd == "showsoluce")
{ {
m_showSoluce = !m_showSoluce; m_cheatShowSoluce = !m_cheatShowSoluce;
m_ui->ShowSoluceUpdate(); m_ui->ShowSoluceUpdate();
return; return;
} }
if (cmd == "allmission") if (cmd == "allmission")
{ {
m_showAll = !m_showAll; m_cheatAllMission = !m_cheatAllMission;
m_ui->AllMissionUpdate(); m_ui->AllMissionUpdate();
return; return;
} }
@ -1763,20 +1763,17 @@ void CRobotMain::StopDisplayVisit()
//! Updates all the shortcuts
void CRobotMain::UpdateShortcuts() void CRobotMain::UpdateShortcuts()
{ {
m_short->UpdateShortcuts(); m_short->UpdateShortcuts();
} }
//! Returns the object that default was select after the creation of a scene
CObject* CRobotMain::GetSelectObject() CObject* CRobotMain::GetSelectObject()
{ {
if (m_selectObject != nullptr) return m_selectObject; if (m_selectObject != nullptr) return m_selectObject;
return SearchHuman(); return SearchHuman();
} }
//! Deselects everything, and returns the object that was selected
CObject* CRobotMain::DeselectAll() CObject* CRobotMain::DeselectAll()
{ {
CObject* prev = nullptr; CObject* prev = nullptr;
@ -1833,17 +1830,8 @@ void CRobotMain::SelectOneObject(CObject* obj, bool displayError)
{ {
m_camera->SetType(Gfx::CAM_TYPE_BACK); m_camera->SetType(Gfx::CAM_TYPE_BACK);
} }
CObject* toto = SearchToto();
if (toto != nullptr)
{
assert(toto->Implements(ObjectInterfaceType::Movable));
CMotionToto* mt = static_cast<CMotionToto*>(dynamic_cast<CMovableObject*>(toto)->GetMotion());
mt->SetLinkType(type);
}
} }
//! Selects the object aimed by the mouse
bool CRobotMain::SelectObject(CObject* obj, bool displayError) bool CRobotMain::SelectObject(CObject* obj, bool displayError)
{ {
if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT) if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT)
@ -1852,7 +1840,7 @@ bool CRobotMain::SelectObject(CObject* obj, bool displayError)
if (m_movieLock || m_editLock) return false; if (m_movieLock || m_editLock) return false;
if (m_movie->IsExist()) return false; if (m_movie->IsExist()) return false;
if (obj != nullptr && if (obj != nullptr &&
(!obj->Implements(ObjectInterfaceType::Controllable) || !(dynamic_cast<CControllableObject*>(obj)->GetSelectable() || m_selectInsect))) return false; (!obj->Implements(ObjectInterfaceType::Controllable) || !(dynamic_cast<CControllableObject*>(obj)->GetSelectable() || m_cheatSelectInsect))) return false;
if (m_missionType == MISSION_CODE_BATTLE && m_codeBattleStarted && m_codeBattleSpectator) if (m_missionType == MISSION_CODE_BATTLE && m_codeBattleStarted && m_codeBattleSpectator)
{ {
@ -1883,7 +1871,6 @@ bool CRobotMain::SelectObject(CObject* obj, bool displayError)
return true; return true;
} }
//! Deselects the selected object
bool CRobotMain::DeselectObject() bool CRobotMain::DeselectObject()
{ {
DeselectAll(); DeselectAll();
@ -1919,49 +1906,11 @@ void CRobotMain::DeleteAllObjects()
m_objMan->DeleteAllObjects(); m_objMan->DeleteAllObjects();
} }
//! Selects the human
void CRobotMain::SelectHuman()
{
SelectObject(SearchHuman());
}
//! Returns the object human
CObject* CRobotMain::SearchHuman() CObject* CRobotMain::SearchHuman()
{ {
return m_objMan->FindNearest(nullptr, OBJECT_HUMAN); return m_objMan->FindNearest(nullptr, OBJECT_HUMAN);
} }
//! Returns the object toto
CObject* CRobotMain::SearchToto()
{
return m_objMan->FindNearest(nullptr, OBJECT_TOTO);
}
//! Returns the nearest selectable object from a given position
CObject* CRobotMain::SearchNearest(Math::Vector pos, CObject* exclu)
{
float min = 100000.0f;
CObject* best = nullptr;
for (CObject* obj : m_objMan->GetAllObjects())
{
if (obj == exclu) continue;
if (!obj->Implements(ObjectInterfaceType::Controllable) || !(dynamic_cast<CControllableObject*>(obj)->GetSelectable() || m_selectInsect)) continue;
ObjectType type = obj->GetType();
if (type == OBJECT_TOTO) continue;
Math::Vector oPos = obj->GetPosition();
float dist = Math::DistanceProjected(oPos, pos);
if (dist < min)
{
min = dist;
best = obj;
}
}
return best;
}
//! Returns the selected object
CObject* CRobotMain::GetSelect() CObject* CRobotMain::GetSelect()
{ {
for (CObject* obj : m_objMan->GetAllObjects()) for (CObject* obj : m_objMan->GetAllObjects())
@ -2113,7 +2062,7 @@ void CRobotMain::HiliteObject(Math::Point pos)
} }
} }
if (obj->Implements(ObjectInterfaceType::Controllable) && (dynamic_cast<CControllableObject*>(obj)->GetSelectable() || m_selectInsect)) if (obj->Implements(ObjectInterfaceType::Controllable) && (dynamic_cast<CControllableObject*>(obj)->GetSelectable() || m_cheatSelectInsect))
{ {
if (dynamic_cast<CControllableObject*>(obj)->GetSelectable()) if (dynamic_cast<CControllableObject*>(obj)->GetSelectable())
{ {
@ -2652,7 +2601,6 @@ bool CRobotMain::EventObject(const Event &event)
//! Load the scene for the character
void CRobotMain::ScenePerso() void CRobotMain::ScenePerso()
{ {
DeleteAllObjects(); // removes all the current 3D Scene DeleteAllObjects(); // removes all the current 3D Scene
@ -3629,7 +3577,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (line->GetCommand() == "NewScript" && !resetObject) if (line->GetCommand() == "NewScript" && !resetObject)
{ {
AddNewScriptName(line->GetParam("type")->AsObjectType(OBJECT_NULL), const_cast<char*>(line->GetParam("name")->AsPath("ai").c_str())); m_newScriptName.push_back(NewScriptName(line->GetParam("type")->AsObjectType(OBJECT_NULL), const_cast<char*>(line->GetParam("name")->AsPath("ai").c_str())));
continue; continue;
} }
@ -3950,10 +3898,12 @@ void CRobotMain::ChangeColor()
} }
//! Calculates the distance to the nearest object //! Calculates the distance to the nearest object
float CRobotMain::SearchNearestObject(Math::Vector center, CObject *exclu) namespace
{
float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject* exclu)
{ {
float min = 100000.0f; float min = 100000.0f;
for (CObject* obj : m_objMan->GetAllObjects()) for (CObject* obj : objMan->GetAllObjects())
{ {
if (!obj->GetDetectable()) continue; // inactive? if (!obj->GetDetectable()) continue; // inactive?
if (IsObjectBeingTransported(obj)) continue; if (IsObjectBeingTransported(obj)) continue;
@ -3997,6 +3947,7 @@ float CRobotMain::SearchNearestObject(Math::Vector center, CObject *exclu)
} }
return min; return min;
} }
}
//! Calculates a free space //! Calculates a free space
bool CRobotMain::FreeSpace(Math::Vector &center, float minRadius, float maxRadius, bool CRobotMain::FreeSpace(Math::Vector &center, float minRadius, float maxRadius,
@ -4018,7 +3969,7 @@ bool CRobotMain::FreeSpace(Math::Vector &center, float minRadius, float maxRadiu
pos.z = p.y; pos.z = p.y;
pos.y = 0.0f; pos.y = 0.0f;
m_terrain->AdjustToFloor(pos, true); m_terrain->AdjustToFloor(pos, true);
float dist = SearchNearestObject(pos, exclu); float dist = SearchNearestObject(m_objMan.get(), pos, exclu);
if (dist >= space) if (dist >= space)
{ {
float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f); float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f);
@ -4047,7 +3998,7 @@ bool CRobotMain::FreeSpace(Math::Vector &center, float minRadius, float maxRadiu
pos.z = p.y; pos.z = p.y;
pos.y = 0.0f; pos.y = 0.0f;
m_terrain->AdjustToFloor(pos, true); m_terrain->AdjustToFloor(pos, true);
float dist = SearchNearestObject(pos, exclu); float dist = SearchNearestObject(m_objMan.get(), pos, exclu);
if (dist >= space) if (dist >= space)
{ {
float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f); float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f);
@ -4083,7 +4034,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector &center, float minFlat, float minRad
pos.z = p.y; pos.z = p.y;
pos.y = 0.0f; pos.y = 0.0f;
m_terrain->AdjustToFloor(pos, true); m_terrain->AdjustToFloor(pos, true);
float dist = SearchNearestObject(pos, exclu); float dist = SearchNearestObject(m_objMan.get(), pos, exclu);
if (dist >= space) if (dist >= space)
{ {
float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f); float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f);
@ -4116,7 +4067,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector &center, float minFlat, float minRad
pos.z = p.y; pos.z = p.y;
pos.y = 0.0f; pos.y = 0.0f;
m_terrain->AdjustToFloor(pos, true); m_terrain->AdjustToFloor(pos, true);
float dist = SearchNearestObject(pos, exclu); float dist = SearchNearestObject(m_objMan.get(), pos, exclu);
if (dist >= space) if (dist >= space)
{ {
float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f); float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f);
@ -4140,7 +4091,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector &center, float minFlat, float minRad
float CRobotMain::GetFlatZoneRadius(Math::Vector center, float maxRadius, float CRobotMain::GetFlatZoneRadius(Math::Vector center, float maxRadius,
CObject *exclu) CObject *exclu)
{ {
float dist = SearchNearestObject(center, exclu); float dist = SearchNearestObject(m_objMan.get(), center, exclu);
if (dist == 0.0f) return 0.0f; if (dist == 0.0f) return 0.0f;
if (dist < maxRadius) if (dist < maxRadius)
maxRadius = dist; maxRadius = dist;
@ -4412,36 +4363,19 @@ bool CRobotMain::ReadFileStack(CObject *obj, FILE *file, int objRank)
return programmable->ReadStack(file); return programmable->ReadStack(file);
} }
std::vector<std::string> CRobotMain::GetNewScriptNames(ObjectType type)
//! Empty the list
void CRobotMain::FlushNewScriptName()
{ {
m_newScriptName.clear(); std::vector<std::string> names;
} for (const auto& newScript : m_newScriptName)
//! Adds a script name
void CRobotMain::AddNewScriptName(ObjectType type, const std::string& name)
{ {
NewScriptName newscript; if (newScript.type == type ||
newscript.type = type; newScript.type == OBJECT_NULL )
newscript.name = name;
m_newScriptName.push_back(newscript);
}
//! Seeks a script name for a given type
std::string CRobotMain::GetNewScriptName(ObjectType type, int rank)
{ {
for (unsigned int i = 0; i < m_newScriptName.size(); i++) names.push_back(newScript.name);
{
if (m_newScriptName[i].type == type ||
m_newScriptName[i].type == OBJECT_NULL )
{
if (rank == 0) return m_newScriptName[i].name;
else rank --;
} }
} }
return ""; return names;
} }
@ -5114,7 +5048,7 @@ const std::map<std::string, MinMax>& CRobotMain::GetObligatoryTokenList()
//! Indicates whether it is possible to control a driving robot //! Indicates whether it is possible to control a driving robot
bool CRobotMain::GetTrainerPilot() bool CRobotMain::GetTrainerPilot()
{ {
return m_trainerPilot; return m_cheatTrainerPilot;
} }
//! Indicates whether the scene is fixed, without interaction //! Indicates whether the scene is fixed, without interaction
@ -5137,7 +5071,7 @@ const std::string& CRobotMain::GetScriptFile()
bool CRobotMain::GetShowSoluce() bool CRobotMain::GetShowSoluce()
{ {
return m_showSoluce; return m_cheatShowSoluce;
} }
bool CRobotMain::GetSceneSoluce() bool CRobotMain::GetSceneSoluce()
@ -5148,7 +5082,7 @@ bool CRobotMain::GetSceneSoluce()
bool CRobotMain::GetShowAll() bool CRobotMain::GetShowAll()
{ {
return m_showAll; return m_cheatAllMission;
} }
bool CRobotMain::GetRadar() bool CRobotMain::GetRadar()
@ -5272,7 +5206,6 @@ void CRobotMain::UpdateSpeedLabel()
} }
//! Creates interface shortcuts to the units
bool CRobotMain::CreateShortcuts() bool CRobotMain::CreateShortcuts()
{ {
if (m_phase != PHASE_SIMUL) return false; if (m_phase != PHASE_SIMUL) return false;
@ -5662,11 +5595,6 @@ Error CRobotMain::CanBuildError(ObjectType type, int team)
return ERR_OK; return ERR_OK;
} }
bool CRobotMain::CanBuild(ObjectType type, int team)
{
return CanBuildError(type, team) == ERR_OK;
}
Error CRobotMain::CanFactoryError(ObjectType type, int team) Error CRobotMain::CanFactoryError(ObjectType type, int team)
{ {
ToolType tool = GetToolFromObject(type); ToolType tool = GetToolFromObject(type);
@ -5690,11 +5618,6 @@ Error CRobotMain::CanFactoryError(ObjectType type, int team)
return ERR_OK; return ERR_OK;
} }
bool CRobotMain::CanFactory(ObjectType type, int team)
{
return CanFactoryError(type, team) == ERR_OK;
}
void CRobotMain::PushToSelectionHistory(CObject* obj) void CRobotMain::PushToSelectionHistory(CObject* obj)
{ {
if (!m_selectionHistory.empty() && m_selectionHistory.back() == obj) if (!m_selectionHistory.empty() && m_selectionHistory.back() == obj)

View File

@ -120,6 +120,8 @@ struct NewScriptName
{ {
ObjectType type = OBJECT_NULL; ObjectType type = OBJECT_NULL;
std::string name = ""; std::string name = "";
NewScriptName(ObjectType type, const std::string& name) : type(type), name(name) {}
}; };
@ -156,6 +158,17 @@ const int SATCOM_PROG = 4;
const int SATCOM_SOLUCE = 5; const int SATCOM_SOLUCE = 5;
const int SATCOM_MAX = 6; const int SATCOM_MAX = 6;
/**
* \brief Main class managing the game world
*
* This is the main class of the whole game engine. It's main job is to manage main parts of the gameplay,
* like loading levels and checking for win conditions, but it's also a place where all things that don't fit
* elsewhere have landed.
*
* \todo In the future, it would be nice to refactor this class to remove as much unrelated stuff as possible
*
* \nosubgrouping
*/
class CRobotMain : public CSingleton<CRobotMain> class CRobotMain : public CSingleton<CRobotMain>
{ {
public: public:
@ -168,11 +181,16 @@ public:
Ui::CDisplayText* GetDisplayText(); Ui::CDisplayText* GetDisplayText();
CPauseManager* GetPauseManager(); CPauseManager* GetPauseManager();
/**
* \name Phase management
*/
//@{
void ChangePhase(Phase phase); void ChangePhase(Phase phase);
bool ProcessEvent(Event &event); bool ProcessEvent(Event &event);
Phase GetPhase(); Phase GetPhase();
//@}
bool CreateShortcuts(); //! Load the scene for apperance customization
void ScenePerso(); void ScenePerso();
void SetMovieLock(bool lock); void SetMovieLock(bool lock);
@ -187,16 +205,32 @@ public:
void SetFriendAim(bool friendAim); void SetFriendAim(bool friendAim);
bool GetFriendAim(); bool GetFriendAim();
//! \name Simulation speed management
//@{
void SetSpeed(float speed); void SetSpeed(float speed);
float GetSpeed(); float GetSpeed();
//@}
//! \brief Create the shortcuts at the top of the screen, if they should be visible
//! \see CMainShort::CreateShortcuts
bool CreateShortcuts();
//! \brief Update the shortcuts at the top of the screen
//! \see CMainShort::UpdateShortcuts
void UpdateShortcuts(); void UpdateShortcuts();
void SelectHuman(); //! Find the astronaut (::OBJECT_HUMAN) object
CObject* SearchHuman(); CObject* SearchHuman();
CObject* SearchToto(); /**
CObject* SearchNearest(Math::Vector pos, CObject* exclu); * \brief Select an object
* \param obj Object to select
* \param displayError If true and the object is currently in error state, automatically display the error message
*
* \note This function automatically adds objects to selection history (see PushToSelectionHistory())
*/
bool SelectObject(CObject* obj, bool displayError=true); bool SelectObject(CObject* obj, bool displayError=true);
//! Return the object that was selected at the start of the scene
CObject* GetSelectObject(); CObject* GetSelectObject();
//! Deselect currently selected object
//! \return Object that was deselected
CObject* DeselectAll(); CObject* DeselectAll();
void ResetObject(); void ResetObject();
@ -251,9 +285,10 @@ public:
void ClearInterface(); void ClearInterface();
void ChangeColor(); void ChangeColor();
float SearchNearestObject(Math::Vector center, CObject *exclu);
bool FreeSpace(Math::Vector &center, float minRadius, float maxRadius, float space, CObject *exclu); bool FreeSpace(Math::Vector &center, float minRadius, float maxRadius, float space, CObject *exclu);
bool FlatFreeSpace(Math::Vector &center, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu); bool FlatFreeSpace(Math::Vector &center, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu);
//! \name In-world indicators
//@{
float GetFlatZoneRadius(Math::Vector center, float maxRadius, CObject *exclu); float GetFlatZoneRadius(Math::Vector center, float maxRadius, CObject *exclu);
void HideDropZone(CObject* metal); void HideDropZone(CObject* metal);
void ShowDropZone(CObject* metal, CObject* transporter); void ShowDropZone(CObject* metal, CObject* transporter);
@ -262,28 +297,34 @@ public:
float radius, float duration=SHOWLIMITTIME); float radius, float duration=SHOWLIMITTIME);
void StartShowLimit(); void StartShowLimit();
void FrameShowLimit(float rTime); void FrameShowLimit(float rTime);
//@}
void SaveAllScript(); void SaveAllScript();
void SaveOneScript(CObject *obj); void SaveOneScript(CObject *obj);
bool SaveFileStack(CObject *obj, FILE *file, int objRank); bool SaveFileStack(CObject *obj, FILE *file, int objRank);
bool ReadFileStack(CObject *obj, FILE *file, int objRank); bool ReadFileStack(CObject *obj, FILE *file, int objRank);
void FlushNewScriptName(); //! Return list of scripts to load to robot created in BotFactory
void AddNewScriptName(ObjectType type, const std::string& name); std::vector<std::string> GetNewScriptNames(ObjectType type);
std::string GetNewScriptName(ObjectType type, int rank);
void SelectPlayer(std::string playerName); void SelectPlayer(std::string playerName);
CPlayerProfile* GetPlayerProfile(); CPlayerProfile* GetPlayerProfile();
/**
* \name Saved game read/write
*/
//@{
bool IOIsBusy(); bool IOIsBusy();
bool IOWriteScene(std::string filename, std::string filecbot, std::string filescreenshot, const std::string& info, bool emergencySave = false); bool IOWriteScene(std::string filename, std::string filecbot, std::string filescreenshot, const std::string& info, bool emergencySave = false);
void IOWriteSceneFinished(); void IOWriteSceneFinished();
CObject* IOReadScene(std::string filename, std::string filecbot); CObject* IOReadScene(std::string filename, std::string filecbot);
void IOWriteObject(CLevelParserLine *line, CObject* obj, const std::string& programDir, int objRank); void IOWriteObject(CLevelParserLine *line, CObject* obj, const std::string& programDir, int objRank);
CObject* IOReadObject(CLevelParserLine *line, const std::string& programDir, const std::string& objCounterText, float objectProgress, int objRank = -1); CObject* IOReadObject(CLevelParserLine *line, const std::string& programDir, const std::string& objCounterText, float objectProgress, int objRank = -1);
//@}
int CreateSpot(Math::Vector pos, Gfx::Color color); int CreateSpot(Math::Vector pos, Gfx::Color color);
//! Find the currently selected object
CObject* GetSelect(); CObject* GetSelect();
void DisplayError(Error err, CObject* pObj, float time=10.0f); void DisplayError(Error err, CObject* pObj, float time=10.0f);
@ -298,12 +339,17 @@ public:
void StartMissionTimer(); void StartMissionTimer();
/**
* \name Autosave management
*/
//@{
void SetAutosave(bool enable); void SetAutosave(bool enable);
bool GetAutosave(); bool GetAutosave();
void SetAutosaveInterval(int interval); void SetAutosaveInterval(int interval);
int GetAutosaveInterval(); int GetAutosaveInterval();
void SetAutosaveSlots(int slots); void SetAutosaveSlots(int slots);
int GetAutosaveSlots(); int GetAutosaveSlots();
//@}
//! Enable mode where completing mission closes the game //! Enable mode where completing mission closes the game
void SetExitAfterMission(bool exit); void SetExitAfterMission(bool exit);
@ -311,49 +357,97 @@ public:
//! Returns true if player can interact with things manually //! Returns true if player can interact with things manually
bool CanPlayerInteract(); bool CanPlayerInteract();
/**
* \name Team definition management
*/
//@{
//! Returns team name for the given team id //! Returns team name for the given team id
const std::string& GetTeamName(int id); const std::string& GetTeamName(int id);
//! Returns true if team-specific colored texture is available //! Returns true if team-specific colored texture is available
bool IsTeamColorDefined(int id); bool IsTeamColorDefined(int id);
//@}
//! Get/set enabled buildings /**
* \name EnableBuild/EnableResearch/DoneResearch
* Management of enabled buildings, enabled researches, and completed researches
*/
//@{ //@{
/**
* \brief Get enabled buildings
* \return Bitmask of BuildType values
*/
int GetEnableBuild(); int GetEnableBuild();
/**
* \brief Set enabled buildings
* \param enableBuild Bitmask of BuildType values
*/
void SetEnableBuild(int enableBuild); void SetEnableBuild(int enableBuild);
//@}
//! Get/set enabled researches
//@{
int GetEnableResearch();
void SetEnableResearch(int enableResearch);
//@}
//! Get/set done researches
//@{
int GetDoneResearch(int team);
void SetDoneResearch(int doneResearch, int team);
//@}
//! Returns true if the given building is enabled /**
//@{ * \brief Get enabled researches
* \return Bitmask of ResearchType values
*/
int GetEnableResearch();
/**
* \brief Set enabled researches
* \param enableResearch Bitmask of ResearchType values
*/
void SetEnableResearch(int enableResearch);
/**
* \brief Get done researches
* \param team Team to get researches for
* \return Bitmask of ResearchType values
*/
int GetDoneResearch(int team = 0);
/**
* \brief Set done researches
* \param doneResearch Bitmask of ResearchType values
* \param team Team to set researches for
*/
void SetDoneResearch(int doneResearch, int team = 0);
//! \brief Check if the given building is enabled
bool IsBuildingEnabled(BuildType type); bool IsBuildingEnabled(BuildType type);
//! \brief Check if the given building is enabled
bool IsBuildingEnabled(ObjectType type); bool IsBuildingEnabled(ObjectType type);
//@} //! \brief Check if the given research is enabled
//! Returns true if the given research is enabled
bool IsResearchEnabled(ResearchType type); bool IsResearchEnabled(ResearchType type);
//! Returns true if the given research is done //! \brief Check if the given research is done
bool IsResearchDone(ResearchType type, int team); bool IsResearchDone(ResearchType type, int team);
//! Marks research as done //! \brief Mark given research as done
void MarkResearchDone(ResearchType type, int team); void MarkResearchDone(ResearchType type, int team);
//! Retruns true if all requirements to build this object are met (EnableBuild + DoneResearch) /**
//@{ * \brief Check if all requirements to build this object are met (EnableBuild + DoneResearch)
bool CanBuild(ObjectType type, int team); * \return true if the building can be built, false otherwise
* \see CanBuildError() for a version which returns a specific reason for the build being denied
*/
inline bool CanBuild(ObjectType type, int team)
{
return CanBuildError(type, team) == ERR_OK;
}
/**
* \brief Check if all requirements to build this object are met (EnableBuild + DoneResearch)
* \return One of Error values - ::ERR_OK if the building can be built, ::ERR_BUILD_DISABLED or ::ERR_BUILD_RESEARCH otherwise
* \see CanBuild() for a version which returns a boolean
*/
Error CanBuildError(ObjectType type, int team); Error CanBuildError(ObjectType type, int team);
//@}
//! Retruns true if all requirements to create this object in BotFactory are met (DoneResearch) /**
//@{ * \brief Check if all requirements to build this object in BotFactory are met (DoneResearch)
bool CanFactory(ObjectType type, int team); * \return true if the robot can be built, false otherwise
* \see CanFactoryError() for a version which returns a specific reason for the build being denied
*/
inline bool CanFactory(ObjectType type, int team)
{
return CanFactoryError(type, team) == ERR_OK;
}
/**
* \brief Check if all requirements to build this object in BotFactory are met (DoneResearch)
* \return One of Error values - ::ERR_OK if the robot can be built, ::ERR_BUILD_DISABLED or ::ERR_BUILD_RESEARCH otherwise
* \see CanFactory() for a version which returns a boolean
*/
Error CanFactoryError(ObjectType type, int team); Error CanFactoryError(ObjectType type, int team);
//@} //@}
@ -364,7 +458,9 @@ public:
void StartDetectEffect(COldObject* object, CObject* target); void StartDetectEffect(COldObject* object, CObject* target);
//! Enable crash sphere debug rendering
void SetDebugCrashSpheres(bool draw); void SetDebugCrashSpheres(bool draw);
//! Check if crash sphere debug rendering is enabled
bool GetDebugCrashSpheres(); bool GetDebugCrashSpheres();
protected: protected:
@ -388,8 +484,11 @@ protected:
CObject* DetectObject(Math::Point pos); CObject* DetectObject(Math::Point pos);
void ChangeCamera(); void ChangeCamera();
void AbortMovie(); void AbortMovie();
//! \brief Select an object, without deselecting the previous one
void SelectOneObject(CObject* obj, bool displayError=true); void SelectOneObject(CObject* obj, bool displayError=true);
void HelpObject(); void HelpObject();
//! \brief Switch to previous object
//! \see PopFromSelectionHistory()
bool DeselectObject(); bool DeselectObject();
void DeleteAllObjects(); void DeleteAllObjects();
void UpdateInfoText(); void UpdateInfoText();
@ -405,9 +504,13 @@ protected:
void PushToSelectionHistory(CObject* obj); void PushToSelectionHistory(CObject* obj);
CObject* PopFromSelectionHistory(); CObject* PopFromSelectionHistory();
//! \name Code battle interface
//@{
void CreateCodeBattleInterface(); void CreateCodeBattleInterface();
void DestroyCodeBattleInterface(); void DestroyCodeBattleInterface();
void SetCodeBattleSpectatorMode(bool mode); void SetCodeBattleSpectatorMode(bool mode);
//@}
void UpdateDebugCrashSpheres(); void UpdateDebugCrashSpheres();
@ -469,9 +572,9 @@ protected:
ActivePause* m_freePhotoPause = nullptr; ActivePause* m_freePhotoPause = nullptr;
bool m_cmdEdit = false; bool m_cmdEdit = false;
ActivePause* m_cmdEditPause = nullptr; ActivePause* m_cmdEditPause = nullptr;
bool m_selectInsect = false; bool m_cheatSelectInsect = false;
bool m_showSoluce = false; bool m_cheatShowSoluce = false;
bool m_showAll = false; bool m_cheatAllMission = false;
bool m_cheatRadar = false; bool m_cheatRadar = false;
bool m_shortCut = false; bool m_shortCut = false;
std::string m_audioTrack; std::string m_audioTrack;
@ -493,7 +596,7 @@ protected:
bool m_editLock = false; // edition in progress? bool m_editLock = false; // edition in progress?
bool m_editFull = false; // edition in full screen? bool m_editFull = false; // edition in full screen?
bool m_hilite = false; bool m_hilite = false;
bool m_trainerPilot = false; // remote trainer? bool m_cheatTrainerPilot = false; // remote trainer?
bool m_friendAim = false; bool m_friendAim = false;
bool m_resetCreate = false; bool m_resetCreate = false;
bool m_mapShow = false; bool m_mapShow = false;

View File

@ -664,11 +664,9 @@ bool CAutoFactory::CreateVehicle()
if (vehicle->Implements(ObjectInterfaceType::ProgramStorage)) if (vehicle->Implements(ObjectInterfaceType::ProgramStorage))
{ {
CProgramStorageObject* programStorage = dynamic_cast<CProgramStorageObject*>(vehicle); CProgramStorageObject* programStorage = dynamic_cast<CProgramStorageObject*>(vehicle);
for ( int i=0 ; ; i++ ) for (const std::string& name : m_main->GetNewScriptNames(m_type))
{ {
std::string name = m_main->GetNewScriptName(m_type, i); Program* prog = programStorage->AddProgram();
if (name.empty()) break;
Program* prog = programStorage->GetOrAddProgram(i);
programStorage->ReadProgram(prog, InjectLevelPathsForCurrentLevel(name)); programStorage->ReadProgram(prog, InjectLevelPathsForCurrentLevel(name));
prog->readOnly = true; prog->readOnly = true;
prog->filename = name; prog->filename = name;

View File

@ -57,7 +57,6 @@ CMotionToto::CMotionToto(COldObject* object) : CMotion(object)
m_blinkTime = 0.0f; m_blinkTime = 0.0f;
m_blinkProgress = -1.0f; m_blinkProgress = -1.0f;
m_lastMotorParticle = 0.0f; m_lastMotorParticle = 0.0f;
m_type = OBJECT_NULL;
m_mousePos = Math::Point(0.0f, 0.0f); m_mousePos = Math::Point(0.0f, 0.0f);
} }
@ -326,35 +325,38 @@ bool CMotionToto::EventFrame(const Event &event)
shift = 18.0f-progress*11.0f; // shift is left shift = 18.0f-progress*11.0f; // shift is left
verti = 10.0f-progress* 8.0f; // shift at the top verti = 10.0f-progress* 8.0f; // shift at the top
CObject* selected = m_main->GetSelect();
ObjectType type = selected != nullptr ? selected->GetType() : OBJECT_NULL;
if ( m_actionType == -1 && if ( m_actionType == -1 &&
(m_type == OBJECT_HUMAN || (type == OBJECT_HUMAN ||
m_type == OBJECT_TECH || type == OBJECT_TECH ||
m_type == OBJECT_MOBILEwa || type == OBJECT_MOBILEwa ||
m_type == OBJECT_MOBILEta || type == OBJECT_MOBILEta ||
m_type == OBJECT_MOBILEfa || type == OBJECT_MOBILEfa ||
m_type == OBJECT_MOBILEia || type == OBJECT_MOBILEia ||
m_type == OBJECT_MOBILEwc || type == OBJECT_MOBILEwc ||
m_type == OBJECT_MOBILEtc || type == OBJECT_MOBILEtc ||
m_type == OBJECT_MOBILEfc || type == OBJECT_MOBILEfc ||
m_type == OBJECT_MOBILEic || type == OBJECT_MOBILEic ||
m_type == OBJECT_MOBILEwi || type == OBJECT_MOBILEwi ||
m_type == OBJECT_MOBILEti || type == OBJECT_MOBILEti ||
m_type == OBJECT_MOBILEfi || type == OBJECT_MOBILEfi ||
m_type == OBJECT_MOBILEii || type == OBJECT_MOBILEii ||
m_type == OBJECT_MOBILEws || type == OBJECT_MOBILEws ||
m_type == OBJECT_MOBILEts || type == OBJECT_MOBILEts ||
m_type == OBJECT_MOBILEfs || type == OBJECT_MOBILEfs ||
m_type == OBJECT_MOBILEis || type == OBJECT_MOBILEis ||
m_type == OBJECT_MOBILErt || type == OBJECT_MOBILErt ||
m_type == OBJECT_MOBILErc || type == OBJECT_MOBILErc ||
m_type == OBJECT_MOBILErr || type == OBJECT_MOBILErr ||
m_type == OBJECT_MOBILErs || type == OBJECT_MOBILErs ||
m_type == OBJECT_MOBILEsa || type == OBJECT_MOBILEsa ||
m_type == OBJECT_MOBILEwt || type == OBJECT_MOBILEwt ||
m_type == OBJECT_MOBILEtt || type == OBJECT_MOBILEtt ||
m_type == OBJECT_MOBILEft || type == OBJECT_MOBILEft ||
m_type == OBJECT_MOBILEit || type == OBJECT_MOBILEit ||
m_type == OBJECT_MOBILEdr ) ) // vehicle? type == OBJECT_MOBILEdr ) ) // vehicle?
{ {
m_clownTime += event.rTime; m_clownTime += event.rTime;
if ( m_clownTime >= m_clownDelay ) if ( m_clownTime >= m_clownDelay )
@ -832,10 +834,3 @@ Error CMotionToto::SetAction(int action, float time)
return ERR_OK; return ERR_OK;
} }
// Specifies the type of the object is attached to toto.
void CMotionToto::SetLinkType(ObjectType type)
{
m_type = type;
}

View File

@ -43,7 +43,6 @@ public:
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::COldModelManager* modelManager) override; void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::COldModelManager* modelManager) override;
bool EventProcess(const Event &event) override; bool EventProcess(const Event &event) override;
Error SetAction(int action, float time=0.2f) override; Error SetAction(int action, float time=0.2f) override;
void SetLinkType(ObjectType type);
void StartDisplayInfo(); void StartDisplayInfo();
void StopDisplayInfo(); void StopDisplayInfo();
@ -65,6 +64,5 @@ protected:
float m_blinkTime; float m_blinkTime;
float m_blinkProgress; float m_blinkProgress;
int m_soundChannel; int m_soundChannel;
ObjectType m_type;
Math::Point m_mousePos; Math::Point m_mousePos;
}; };

View File

@ -282,7 +282,7 @@ void CMainShort::SelectNext()
if (m_shortcuts.size() == 0) if (m_shortcuts.size() == 0)
{ {
m_main->SelectHuman(); m_main->SelectObject(m_main->SearchHuman());
return; return;
} }