From 4506a4b8bdff2986d2104d3cbe711aed504ce30d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 14 Jul 2015 13:42:47 +0200 Subject: [PATCH] TraceColor enum --- src/CMakeLists.txt | 1 + src/object/brain.cpp | 47 ++++++------ src/object/brain.h | 6 +- src/object/motion/motionvehicle.cpp | 7 +- src/object/motion/motionvehicle.h | 10 +-- src/object/task/taskmanager.cpp | 3 +- src/object/task/taskmanager.h | 4 +- src/object/task/taskpen.cpp | 32 ++++---- src/object/task/taskpen.h | 8 +- src/object/trace_color.cpp | 44 +++++++++++ src/object/trace_color.h | 47 ++++++++++++ src/physics/physics.cpp | 11 ++- src/physics/physics.h | 4 +- src/script/scriptfunc.cpp | 113 +++++++++++----------------- 14 files changed, 196 insertions(+), 141 deletions(-) create mode 100644 src/object/trace_color.cpp create mode 100644 src/object/trace_color.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8eed248f..717591b6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -192,6 +192,7 @@ set(BASE_SOURCES object/task/taskturn.cpp object/task/taskwait.cpp object/tool_type.cpp + object/trace_color.cpp object/subclass/exchange_post.cpp object/subclass/static_object.cpp physics/physics.cpp diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 507966b2..16da92f2 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -798,35 +798,35 @@ bool CBrain::EventProcess(const Event &event) } if ( action == EVENT_OBJECT_PEN1 ) // black { - err = StartTaskPen(true, 1); + err = StartTaskPen(true, TraceColor::Black); } if ( action == EVENT_OBJECT_PEN2 ) // yellow { - err = StartTaskPen(true, 8); + err = StartTaskPen(true, TraceColor::Yellow); } if ( action == EVENT_OBJECT_PEN3 ) // orange { - err = StartTaskPen(true, 7); + err = StartTaskPen(true, TraceColor::Orange); } if ( action == EVENT_OBJECT_PEN4 ) // red { - err = StartTaskPen(true, 4); + err = StartTaskPen(true, TraceColor::Red); } if ( action == EVENT_OBJECT_PEN5 ) // violet { - err = StartTaskPen(true, 6); + err = StartTaskPen(true, TraceColor::Purple); } if ( action == EVENT_OBJECT_PEN6 ) // blue { - err = StartTaskPen(true, 14); + err = StartTaskPen(true, TraceColor::Blue); } if ( action == EVENT_OBJECT_PEN7 ) // green { - err = StartTaskPen(true, 12); + err = StartTaskPen(true, TraceColor::Green); } if ( action == EVENT_OBJECT_PEN8 ) // brown { - err = StartTaskPen(true, 10); + err = StartTaskPen(true, TraceColor::Brown); } if ( action == EVENT_OBJECT_REC ) // registered? @@ -1156,12 +1156,12 @@ Error CBrain::StartTaskTerraform() // Change pencil. -Error CBrain::StartTaskPen(bool down, int color) +Error CBrain::StartTaskPen(bool down, TraceColor color) { auto motionVehicle = dynamic_cast(m_motion); assert(motionVehicle != nullptr); - if (color == -1) + if (color == TraceColor::Default) color = motionVehicle->GetTraceColor(); motionVehicle->SetTraceDown(down); @@ -2267,7 +2267,6 @@ void CBrain::UpdateInterface() Ui::CButton* pb; Ui::CSlider* ps; Ui::CColor* pc; - int color; bool bEnable, bFly, bRun; char title[100]; @@ -2485,46 +2484,46 @@ void CBrain::UpdateInterface() pb->ClearState(Ui::STATE_CHECK); } - color = motionVehicle->GetTraceColor(); + TraceColor color = motionVehicle->GetTraceColor(); pc = static_cast< Ui::CColor* >(pw->SearchControl(EVENT_OBJECT_PEN1)); if ( pc != 0 ) { - pc->SetState(Ui::STATE_CHECK, color==1); + pc->SetState(Ui::STATE_CHECK, color == TraceColor::Black); } pc = static_cast< Ui::CColor* >(pw->SearchControl(EVENT_OBJECT_PEN2)); if ( pc != 0 ) { - pc->SetState(Ui::STATE_CHECK, color==8); + pc->SetState(Ui::STATE_CHECK, color == TraceColor::Yellow); } pc = static_cast< Ui::CColor* >(pw->SearchControl(EVENT_OBJECT_PEN3)); if ( pc != 0 ) { - pc->SetState(Ui::STATE_CHECK, color==7); + pc->SetState(Ui::STATE_CHECK, color == TraceColor::Orange); } pc = static_cast< Ui::CColor* >(pw->SearchControl(EVENT_OBJECT_PEN4)); if ( pc != 0 ) { - pc->SetState(Ui::STATE_CHECK, color==4); + pc->SetState(Ui::STATE_CHECK, color == TraceColor::Red); } pc = static_cast< Ui::CColor* >(pw->SearchControl(EVENT_OBJECT_PEN5)); if ( pc != 0 ) { - pc->SetState(Ui::STATE_CHECK, color==6); + pc->SetState(Ui::STATE_CHECK, color == TraceColor::Purple); } pc = static_cast< Ui::CColor* >(pw->SearchControl(EVENT_OBJECT_PEN6)); if ( pc != 0 ) { - pc->SetState(Ui::STATE_CHECK, color==14); + pc->SetState(Ui::STATE_CHECK, color == TraceColor::Blue); } pc = static_cast< Ui::CColor* >(pw->SearchControl(EVENT_OBJECT_PEN7)); if ( pc != 0 ) { - pc->SetState(Ui::STATE_CHECK, color==12); + pc->SetState(Ui::STATE_CHECK, color == TraceColor::Green); } pc = static_cast< Ui::CColor* >(pw->SearchControl(EVENT_OBJECT_PEN8)); if ( pc != 0 ) { - pc->SetState(Ui::STATE_CHECK, color==10); + pc->SetState(Ui::STATE_CHECK, color == TraceColor::Brown); } } else @@ -2930,7 +2929,7 @@ void CBrain::TraceRecordStart() } else // pen up? { - m_traceColor = -1; + m_traceColor = TraceColor::Default; } delete[] m_traceRecordBuffer; @@ -2945,7 +2944,6 @@ void CBrain::TraceRecordFrame() TraceOper oper = TO_STOP; Math::Vector pos; float angle, len, speed; - int color; CMotionVehicle* motionVehicle = dynamic_cast(m_motion); assert(motionVehicle != nullptr); @@ -2957,14 +2955,11 @@ void CBrain::TraceRecordFrame() speed = m_physics->GetCirMotionY(MO_REASPEED); if ( speed != 0.0f ) oper = TO_TURN; + TraceColor color = TraceColor::Default; if ( motionVehicle->GetTraceDown() ) // pencil down? { color = motionVehicle->GetTraceColor(); } - else // pen up? - { - color = -1; - } if ( oper != m_traceOper || color != m_traceColor ) diff --git a/src/object/brain.h b/src/object/brain.h index 5f75b12c..d50837ef 100644 --- a/src/object/brain.h +++ b/src/object/brain.h @@ -31,6 +31,7 @@ #include "object/task/taskmanip.h" #include "object/task/taskflag.h" #include "object/task/taskshield.h" +#include "object/trace_color.h" #include @@ -155,7 +156,7 @@ public: int GetProgramIndex(Program* program); protected: - Error StartTaskPen(bool down, int color = -1); + Error StartTaskPen(bool down, TraceColor color = TraceColor::Default); bool EventFrame(const Event &event); @@ -236,8 +237,7 @@ protected: TraceOper m_traceOper; Math::Vector m_tracePos; float m_traceAngle; - int m_traceColor; + TraceColor m_traceColor; int m_traceRecordIndex; TraceRecord* m_traceRecordBuffer; }; - diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp index bc05b8c8..1bc0c45a 100644 --- a/src/object/motion/motionvehicle.cpp +++ b/src/object/motion/motionvehicle.cpp @@ -68,7 +68,7 @@ CMotionVehicle::CMotionVehicle(COldObject* object) : CMotion(object) m_bFlyFix = false; m_bTraceDown = false; - m_traceColor = 1; // black + m_traceColor = TraceColor::Black; // black m_traceWidth = 0.5f; } @@ -1909,12 +1909,12 @@ void CMotionVehicle::SetTraceDown(bool bDown) m_bTraceDown = bDown; } -int CMotionVehicle::GetTraceColor() +TraceColor CMotionVehicle::GetTraceColor() { return m_traceColor; } -void CMotionVehicle::SetTraceColor(int color) +void CMotionVehicle::SetTraceColor(TraceColor color) { m_traceColor = color; } @@ -1928,4 +1928,3 @@ void CMotionVehicle::SetTraceWidth(float width) { m_traceWidth = width; } - diff --git a/src/object/motion/motionvehicle.h b/src/object/motion/motionvehicle.h index ab04310f..6414bccd 100644 --- a/src/object/motion/motionvehicle.h +++ b/src/object/motion/motionvehicle.h @@ -17,12 +17,11 @@ * along with this program. If not, see http://gnu.org/licenses */ -// motionvehicle.h - #pragma once #include "object/motion/motion.h" +#include "object/trace_color.h" @@ -38,8 +37,8 @@ public: bool GetTraceDown(); void SetTraceDown(bool bDown); - int GetTraceColor(); - void SetTraceColor(int color); + TraceColor GetTraceColor(); + void SetTraceColor(TraceColor color); float GetTraceWidth(); void SetTraceWidth(float width); @@ -66,7 +65,6 @@ protected: Math::Vector m_posKey; bool m_bFlyFix; bool m_bTraceDown; - int m_traceColor; + TraceColor m_traceColor; float m_traceWidth; }; - diff --git a/src/object/task/taskmanager.cpp b/src/object/task/taskmanager.cpp index 97a266de..026b843a 100644 --- a/src/object/task/taskmanager.cpp +++ b/src/object/task/taskmanager.cpp @@ -156,7 +156,7 @@ Error CTaskManager::StartTaskTerraform() // Changes the pencil. -Error CTaskManager::StartTaskPen(bool bDown, int color) +Error CTaskManager::StartTaskPen(bool bDown, TraceColor color) { m_task = new CTaskPen(m_object); return (static_cast(m_task))->Start(bDown, color); @@ -263,4 +263,3 @@ bool CTaskManager::Abort() if ( m_task == 0 ) return false; return m_task->Abort(); } - diff --git a/src/object/task/taskmanager.h b/src/object/task/taskmanager.h index 8e3c55f3..4c6836fd 100644 --- a/src/object/task/taskmanager.h +++ b/src/object/task/taskmanager.h @@ -27,6 +27,7 @@ #include "object/task/taskgoto.h" #include "object/task/taskshield.h" #include "object/task/taskflag.h" +#include "object/trace_color.h" @@ -48,7 +49,7 @@ public: Error StartTaskDeleteMark(); Error StartTaskInfo(const char *name, float value, float power, bool bSend); Error StartTaskTerraform(); - Error StartTaskPen(bool bDown, int color); + Error StartTaskPen(bool bDown, TraceColor color); Error StartTaskRecover(); Error StartTaskShield(TaskShieldMode mode, float delay); Error StartTaskFire(float delay); @@ -67,4 +68,3 @@ protected: COldObject* m_object; bool m_bPilot; }; - diff --git a/src/object/task/taskpen.cpp b/src/object/task/taskpen.cpp index efe0eb9c..d9eec931 100644 --- a/src/object/task/taskpen.cpp +++ b/src/object/task/taskpen.cpp @@ -129,7 +129,7 @@ bool CTaskPen::EventProcess(const Event &event) // Assigns the goal has achieved. -Error CTaskPen::Start(bool bDown, int color) +Error CTaskPen::Start(bool bDown, TraceColor color) { Math::Vector pos; Math::Matrix* mat; @@ -262,26 +262,28 @@ int CTaskPen::AngleToRank(float angle) // Converting a color to the angle of carousel of pencils. -float CTaskPen::ColorToAngle(int color) +float CTaskPen::ColorToAngle(TraceColor color) { return -45.0f*Math::PI/180.0f*ColorToRank(color); } // Converting a color number to the pencil (0 .. 7). -int CTaskPen::ColorToRank(int color) +int CTaskPen::ColorToRank(TraceColor color) { - if ( color == 8 ) return 1; // yellow - if ( color == 7 ) return 2; // orange - if ( color == 5 ) return 2; // pink - if ( color == 4 ) return 3; // red - if ( color == 6 ) return 4; // purple - if ( color == 14 ) return 5; // blue - if ( color == 15 ) return 5; // light blue - if ( color == 12 ) return 6; // green - if ( color == 13 ) return 6; // light green - if ( color == 10 ) return 7; // brown - if ( color == 9 ) return 7; // beige + if ( color == TraceColor::Yellow ) return 1; // yellow + if ( color == TraceColor::Orange ) return 2; // orange + if ( color == TraceColor::Pink ) return 2; // pink + if ( color == TraceColor::Red ) return 3; // red + if ( color == TraceColor::Purple ) return 4; // purple + if ( color == TraceColor::Blue ) return 5; // blue + if ( color == TraceColor::LightBlue ) return 5; // light blue + if ( color == TraceColor::Green ) return 6; // green + if ( color == TraceColor::LightGreen ) return 6; // light green + if ( color == TraceColor::Brown ) return 7; // brown + if ( color == TraceColor::Beige ) return 7; // beige + + if ( color == TraceColor::RedArrow ) return 3; // red + return 0; // black } - diff --git a/src/object/task/taskpen.h b/src/object/task/taskpen.h index de9a66f3..d4aef7d3 100644 --- a/src/object/task/taskpen.h +++ b/src/object/task/taskpen.h @@ -23,6 +23,7 @@ #include "object/task/task.h" +#include "object/trace_color.h" #include "math/vector.h" @@ -44,15 +45,15 @@ public: bool EventProcess(const Event &event); - Error Start(bool bDown, int color); + Error Start(bool bDown, TraceColor color); Error IsEnded(); bool Abort(); protected: void SoundManip(float time, float amplitude, float frequency); int AngleToRank(float angle); - float ColorToAngle(int color); - int ColorToRank(int color); + float ColorToAngle(TraceColor color); + int ColorToRank(TraceColor color); protected: bool m_bError; @@ -68,4 +69,3 @@ protected: float m_newAngle; float m_timeDown; }; - diff --git a/src/object/trace_color.cpp b/src/object/trace_color.cpp new file mode 100644 index 00000000..a2e74c80 --- /dev/null +++ b/src/object/trace_color.cpp @@ -0,0 +1,44 @@ +/* + * 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/trace_color.h" + +std::string TraceColorName(TraceColor color) +{ + switch(color) { + case TraceColor::White: return "White"; break; + case TraceColor::Black: return "Black"; break; + case TraceColor::Gray: return "Gray"; break; + case TraceColor::LightGray: return "LightGray"; break; + case TraceColor::Red: return "Red"; break; + case TraceColor::Pink: return "Pink"; break; + case TraceColor::Purple: return "Purple"; break; + case TraceColor::Orange: return "Orange"; break; + case TraceColor::Yellow: return "Yellow"; break; + case TraceColor::Beige: return "Beige"; break; + case TraceColor::Brown: return "Brown"; break; + case TraceColor::Skin: return "Skin"; break; + case TraceColor::Green: return "Green"; break; + case TraceColor::LightGreen: return "LightGreen"; break; + case TraceColor::Blue: return "Blue"; break; + case TraceColor::LightBlue: return "LightBlue"; break; + case TraceColor::RedArrow: return "RedArrow"; break; + case TraceColor::BlackArrow: return "BlackArrow"; break; + default: return ""; break; + } +} diff --git a/src/object/trace_color.h b/src/object/trace_color.h new file mode 100644 index 00000000..a39696bc --- /dev/null +++ b/src/object/trace_color.h @@ -0,0 +1,47 @@ +/* + * 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 + */ +#pragma once + +#include + +enum class TraceColor : int { + Default = -1, + + White = 0, + Black = 1, + Gray = 2, + LightGray = 3, + Red = 4, + Pink = 5, + Purple = 6, + Orange = 7, + Yellow = 8, + Beige = 9, + Brown = 10, + Skin = 11, + Green = 12, + LightGreen = 13, + Blue = 14, + LightBlue = 15, + RedArrow = 16, + BlackArrow = 17, + Max, +}; + +std::string TraceColorName(TraceColor c); diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index f807cf01..69b84d9f 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -2423,7 +2423,7 @@ void CPhysics::FloorAdapt(float aTime, float rTime, } else { - WheelParticle(-1, 0.0f); + WheelParticle(TraceColor::Default, 0.0f); } } @@ -3748,7 +3748,7 @@ void CPhysics::WaterParticle(float aTime, Math::Vector pos, ObjectType type, // Creates the trace under the robot. -void CPhysics::WheelParticle(int color, float width) +void CPhysics::WheelParticle(TraceColor color, float width) { Math::Matrix* mat; Math::Vector goal1, goal2, wheel1, wheel2; @@ -3758,11 +3758,11 @@ void CPhysics::WheelParticle(int color, float width) mat = m_object->GetWorldMatrix(0); // Draw a trace on the ground. - if ( color >= 0 && color <= 17 ) + if ( color != TraceColor::Default ) { - parti = static_cast(Gfx::PARTITRACE0+color); + parti = static_cast(Gfx::PARTITRACE0+static_cast(color)); step = 2.0f; - if ( color >= 16 ) step = 4.0f; // arrow? + if ( static_cast(color) >= static_cast(TraceColor::RedArrow) ) step = 4.0f; // arrow? step /= m_engine->GetTracePrecision(); goal1.x = step/2.0f; @@ -3892,4 +3892,3 @@ float CPhysics::GetFallDamageFraction() { return m_fallDamageFraction; } - diff --git a/src/physics/physics.h b/src/physics/physics.h index 7a2276c7..6836e1e7 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -30,6 +30,7 @@ #include "math/vector.h" #include "object/object_type.h" +#include "object/trace_color.h" class CObject; @@ -205,7 +206,7 @@ protected: void CrashParticle(float crash); void MotorParticle(float aTime, float rTime); void WaterParticle(float aTime, Math::Vector pos, ObjectType type, float floor, float advance, float turn); - void WheelParticle(int color, float width); + void WheelParticle(TraceColor color, float width); void SetFalling(); protected: @@ -268,4 +269,3 @@ protected: float m_fallDamageFraction; float m_minFallingHeight; }; - diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index 8c4ce43b..764238dd 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -36,6 +36,7 @@ #include "object/brain.h" #include "object/object.h" #include "object/object_manager.h" +#include "object/trace_color.h" #include "object/robotmain.h" #include "object/task/taskmanager.h" #include "object/subclass/exchange_post.h" @@ -1642,6 +1643,11 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v result->SetValInt(1); // error return true; } + if(type == OBJECT_MOBILEdr) + { + assert(object->Implements(ObjectInterfaceType::Old)); // TODO: temporary hack + dynamic_cast(object)->SetManual(true); + } script->m_main->CreateShortcuts(); } @@ -2934,30 +2940,30 @@ bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, v CMotionVehicle* motionVehicle = dynamic_cast(pThis->GetMotion()); assert(motionVehicle != nullptr); + exception = 0; + + if ( var != 0 ) + { + color = var->GetValInt(); + if ( color < 0 ) color = 0; + if ( color > static_cast(TraceColor::Max) ) color = static_cast(TraceColor::Max); + motionVehicle->SetTraceColor(static_cast(color)); + + var = var->GetNext(); + if ( var != 0 ) + { + width = var->GetValFloat(); + if ( width < 0.1f ) width = 0.1f; + if ( width > 1.0f ) width = 1.0f; + motionVehicle->SetTraceWidth(width); + } + } + motionVehicle->SetTraceDown(true); + if ( pThis->GetType() == OBJECT_MOBILEdr ) { - exception = 0; - if ( script->m_primaryTask == 0 ) // no task in progress? { - if ( var != 0 ) - { - color = var->GetValInt(); - if ( color < 0 ) color = 0; - if ( color > 17 ) color = 17; - motionVehicle->SetTraceColor(color); - - var = var->GetNext(); - if ( var != 0 ) - { - width = var->GetValFloat(); - if ( width < 0.1f ) width = 0.1f; - if ( width > 1.0f ) width = 1.0f; - motionVehicle->SetTraceWidth(width); - } - } - motionVehicle->SetTraceDown(true); - script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskPen(motionVehicle->GetTraceDown(), motionVehicle->GetTraceColor()); if ( err != ERR_OK ) @@ -2977,24 +2983,6 @@ bool CScriptFunctions::rPenDown(CBotVar* var, CBotVar* result, int& exception, v } else { - if ( var != 0 ) - { - color = var->GetValInt(); - if ( color < 0 ) color = 0; - if ( color > 17 ) color = 17; - motionVehicle->SetTraceColor(color); - - var = var->GetNext(); - if ( var != 0 ) - { - width = var->GetValFloat(); - if ( width < 0.1f ) width = 0.1f; - if ( width > 1.0f ) width = 1.0f; - motionVehicle->SetTraceWidth(width); - } - } - motionVehicle->SetTraceDown(true); - return true; } } @@ -3010,10 +2998,12 @@ bool CScriptFunctions::rPenUp(CBotVar* var, CBotVar* result, int& exception, voi CMotionVehicle* motionVehicle = dynamic_cast(pThis->GetMotion()); assert(motionVehicle != nullptr); + exception = 0; + + motionVehicle->SetTraceDown(false); + if ( pThis->GetType() == OBJECT_MOBILEdr ) { - exception = 0; - if ( script->m_primaryTask == 0 ) // no task in progress? { motionVehicle->SetTraceDown(false); @@ -3037,7 +3027,6 @@ bool CScriptFunctions::rPenUp(CBotVar* var, CBotVar* result, int& exception, voi } else { - motionVehicle->SetTraceDown(false); return true; } } @@ -3054,17 +3043,17 @@ bool CScriptFunctions::rPenColor(CBotVar* var, CBotVar* result, int& exception, CMotionVehicle* motionVehicle = dynamic_cast(pThis->GetMotion()); assert(motionVehicle != nullptr); + exception = 0; + + color = var->GetValInt(); + if ( color < 0 ) color = 0; + if ( color > static_cast(TraceColor::Max) ) color = static_cast(TraceColor::Max); + motionVehicle->SetTraceColor(static_cast(color)); + if ( pThis->GetType() == OBJECT_MOBILEdr ) { - exception = 0; - if ( script->m_primaryTask == 0 ) // no task in progress? { - color = var->GetValInt(); - if ( color < 0 ) color = 0; - if ( color > 17 ) color = 17; - motionVehicle->SetTraceColor(color); - script->m_primaryTask = new CTaskManager(script->m_object); err = script->m_primaryTask->StartTaskPen(motionVehicle->GetTraceDown(), motionVehicle->GetTraceColor()); if ( err != ERR_OK ) @@ -3084,11 +3073,6 @@ bool CScriptFunctions::rPenColor(CBotVar* var, CBotVar* result, int& exception, } else { - color = var->GetValInt(); - if ( color < 0 ) color = 0; - if ( color > 17 ) color = 17; - motionVehicle->SetTraceColor(color); - return true; } } @@ -3676,24 +3660,11 @@ void CScriptFunctions::Init() } CBotProgram::DefineNum("Any", OBJECT_NULL); - CBotProgram::DefineNum("White", 0); - CBotProgram::DefineNum("Black", 1); - CBotProgram::DefineNum("Gray", 2); - CBotProgram::DefineNum("LightGray", 3); - CBotProgram::DefineNum("Red", 4); - CBotProgram::DefineNum("Pink", 5); - CBotProgram::DefineNum("Purple", 6); - CBotProgram::DefineNum("Orange", 7); - CBotProgram::DefineNum("Yellow", 8); - CBotProgram::DefineNum("Beige", 9); - CBotProgram::DefineNum("Brown", 10); - CBotProgram::DefineNum("Skin", 11); - CBotProgram::DefineNum("Green", 12); - CBotProgram::DefineNum("LightGreen", 13); - CBotProgram::DefineNum("Blue", 14); - CBotProgram::DefineNum("LightBlue", 15); - CBotProgram::DefineNum("BlackArrow", 16); - CBotProgram::DefineNum("RedArrow", 17); + for (int i = 0; i < static_cast(TraceColor::Max); i++) + { + TraceColor color = static_cast(i); + CBotProgram::DefineNum(TraceColorName(color).c_str(), static_cast(color)); + } CBotProgram::DefineNum("InFront", TMA_FFRONT); CBotProgram::DefineNum("Behind", TMA_FBACK);