From 7e18757d290896068572b6df9df7fe6295fbc292 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 11 Aug 2015 17:51:39 +0200 Subject: [PATCH] CScript user pointer cleanup; moved some functions from COldObjectInterface to main CObject * moved (Get|Set)Clip [renamed to (Get|Set)Collisions], (Get|Set)Team, (Get|Set)Proxy(Activate|Distance) and GetBotVar to main CObject class * refactored scripting to pass CScript* as the user pointer, removing the need for GetRunScript() * changed accessing of "object" class in CBot to use ->GetUserPtr() * refactored object limits to remove (Start|Stop)ShowLimit from COldObject * added notes on possible interfaces for most of the other COldObjectInterface functions --- src/CBot/CBotProgram.cpp | 5 - src/object/auto/autodestroyer.cpp | 3 +- src/object/object.cpp | 73 ++++++++++++ src/object/object.h | 29 +++++ src/object/old_object.cpp | 147 ++--------------------- src/object/old_object.h | 23 +--- src/object/old_object_interface.cpp | 48 +------- src/object/old_object_interface.h | 83 ++++++------- src/object/robotmain.cpp | 40 ++++--- src/object/robotmain.h | 1 - src/physics/physics.cpp | 2 +- src/script/script.cpp | 10 +- src/script/script.h | 2 +- src/script/scriptfunc.cpp | 173 +++++++++++++--------------- 14 files changed, 267 insertions(+), 372 deletions(-) diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index e28689a8..96267199 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -81,9 +81,6 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, ListFonctions.SetSize(0); m_ErrorCode = 0; - if (m_pInstance != NULL && m_pInstance->m_pUserPtr != NULL) - pUser = m_pInstance->m_pUserPtr; - // transforms the program in Tokens CBotToken* pBaseToken = CBotToken::CompileTokens(program, error); if ( pBaseToken == NULL ) return false; @@ -220,8 +217,6 @@ bool CBotProgram::Run(void* pUser, int timer) if (m_pStack == NULL || m_pRun == NULL) goto error; m_ErrorCode = 0; - if (m_pInstance != NULL && m_pInstance->m_pUserPtr != NULL) - pUser = m_pInstance->m_pUserPtr; m_pStack->Reset(pUser); // empty the possible previous error, and resets the timer if ( timer >= 0 ) m_pStack->SetTimer(timer); diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index de6469ad..dcafffff 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -172,7 +172,7 @@ bool CAutoDestroyer::EventProcess(const Event &event) if ( scrap != nullptr ) { //m_engine->GetPyroManager()->Create(Gfx::PT_FRAGT, scrap); - scrap->ExplodeObject(ExplosionType::Bang, std::numeric_limits::infinity()); + scrap->ExplodeObject(ExplosionType::Bang, 1.0f); } m_bExplo = true; } @@ -393,4 +393,3 @@ void CAutoDestroyer::EnableInterface(Ui::CWindow *pw, EventType event, bool bSta control->SetState(Ui::STATE_ENABLE, bState); } - diff --git a/src/object/object.cpp b/src/object/object.cpp index 8eae64a4..3ab7e764 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -1,7 +1,28 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, 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 + */ + #include "object/object.h" #include "graphics/model/model_crash_sphere.h" +#include "script/scriptfunc.h" + CObject::CObject(int id, ObjectType type) : m_id(id) @@ -10,12 +31,18 @@ CObject::CObject(int id, ObjectType type) , m_rotation(0.0f, 0.0f, 0.0f) , m_scale(1.0f, 1.0f, 1.0f) , m_animateOnReset(false) + , m_collisions(true) + , m_team(0) + , m_proxyActivate(false) + , m_proxyDistance(60.0f) { m_implementedInterfaces.fill(false); + m_botVar = CScriptFunctions::CreateObjectVar(this); } CObject::~CObject() { + CScriptFunctions::DestroyObjectVar(m_botVar, true); } void CObject::SetCrashSpheres(const std::vector& crashSpheres) @@ -64,6 +91,7 @@ Math::Vector CObject::GetPosition() const void CObject::SetPosition(const Math::Vector& pos) { // TODO: provide default implementation... + throw std::logic_error("CObject::SetPosition() - not implemented!"); } Math::Vector CObject::GetRotation() const @@ -74,6 +102,7 @@ Math::Vector CObject::GetRotation() const void CObject::SetRotation(const Math::Vector& rotation) { // TODO: provide default implementation... + throw std::logic_error("CObject::SetRotation() - not implemented!"); } void CObject::SetRotationX(float angle) @@ -120,6 +149,7 @@ Math::Vector CObject::GetScale() const void CObject::SetScale(const Math::Vector& scale) { // TODO: provide default implementation... + throw std::logic_error("CObject::SetScale() - not implemented!"); } void CObject::SetScale(float scale) @@ -195,4 +225,47 @@ void CObject::SetAnimateOnReset(bool animateOnReset) m_animateOnReset = animateOnReset; } +void CObject::SetCollisions(bool collisions) +{ + m_collisions = collisions; +} +bool CObject::GetCollisions() +{ + return m_collisions; +} + +void CObject::SetTeam(int team) +{ + m_team = team; +} + +int CObject::GetTeam() +{ + return m_team; +} + +void CObject::SetProxyActivate(bool activate) +{ + m_proxyActivate = activate; +} + +bool CObject::GetProxyActivate() +{ + return m_proxyActivate; +} + +void CObject::SetProxyDistance(float distance) +{ + m_proxyDistance = distance; +} + +float CObject::GetProxyDistance() +{ + return m_proxyDistance; +} + +CBotVar* CObject::GetBotVar() +{ + return m_botVar; +} diff --git a/src/object/object.h b/src/object/object.h index 0beef7d5..f28ec402 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -36,6 +36,7 @@ struct ModelCrashSphere; } // namespace Gfx class CLevelParserLine; +class CBotVar; /** * \class CObject @@ -157,6 +158,29 @@ public: //! Returns flag controlling animation effect on level reset bool GetAnimateOnReset(); + //! Turns object collisions on/off + void SetCollisions(bool collisions); + //! Returns true if collisions are enabled + bool GetCollisions(); + + //! Sets object team (shouldn't be called after creation because the model won't update!) + void SetTeam(int team); + //! Returns object team + int GetTeam(); + + //! Enable object activation only after you come close + void SetProxyActivate(bool activate); + //! Returns close activation mode + bool GetProxyActivate(); + + //! Sets distance for close activation + void SetProxyDistance(float distance); + //! Returns distance for close activation + float GetProxyDistance(); + + //! Returns CBot "object" variable associated with this object + CBotVar* GetBotVar(); + protected: //! Transform crash sphere by object's world matrix virtual void TransformCrashSphere(Math::Sphere& crashSphere) = 0; @@ -173,4 +197,9 @@ protected: std::vector m_crashSpheres; //!< crash spheres Math::Sphere m_cameraCollisionSphere; bool m_animateOnReset; + bool m_collisions; + int m_team; + bool m_proxyActivate; + float m_proxyDistance; + CBotVar* m_botVar; }; diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 090c6bcd..180c3956 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -118,7 +118,6 @@ COldObject::COldObject(int id) m_main = CRobotMain::GetInstancePointer(); m_terrain = m_main->GetTerrain(); m_camera = m_main->GetCamera(); - m_runScript = nullptr; m_type = OBJECT_FIX; m_option = 0; @@ -144,13 +143,10 @@ COldObject::COldObject(int id) m_bCheckToken = true; m_bVisible = true; m_bEnable = true; - m_bProxyActivate = false; m_bTrainer = false; m_bToy = false; m_bManual = false; m_bFixed = false; - m_bClip = true; - m_bShowLimit = false; m_showLimitRadius = 0.0f; m_aTime = 0.0f; m_shotTime = 0.0f; @@ -168,10 +164,8 @@ COldObject::COldObject(int id) m_shieldRadius = 0.0f; m_defRank = -1; m_magnifyDamage = 1.0f; - m_proxyDistance = 60.0f; m_param = 0.0f; m_infoReturn = NAN; - m_team = 0; m_character = Character(); m_character.wheelFront = 1.0f; @@ -211,16 +205,12 @@ COldObject::COldObject(int id) m_traceRecord = false; DeleteAllCrashSpheres(); - - m_botVar = CScriptFunctions::CreateObjectVar(this); } // Object's destructor. COldObject::~COldObject() { - CScriptFunctions::DestroyObjectVar(m_botVar, true); - m_botVar = nullptr; } @@ -341,12 +331,6 @@ void COldObject::DeleteObject(bool bAll) } } - if ( m_bShowLimit ) - { - m_main->FlushShowLimit(0); - m_bShowLimit = false; - } - if ( !bAll ) m_main->CreateShortcuts(); } @@ -601,7 +585,7 @@ bool COldObject::ExplodeObject(ExplosionType type, float force, float decay) m_team = 0; // Back to neutral on destruction - if ( m_botVar != 0 ) + if ( m_botVar != nullptr ) { if ( m_type == OBJECT_STONE || m_type == OBJECT_URANIUM || @@ -799,11 +783,12 @@ void COldObject::Write(CLevelParserLine* line) line->AddParam("enable", MakeUnique(GetEnable())); // TODO: doesn't seem to be used + // But it is, this is used by aliens after Thumper ~krzys_h if ( GetFixed() ) line->AddParam("fixed", MakeUnique(GetFixed())); - if ( !GetClip() ) - line->AddParam("clip", MakeUnique(GetClip())); + if ( !GetCollisions() ) + line->AddParam("clip", MakeUnique(GetCollisions())); if ( GetLock() ) line->AddParam("lock", MakeUnique(GetLock())); @@ -894,7 +879,7 @@ void COldObject::Read(CLevelParserLine* line) SetSelectable(line->GetParam("selectable")->AsBool(true)); SetEnable(line->GetParam("enable")->AsBool(true)); SetFixed(line->GetParam("fixed")->AsBool(false)); - SetClip(line->GetParam("clip")->AsBool(true)); + SetCollisions(line->GetParam("clip")->AsBool(true)); SetLock(line->GetParam("lock")->AsBool(false)); SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false)); SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit); @@ -1173,11 +1158,6 @@ void COldObject::SetPartPosition(int part, const Math::Vector &pos) lightPos.y += m_effectHeight; m_lightMan->SetLightPos(m_effectLight, lightPos); } - - if ( m_bShowLimit ) - { - m_main->AdjustShowLimit(0, pos); - } } } @@ -2065,20 +2045,6 @@ bool COldObject::EventFrame(const Event &event) UpdateTransformObject(); UpdateSelectParticle(); - if ( m_bProxyActivate ) // active if it is near? - { - Math::Vector eye = m_engine->GetLookatPt(); - float dist = Math::Distance(eye, GetPosition()); - if ( dist < m_proxyDistance ) - { - m_bProxyActivate = false; - m_main->CreateShortcuts(); - m_sound->Play(SOUND_FINDING); - m_engine->GetPyroManager()->Create(Gfx::PT_FINDING, this, 0.0f); - m_main->DisplayError(INFO_FINDING, this); - } - } - if (Implements(ObjectInterfaceType::Programmable)) { if ( GetActivity() ) @@ -2471,33 +2437,6 @@ bool COldObject::GetFixed() } -// Indicates whether an object is subjected to clipping (obstacles). - -void COldObject::SetClip(bool bClip) -{ - m_bClip = bClip; -} - -bool COldObject::GetClip() -{ - return m_bClip; -} - - -// Controls object team - -void COldObject::SetTeam(int team) -{ - // NOTE: This shouldn't be called after the object is already created - m_team = team; -} - -int COldObject::GetTeam() -{ - return m_team; -} - - // Pushes an object. bool COldObject::JostleObject(float force) @@ -2751,28 +2690,6 @@ bool COldObject::GetEnable() } -// Management mode or an object is only active when you're close. - -void COldObject::SetProxyActivate(bool bActivate) -{ - m_bProxyActivate = bActivate; -} - -bool COldObject::GetProxyActivate() -{ - return m_bProxyActivate; -} - -void COldObject::SetProxyDistance(float distance) -{ - m_proxyDistance = distance; -} - -float COldObject::GetProxyDistance() -{ - return m_proxyDistance; -} - // Management of the method of increasing damage. @@ -2831,12 +2748,6 @@ void COldObject::SetBurn(bool bBurn) { m_bBurn = bBurn; m_burnTime = 0.0f; - -//? if ( m_botVar != 0 ) -//? { -//? if ( m_bBurn ) m_botVar->SetUserPtr(OBJECTDELETED); -//? else m_botVar->SetUserPtr(this); -//? } } bool COldObject::GetBurn() @@ -2852,12 +2763,6 @@ void COldObject::SetDead(bool bDead) { StopProgram(); // stops the current task } - -//? if ( m_botVar != 0 ) -//? { -//? if ( m_bDead ) m_botVar->SetUserPtr(OBJECTDELETED); -//? else m_botVar->SetUserPtr(this); -//? } } bool COldObject::GetDead() @@ -2956,29 +2861,16 @@ float COldObject::GetGunGoalH() return m_gunGoalH; } - - -// Shows the limits of the object. - -bool COldObject::StartShowLimit() -{ - if ( m_showLimitRadius == 0.0f ) return false; - - m_main->SetShowLimit(0, Gfx::PARTILIMIT1, this, GetPosition(), m_showLimitRadius); - m_bShowLimit = true; - return true; -} - -void COldObject::StopShowLimit() -{ - m_bShowLimit = false; -} - void COldObject::SetShowLimitRadius(float radius) { m_showLimitRadius = radius; } +float COldObject::GetShowLimitRadius() +{ + return m_showLimitRadius; +} + // Creates or removes particles associated to the object. @@ -3195,25 +3087,6 @@ void COldObject::UpdateSelectParticle() } -// Getes the pointer to the current script execution. - -void COldObject::SetRunScript(CScript* script) -{ - m_runScript = script; -} - -CScript* COldObject::GetRunScript() -{ - return m_runScript; -} - -// Returns the variables of "this" for CBOT. - -CBotVar* COldObject::GetBotVar() -{ - return m_botVar; -} - // Returns the physics associated to the object. CPhysics* COldObject::GetPhysics() diff --git a/src/object/old_object.h b/src/object/old_object.h index 2fec06e4..48627424 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -100,7 +100,6 @@ protected: void SetAuto(std::unique_ptr automat); void SetShowLimitRadius(float radius); void SetCapacity(float capacity); - float GetProxyDistance(); void SetOption(int option); void SetJostlingSphere(const Math::Sphere& sphere); @@ -215,12 +214,6 @@ public: void SetFixed(bool bFixed) override; bool GetFixed() override; - void SetClip(bool bClip) override; - bool GetClip() override; - - void SetTeam(int team) override; - int GetTeam() override; - Math::Sphere GetJostlingSphere() const override; bool JostleObject(float force) override; @@ -255,10 +248,6 @@ public: void SetCheckToken(bool bMode); bool GetCheckToken(); - void SetProxyActivate(bool bActivate) override; - bool GetProxyActivate() override; - void SetProxyDistance(float distance); - void SetMagnifyDamage(float factor) override; float GetMagnifyDamage() override; @@ -281,14 +270,10 @@ public: float GetGunGoalV(); float GetGunGoalH(); - bool StartShowLimit() override; - void StopShowLimit() override; + float GetShowLimitRadius() override; void CreateSelectParticle(); - void SetRunScript(CScript* script); - CScript* GetRunScript() override; - CBotVar* GetBotVar() override; CPhysics* GetPhysics() override; CMotion* GetMotion() override; CAuto* GetAuto() override; @@ -424,9 +409,6 @@ protected: std::unique_ptr m_auto; std::unique_ptr m_objectInterface; - CBotVar* m_botVar; - CScript* m_runScript; - std::string m_name; // name of the object Character m_character; // characteristic int m_option; // option @@ -457,7 +439,6 @@ protected: bool m_bCheckToken; // object with audited tokens bool m_bVisible; // object active but undetectable bool m_bEnable; // dead object - bool m_bProxyActivate; // active object so close bool m_bLock; bool m_bExplo; bool m_bCargo; @@ -469,7 +450,6 @@ protected: bool m_bManual; // manual control (Scribbler) bool m_bFixed; bool m_bClip; - bool m_bShowLimit; float m_showLimitRadius; float m_gunGoalV; float m_gunGoalH; @@ -478,7 +458,6 @@ protected: bool m_bCameraLock; int m_defRank; float m_magnifyDamage; - float m_proxyDistance; float m_param; int m_team; diff --git a/src/object/old_object_interface.cpp b/src/object/old_object_interface.cpp index c9f4e995..b03d612f 100644 --- a/src/object/old_object_interface.cpp +++ b/src/object/old_object_interface.cpp @@ -152,25 +152,6 @@ bool COldObjectInterface::GetFixed() } -void COldObjectInterface::SetClip(bool bClip) -{ - throw std::logic_error("SetClip: not implemented!"); -} - -bool COldObjectInterface::GetClip() -{ - throw std::logic_error("GetClip: not implemented!"); -} -void COldObjectInterface::SetTeam(int team) -{ - throw std::logic_error("SetTeam: not implemented!"); -} - -int COldObjectInterface::GetTeam() -{ - throw std::logic_error("GetTeam: not implemented!"); -} - void COldObjectInterface::StartDetectEffect(CObject *target, bool bFound) { throw std::logic_error("StartDetectEffect: not implemented!"); @@ -208,17 +189,6 @@ bool COldObjectInterface::GetEnable() } -void COldObjectInterface::SetProxyActivate(bool bActivate) -{ - throw std::logic_error("SetProxyActivate: not implemented!"); -} - -bool COldObjectInterface::GetProxyActivate() -{ - throw std::logic_error("GetProxyActivate: not implemented!"); -} - - void COldObjectInterface::SetMagnifyDamage(float factor) { throw std::logic_error("SetMagnifyDamage: not implemented!"); @@ -303,26 +273,12 @@ bool COldObjectInterface::GetActive() //throw std::logic_error("GetActive: not implemented!"); } -bool COldObjectInterface::StartShowLimit() +float COldObjectInterface::GetShowLimitRadius() { - throw std::logic_error("StartShowLimit: not implemented!"); -} - -void COldObjectInterface::StopShowLimit() -{ - throw std::logic_error("StopShowLimit: not implemented!"); + throw std::logic_error("GetShowLimitRadius: not implemented!"); } -CScript* COldObjectInterface::GetRunScript() -{ - throw std::logic_error("GetRunScript: not implemented!"); -} - -CBotVar* COldObjectInterface::GetBotVar() -{ - throw std::logic_error("GetBotVar: not implemented!"); -} CPhysics* COldObjectInterface::GetPhysics() { throw std::logic_error("GetPhysics: not implemented!"); diff --git a/src/object/old_object_interface.h b/src/object/old_object_interface.h index 79720ca8..de9a665f 100644 --- a/src/object/old_object_interface.h +++ b/src/object/old_object_interface.h @@ -91,40 +91,42 @@ public: virtual Character* GetCharacter(); + virtual void FlatParent(); + + // This goes to CPowerContainerObject [implemented by: PowerCell, NuclearCell, PowerStation, PowerPlant] virtual void SetEnergy(float level); virtual float GetEnergy(); virtual float GetCapacity(); + // This goes to CShieldedObject (probably will inherit from CDestroyableObject) virtual void SetShield(float level); virtual float GetShield(); - - virtual void SetRange(float delay); - virtual float GetRange(); - - virtual void SetFixed(bool bFixed); - virtual bool GetFixed(); - - virtual void SetClip(bool bClip); - virtual bool GetClip(); - virtual void SetTeam(int team); - virtual int GetTeam(); - - virtual void StartDetectEffect(CObject *target, bool bFound); - - virtual void SetVirusMode(bool bEnable); - virtual bool GetVirusMode(); - - virtual void SetHighlight(bool mode); - - virtual void SetEnable(bool bEnable); - virtual bool GetEnable(); - - virtual void SetProxyActivate(bool bActivate); - virtual bool GetProxyActivate(); - virtual void SetMagnifyDamage(float factor); virtual float GetMagnifyDamage(); + // This goes to CFlyingObject (child of CMovableObject) + virtual void SetRange(float delay); + virtual float GetRange(); + + // This goes to CBaseAlien or something like that + virtual void SetFixed(bool bFixed); + virtual bool GetFixed(); + + // This either goes to CProgrammableObject or gets removed entirely (detect() was used in Ceebot-Teen only, unless we want to restore it) + virtual void StartDetectEffect(CObject *target, bool bFound); + + // Not sure. Maybe a separate interface, or maybe CControllableObject (buildings can have viruses too) + virtual void SetVirusMode(bool bEnable); + virtual bool GetVirusMode(); + + // This sets highlight on mouse over object, goes to CControllableObject + virtual void SetHighlight(bool mode); + + // Main CObject class? + virtual void SetEnable(bool bEnable); + virtual bool GetEnable(); + + // These go to Shielder subclass //! Shielder radius (only while active) [0 or RADIUS_SHIELD_MIN..RADIUS_SHIELD_MAX] virtual float GetShieldRadius(); //! Shielder radius [0..1] @@ -133,37 +135,36 @@ public: virtual float GetParam(); //@} + // TODO: What to do with these? virtual void SetExploding(bool bExplo); virtual bool IsExploding(); + virtual void SetBurn(bool bBurn); + virtual bool GetBurn(); + virtual void SetDead(bool bDead); + virtual bool GetDead(); + virtual bool GetRuin(); + virtual bool GetActive(); + // probably main CObject? virtual void SetLock(bool bLock); virtual bool GetLock(); - virtual void SetBurn(bool bBurn); - virtual bool GetBurn(); + // Not sure. CRangedObject? + virtual float GetShowLimitRadius(); - virtual void SetDead(bool bDead); - virtual bool GetDead(); - - virtual bool GetRuin(); - - virtual bool GetActive(); - - virtual bool StartShowLimit(); - virtual void StopShowLimit(); - - virtual CScript* GetRunScript(); - virtual CBotVar* GetBotVar(); virtual CPhysics* GetPhysics(); virtual CMotion* GetMotion(); + + // This will be eventually removed after refactoring to subclasses virtual CAuto* GetAuto(); + // TODO: We'll see if this is still needed after I refactor program storage later virtual void SetDefRank(int rank); virtual int GetDefRank(); + // main CObject? not sure virtual bool GetTooltipName(std::string& name); - virtual void FlatParent(); - + // CProgrammableObject or refactor virtual float GetInfoReturn(); }; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index cc07260c..4b668d80 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -1185,7 +1185,7 @@ void CRobotMain::ExecuteCmd(char *cmd) { CObject* object = GetSelect(); if (object != nullptr) - object->SetClip(false); + object->SetCollisions(false); return; } @@ -1193,7 +1193,7 @@ void CRobotMain::ExecuteCmd(char *cmd) { CObject* object = GetSelect(); if (object != nullptr) - object->SetClip(true); + object->SetCollisions(true); return; } @@ -2555,6 +2555,20 @@ bool CRobotMain::EventFrame(const Event &event) toto = obj; else if (obj->Implements(ObjectInterfaceType::Interactive)) dynamic_cast(obj)->EventProcess(event); + + if ( obj->GetProxyActivate() ) // active if it is near? + { + Math::Vector eye = m_engine->GetLookatPt(); + float dist = Math::Distance(eye, obj->GetPosition()); + if ( dist < obj->GetProxyActivate() ) + { + obj->SetProxyActivate(false); + CreateShortcuts(); + m_sound->Play(SOUND_FINDING); + m_engine->GetPyroManager()->Create(Gfx::PT_FINDING, obj, 0.0f); + DisplayError(INFO_FINDING, obj); + } + } } // Advances all objects transported by robots. for (CObject* obj : m_objMan->GetAllObjects()) @@ -3610,7 +3624,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) oldObj->SetRange(line->GetParam("range")->AsFloat(30.0f)); oldObj->SetShield(line->GetParam("shield")->AsFloat(1.0f)); oldObj->SetMagnifyDamage(line->GetParam("magnifyDamage")->AsFloat(1.0f)); - oldObj->SetClip(line->GetParam("clip")->AsBool(true)); + oldObj->SetCollisions(line->GetParam("clip")->AsBool(true)); oldObj->SetCheckToken(!line->GetParam("checkToken")->IsDefined() ? trainer || !selectable : line->GetParam("checkToken")->AsBool(true)); // SetManual will affect bot speed if (type == OBJECT_MOBILEdr) @@ -4547,11 +4561,6 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* transporter) //! Erases the boundaries shown void CRobotMain::FlushShowLimit(int i) { - if (m_showLimit[i].link != 0) - { - m_showLimit[i].link->StopShowLimit(); - } - for (int j = 0; j < m_showLimit[i].total; j++) { if (m_showLimit[i].parti[j] == 0) continue; @@ -4601,19 +4610,13 @@ void CRobotMain::SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, } } -//! Adjusts the boundaries to show -void CRobotMain::AdjustShowLimit(int i, Math::Vector pos) -{ - m_showLimit[i].pos = pos; -} - //! Mount the boundaries of the selected object void CRobotMain::StartShowLimit() { CObject* obj = GetSelect(); if (obj == nullptr) return; - - obj->StartShowLimit(); + if (obj->GetShowLimitRadius() == 0.0f) return; + SetShowLimit(0, Gfx::PARTILIMIT1, obj, obj->GetPosition(), obj->GetShowLimitRadius()); } //! Advances the boundaries shown @@ -4645,6 +4648,11 @@ void CRobotMain::FrameShowLimit(float rTime) if (speed < 0.1f) speed = 0.1f; float angle = m_showLimit[i].time*speed; + if (m_showLimit[i].link != nullptr) + { + m_showLimit[i].pos = m_showLimit[i].link->GetPosition(); + } + for (int j = 0; j < m_showLimit[i].total; j++) { if (m_showLimit[i].parti[j] == 0) continue; diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 550641bc..0fb18b24 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -267,7 +267,6 @@ public: void FlushShowLimit(int i); void SetShowLimit(int i, Gfx::ParticleType parti, CObject *pObj, Math::Vector pos, float radius, float duration=SHOWLIMITTIME); - void AdjustShowLimit(int i, Math::Vector pos); void StartShowLimit(); void FrameShowLimit(float rTime); diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 78dd0c2d..a7adacf7 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -2495,7 +2495,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) ObjectType iType, oType; if ( m_object->GetRuin() ) return 0; // is burning or exploding? - if ( !m_object->GetClip() ) return 0; + if ( !m_object->GetCollisions() ) return 0; // iiPos = sphere center is the old position. // iPos = sphere center has the new position. diff --git a/src/script/script.cpp b/src/script/script.cpp index cc35d7bb..e66f8365 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -52,6 +52,8 @@ const int CBOT_IPF = 100; // CBOT: default number of instructions / frame CScript::CScript(COldObject* object) { + assert(object->Implements(ObjectInterfaceType::Programmable)); + m_object = object; assert(m_object->Implements(ObjectInterfaceType::TaskExecutor)); m_taskExecutor = dynamic_cast(m_object); @@ -347,7 +349,6 @@ bool CScript::Run() if ( !m_botProg->Start(m_mainFunction) ) return false; - m_object->SetRunScript(this); m_bRun = true; m_bContinue = false; m_ipf = CBOT_IPF; @@ -373,7 +374,7 @@ bool CScript::Continue() { if ( m_bContinue ) // instuction "move", "goto", etc. ? { - if ( m_botProg->Run(m_object, 0) ) + if ( m_botProg->Run(this, 0) ) { m_botProg->GetError(m_error, m_cursor1, m_cursor2); if ( m_cursor1 < 0 || m_cursor1 > m_len || @@ -406,7 +407,7 @@ bool CScript::Continue() return false; } - if ( m_botProg->Run(m_object, m_ipf) ) + if ( m_botProg->Run(this, m_ipf) ) { m_botProg->GetError(m_error, m_cursor1, m_cursor2); if ( m_cursor1 < 0 || m_cursor1 > m_len || @@ -446,7 +447,7 @@ bool CScript::Step() // TODO: m_app StepSimulation??? m_engine->StepSimulation(0.01f); // advance of 10ms // ??? m_engine->SetPause(true); - if ( m_botProg->Run(m_object, 0) ) // step mode + if ( m_botProg->Run(this, 0) ) // step mode { m_botProg->GetError(m_error, m_cursor1, m_cursor2); if ( m_cursor1 < 0 || m_cursor1 > m_len || @@ -1043,7 +1044,6 @@ bool CScript::ReadStack(FILE *file) if ( m_botProg == 0 ) return false; if ( !m_botProg->RestoreState(file) ) return false; - m_object->SetRunScript(this); m_bRun = true; m_bContinue = false; return true; diff --git a/src/script/script.h b/src/script/script.h index 55e50c61..51d3bd53 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -100,7 +100,7 @@ protected: bool Compile(); protected: - COldObject* m_object; + COldObject* m_object; CTaskExecutorObject* m_taskExecutor; Gfx::CEngine* m_engine; diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 6eedaa09..ed6309b9 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -517,7 +517,7 @@ bool CScriptFunctions::rGetResearchEnable(CBotVar* var, CBotVar* result, int& ex bool CScriptFunctions::rGetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; result->SetValInt(CRobotMain::GetInstancePointer()->GetDoneResearch(pThis->GetTeam())); return true; } @@ -544,7 +544,7 @@ bool CScriptFunctions::rSetResearchEnable(CBotVar* var, CBotVar* result, int& ex bool CScriptFunctions::rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; CRobotMain::GetInstancePointer()->SetDoneResearch(var->GetValInt(), pThis->GetTeam()); CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE)); return true; @@ -616,14 +616,11 @@ CBotTypResult CScriptFunctions::cBusy(CBotVar* thisclass, CBotVar* &var) bool CScriptFunctions::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; exception = 0; - CBotVar* idVar = thisclass->GetItem("id"); - assert(idVar != nullptr); - int rank = idVar->GetValInt(); - CObject* obj = CObjectManager::GetInstancePointer()->GetObjectById(rank); + CObject* obj = static_cast(thisclass->GetUserPtr()); CAuto* automat = obj->GetAuto(); if ( pThis->GetTeam() != obj->GetTeam() && obj->GetTeam() != 0 ) @@ -643,16 +640,13 @@ bool CScriptFunctions::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, bool CScriptFunctions::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); - CScript* script = pThis->GetRunScript(); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; exception = 0; Error err; - CBotVar* idVar = thisclass->GetItem("id"); - assert(idVar != nullptr); - int rank = idVar->GetValInt(); - CObject* obj = CObjectManager::GetInstancePointer()->GetObjectById(rank); + CObject* obj = static_cast(thisclass->GetUserPtr()); CAuto* automat = obj->GetAuto(); if ( pThis->GetTeam() != obj->GetTeam() && obj->GetTeam() != 0 ) @@ -702,8 +696,8 @@ CBotTypResult CScriptFunctions::cFactory(CBotVar* thisclass, CBotVar* &var) bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); - CScript* script = pThis->GetRunScript(); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; Error err; @@ -721,10 +715,7 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul else program = ""; - CBotVar* idVar = thisclass->GetItem("id"); - assert(idVar != nullptr); - int rank = idVar->GetValInt(); - CObject* factory = CObjectManager::GetInstancePointer()->GetObjectById(rank); + CObject* factory = static_cast(thisclass->GetUserPtr()); if (factory == nullptr) { exception = ERR_GENERIC; @@ -785,8 +776,8 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); - CScript* script = pThis->GetRunScript(); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; Error err; @@ -794,10 +785,7 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu ResearchType type = static_cast(var->GetValInt()); - CBotVar* idVar = thisclass->GetItem("id"); - assert(idVar != nullptr); - int rank = idVar->GetValInt(); - CObject* center = CObjectManager::GetInstancePointer()->GetObjectById(rank); + CObject* center = static_cast(thisclass->GetUserPtr()); CAuto* automat = center->GetAuto(); if ( pThis->GetTeam() != center->GetTeam() && center->GetTeam() != 0 ) @@ -863,17 +851,14 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu bool CScriptFunctions::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); - CScript* script = pThis->GetRunScript(); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; Error err; exception = 0; - CBotVar* idVar = thisclass->GetItem("id"); - assert(idVar != nullptr); - int rank = idVar->GetValInt(); - CObject* base = CObjectManager::GetInstancePointer()->GetObjectById(rank); + CObject* base = static_cast(thisclass->GetUserPtr()); CAuto* automat = base->GetAuto(); if ( pThis->GetTeam() != base->GetTeam() && base->GetTeam() != 0 ) @@ -933,7 +918,7 @@ CBotTypResult CScriptFunctions::cDelete(CBotVar* &var, void* user) bool CScriptFunctions::rDelete(CBotVar* var, CBotVar* result, int& exception, void* user) { int exploType = 0; - float force = std::numeric_limits::infinity(); + float force = 1.0f; int rank = var->GetValInt(); var->GetNext(); @@ -998,7 +983,7 @@ CBotTypResult CScriptFunctions::cSearch(CBotVar* &var, void* user) bool CScriptFunctions::rSearch(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; CObject *pBest; CBotVar* array; Math::Vector pos, oPos; @@ -1098,7 +1083,7 @@ CBotTypResult CScriptFunctions::cRadar(CBotVar* &var, void* user) bool CScriptFunctions::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; CObject *pBest; CBotVar* array; Math::Vector oPos; @@ -1255,8 +1240,8 @@ CBotTypResult CScriptFunctions::cDetect(CBotVar* &var, void* user) bool CScriptFunctions::rDetect(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; CObject *pBest; CBotVar* array; int type; @@ -1351,7 +1336,7 @@ CBotTypResult CScriptFunctions::cDirection(CBotVar* &var, void* user) bool CScriptFunctions::rDirection(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; Math::Vector iPos, oPos; float a, g; @@ -1371,7 +1356,7 @@ bool CScriptFunctions::rDirection(CBotVar* var, CBotVar* result, int& exception, bool CScriptFunctions::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; ObjectType category = static_cast(var->GetValInt()); exception = 0; @@ -1390,7 +1375,7 @@ bool CScriptFunctions::rCanResearch(CBotVar* var, CBotVar* result, int& exceptio bool CScriptFunctions::rResearched(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; ResearchType research = static_cast(var->GetValInt()); exception = 0; @@ -1412,8 +1397,8 @@ bool CScriptFunctions::rBuildingEnabled(CBotVar* var, CBotVar* result, int& exce bool CScriptFunctions::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); - CScript* script = pThis->GetRunScript(); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; ObjectType oType; ObjectType category; Error err; @@ -1516,8 +1501,8 @@ CBotTypResult CScriptFunctions::cProduce(CBotVar* &var, void* user) bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* me = (static_cast(user)); + CScript* script = static_cast(user); + CObject* me = script->m_object; const char* name = ""; Math::Vector pos; float angle = 0.0f; @@ -1703,8 +1688,8 @@ CBotTypResult CScriptFunctions::cSpace(CBotVar* &var, void* user) bool CScriptFunctions::rSpace(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; CBotVar* pSub; Math::Vector center; float rMin, rMax, dist; @@ -1786,8 +1771,8 @@ CBotTypResult CScriptFunctions::cFlatSpace(CBotVar* &var, void* user) bool CScriptFunctions::rFlatSpace(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; CBotVar* pSub; Math::Vector center; float flatMin, rMin, rMax, dist; @@ -1860,8 +1845,8 @@ CBotTypResult CScriptFunctions::cFlatGround(CBotVar* &var, void* user) bool CScriptFunctions::rFlatGround(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; Math::Vector center; float rMax, dist; @@ -1880,7 +1865,7 @@ bool CScriptFunctions::rFlatGround(CBotVar* var, CBotVar* result, int& exception bool CScriptFunctions::rWait(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); float value; Error err; @@ -1909,7 +1894,7 @@ bool CScriptFunctions::rWait(CBotVar* var, CBotVar* result, int& exception, void bool CScriptFunctions::rMove(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); float value; Error err; @@ -1938,7 +1923,7 @@ bool CScriptFunctions::rMove(CBotVar* var, CBotVar* result, int& exception, void bool CScriptFunctions::rTurn(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); float value; Error err; @@ -1993,7 +1978,7 @@ CBotTypResult CScriptFunctions::cGoto(CBotVar* &var, void* user) bool CScriptFunctions::rGoto(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); Math::Vector pos; TaskGotoGoal goal; TaskGotoCrash crash; @@ -2058,8 +2043,8 @@ CBotTypResult CScriptFunctions::cGrabDrop(CBotVar* &var, void* user) bool CScriptFunctions::rGrab(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; ObjectType oType; TaskManipArm type; Error err; @@ -2107,8 +2092,8 @@ bool CScriptFunctions::rGrab(CBotVar* var, CBotVar* result, int& exception, void bool CScriptFunctions::rDrop(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; ObjectType oType; TaskManipArm type; Error err; @@ -2150,7 +2135,7 @@ bool CScriptFunctions::rDrop(CBotVar* var, CBotVar* result, int& exception, void bool CScriptFunctions::rSniff(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); Error err; exception = 0; @@ -2193,8 +2178,8 @@ CBotTypResult CScriptFunctions::cReceive(CBotVar* &var, void* user) bool CScriptFunctions::rReceive(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; CBotString cbs; Error err; const char* p; @@ -2261,7 +2246,7 @@ CBotTypResult CScriptFunctions::cSend(CBotVar* &var, void* user) bool CScriptFunctions::rSend(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); CBotString cbs; Error err; const char* p; @@ -2329,7 +2314,7 @@ CBotTypResult CScriptFunctions::cDeleteInfo(CBotVar* &var, void* user) bool CScriptFunctions::rDeleteInfo(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; exception = 0; @@ -2377,7 +2362,7 @@ CBotTypResult CScriptFunctions::cTestInfo(CBotVar* &var, void* user) bool CScriptFunctions::rTestInfo(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; exception = 0; @@ -2408,7 +2393,7 @@ bool CScriptFunctions::rTestInfo(CBotVar* var, CBotVar* result, int& exception, bool CScriptFunctions::rThump(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); Error err; exception = 0; @@ -2435,7 +2420,7 @@ bool CScriptFunctions::rThump(CBotVar* var, CBotVar* result, int& exception, voi bool CScriptFunctions::rRecycle(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); Error err; exception = 0; @@ -2479,8 +2464,8 @@ CBotTypResult CScriptFunctions::cShield(CBotVar* &var, void* user) bool CScriptFunctions::rShield(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; float oper, radius; Error err; @@ -2542,7 +2527,7 @@ bool CScriptFunctions::rShield(CBotVar* var, CBotVar* result, int& exception, vo CBotTypResult CScriptFunctions::cFire(CBotVar* &var, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; ObjectType type; type = pThis->GetType(); @@ -2574,8 +2559,8 @@ CBotTypResult CScriptFunctions::cFire(CBotVar* &var, void* user) bool CScriptFunctions::rFire(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; float delay; Math::Vector impact; Error err; @@ -2637,7 +2622,7 @@ CBotTypResult CScriptFunctions::cAim(CBotVar* &var, void* user) bool CScriptFunctions::rAim(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); float x, y; Error err; @@ -2684,8 +2669,8 @@ CBotTypResult CScriptFunctions::cMotor(CBotVar* &var, void* user) bool CScriptFunctions::rMotor(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); - CPhysics* physics = (static_cast(user))->GetPhysics(); + CObject* pThis = static_cast(user)->m_object; + CPhysics* physics = (static_cast(user)->m_object)->GetPhysics(); float left, right, speed, turn; left = var->GetValFloat(); @@ -2716,7 +2701,7 @@ bool CScriptFunctions::rMotor(CBotVar* var, CBotVar* result, int& exception, voi bool CScriptFunctions::rJet(CBotVar* var, CBotVar* result, int& exception, void* user) { - CPhysics* physics = (static_cast(user))->GetPhysics(); + CPhysics* physics = (static_cast(user)->m_object)->GetPhysics(); float value; value = var->GetValFloat(); @@ -2745,7 +2730,7 @@ CBotTypResult CScriptFunctions::cTopo(CBotVar* &var, void* user) bool CScriptFunctions::rTopo(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); Math::Vector pos; float level; @@ -2780,7 +2765,7 @@ CBotTypResult CScriptFunctions::cMessage(CBotVar* &var, void* user) bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); CBotString cbs; const char* p; Ui::TextType type; @@ -2804,7 +2789,7 @@ bool CScriptFunctions::rMessage(CBotVar* var, CBotVar* result, int& exception, v bool CScriptFunctions::rCmdline(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; float value; int rank; @@ -2821,7 +2806,7 @@ bool CScriptFunctions::rCmdline(CBotVar* var, CBotVar* result, int& exception, v bool CScriptFunctions::rIsMovie(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); float value; value = script->m_main->GetMovieLock()?1.0f:0.0f; @@ -2834,7 +2819,7 @@ bool CScriptFunctions::rIsMovie(CBotVar* var, CBotVar* result, int& exception, v bool CScriptFunctions::rErrMode(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); int value; value = var->GetValInt(); @@ -2849,7 +2834,7 @@ bool CScriptFunctions::rErrMode(CBotVar* var, CBotVar* result, int& exception, v bool CScriptFunctions::rIPF(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); int value; value = var->GetValInt(); @@ -2864,7 +2849,7 @@ bool CScriptFunctions::rIPF(CBotVar* var, CBotVar* result, int& exception, void* bool CScriptFunctions::rAbsTime(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); float value; value = script->m_main->GetGameTime(); @@ -2892,8 +2877,8 @@ CBotTypResult CScriptFunctions::cPenDown(CBotVar* &var, void* user) bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; int color; float width; Error err; @@ -2950,8 +2935,8 @@ bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, v bool CScriptFunctions::rPenUp(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; Error err; CMotionVehicle* motionVehicle = dynamic_cast(pThis->GetMotion()); @@ -2992,8 +2977,8 @@ bool CScriptFunctions::rPenUp(CBotVar* var, CBotVar* result, int& exception, voi bool CScriptFunctions::rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); - CObject* pThis = static_cast(user); + CScript* script = static_cast(user); + CObject* pThis = script->m_object; int color; Error err; @@ -3036,7 +3021,7 @@ bool CScriptFunctions::rPenColor(CBotVar* var, CBotVar* result, int& exception, bool CScriptFunctions::rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user) { - CObject* pThis = static_cast(user); + CObject* pThis = static_cast(user)->m_object; float width; CMotionVehicle* motionVehicle = dynamic_cast(pThis->GetMotion()); @@ -3064,12 +3049,9 @@ CBotTypResult CScriptFunctions::cOneObject(CBotVar* &var, void* user) bool CScriptFunctions::rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast(user))->GetRunScript(); + CScript* script = static_cast(user); - CBotVar* idVar = var->GetItem("id"); - assert(idVar != nullptr); - int rank = idVar->GetValInt(); - CObject* object = CObjectManager::GetInstancePointer()->GetObjectById(rank); + CObject* object = static_cast(var->GetUserPtr()); script->m_main->SelectObject(object, false); @@ -3801,8 +3783,9 @@ void CScriptFunctions::uObject(CBotVar* botThis, void* user) if ( user == nullptr ) return; - assert(static_cast(user)->Implements(ObjectInterfaceType::Old)); - COldObject* object = static_cast(user); + CObject* obj = static_cast(user); + assert(obj->Implements(ObjectInterfaceType::Old)); + COldObject* object = static_cast(obj); physics = object->GetPhysics();