[colobot] 345/390: Added CBot functions for rounding: floor(), ceil(), round(), and trunc()
Didier Raboud
odyx at moszumanska.debian.org
Fri Jun 12 14:22:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch upstream/latest
in repository colobot.
commit c28e1f6150c36d478d8415852a7e23a86128d743
Author: Tomasz Kapuściński <tomaszkax86 at gmail.com>
Date: Wed May 6 23:29:55 2015 +0200
Added CBot functions for rounding: floor(), ceil(), round(), and trunc()
---
src/script/cbottoken.cpp | 12 ++++++++++++
src/script/scriptfunc.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++
src/script/scriptfunc.h | 4 ++++
3 files changed, 64 insertions(+)
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp
index 81c7187..004c2b4 100644
--- a/src/script/cbottoken.cpp
+++ b/src/script/cbottoken.cpp
@@ -253,6 +253,10 @@ std::string GetHelpFilename(const char *token)
if ( strcmp(token, "pow" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
if ( strcmp(token, "rand" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
if ( strcmp(token, "abs" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
+ if ( strcmp(token, "floor" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
+ if ( strcmp(token, "ceil" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
+ if ( strcmp(token, "round" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
+ if ( strcmp(token, "trunc" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
if ( strcmp(token, "getbuild" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getbuild.txt");
if ( strcmp(token, "getresearchenable" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getresen.txt");
if ( strcmp(token, "getresearchdone" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getresdo.txt");
@@ -383,6 +387,10 @@ bool IsFunction(const char *token)
if ( strcmp(token, "pow" ) == 0 ) return true;
if ( strcmp(token, "rand" ) == 0 ) return true;
if ( strcmp(token, "abs" ) == 0 ) return true;
+ if ( strcmp(token, "floor" ) == 0 ) return true;
+ if ( strcmp(token, "ceil" ) == 0 ) return true;
+ if ( strcmp(token, "round" ) == 0 ) return true;
+ if ( strcmp(token, "trunc" ) == 0 ) return true;
if ( strcmp(token, "getbuild" ) == 0 ) return true;
if ( strcmp(token, "getresearchenable" ) == 0 ) return true;
if ( strcmp(token, "getresearchdone" ) == 0 ) return true;
@@ -479,6 +487,10 @@ const char* GetHelpText(const char *token)
if ( strcmp(token, "pow" ) == 0 ) return "pow ( x, y );";
if ( strcmp(token, "rand" ) == 0 ) return "rand ( );";
if ( strcmp(token, "abs" ) == 0 ) return "abs ( value );";
+ if ( strcmp(token, "floor" ) == 0 ) return "floor ( value );";
+ if ( strcmp(token, "ceil" ) == 0 ) return "ceil ( value );";
+ if ( strcmp(token, "round" ) == 0 ) return "round ( value );";
+ if ( strcmp(token, "trunc" ) == 0 ) return "trunc ( value );";
if ( strcmp(token, "getbuild" ) == 0 ) return "getbuild ( );";
if ( strcmp(token, "getresearchenable" ) == 0 ) return "getresearchenable ( );";
if ( strcmp(token, "getresearchdone" ) == 0 ) return "getresearchdone ( );";
diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp
index cd05061..8ffa6a0 100644
--- a/src/script/scriptfunc.cpp
+++ b/src/script/scriptfunc.cpp
@@ -346,6 +346,50 @@ bool CScriptFunctions::rAbs(CBotVar* var, CBotVar* result, int& exception, void*
return true;
}
+// Instruction "floor()"
+
+bool CScriptFunctions::rFloor(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ float value;
+
+ value = var->GetValFloat();
+ result->SetValFloat(floor(value));
+ return true;
+}
+
+// Instruction "ceil()"
+
+bool CScriptFunctions::rCeil(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ float value;
+
+ value = var->GetValFloat();
+ result->SetValFloat(ceil(value));
+ return true;
+}
+
+// Instruction "round()"
+
+bool CScriptFunctions::rRound(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ float value;
+
+ value = var->GetValFloat();
+ result->SetValFloat(round(value));
+ return true;
+}
+
+// Instruction "trunc()"
+
+bool CScriptFunctions::rTrunc(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ float value;
+
+ value = var->GetValFloat();
+ result->SetValFloat(trunc(value));
+ return true;
+}
+
// Compilation of the instruction "endmission(result, delay)"
CBotTypResult CScriptFunctions::cEndMission(CBotVar* &var, void* user)
@@ -3899,6 +3943,10 @@ void CScriptFunctions::Init()
CBotProgram::AddFunction("pow", rPow, CScriptFunctions::cTwoFloat);
CBotProgram::AddFunction("rand", rRand, CScriptFunctions::cNull);
CBotProgram::AddFunction("abs", rAbs, CScriptFunctions::cOneFloat);
+ CBotProgram::AddFunction("floor", rFloor, CScriptFunctions::cOneFloat);
+ CBotProgram::AddFunction("ceil", rCeil, CScriptFunctions::cOneFloat);
+ CBotProgram::AddFunction("round", rRound, CScriptFunctions::cOneFloat);
+ CBotProgram::AddFunction("trunc", rTrunc, CScriptFunctions::cOneFloat);
CBotProgram::AddFunction("endmission",rEndMission,CScriptFunctions::cEndMission);
CBotProgram::AddFunction("playmusic", rPlayMusic ,CScriptFunctions::cPlayMusic);
diff --git a/src/script/scriptfunc.h b/src/script/scriptfunc.h
index 08c2be2..ef9e8d5 100644
--- a/src/script/scriptfunc.h
+++ b/src/script/scriptfunc.h
@@ -84,6 +84,10 @@ private:
static bool rPow(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rRand(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rAbs(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rFloor(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rCeil(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rRound(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rTrunc(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rEndMission(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rStopMusic(CBotVar* var, CBotVar* result, int& exception, void* user);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list