[colobot] 341/390: Added atan2() function to CBot

Didier Raboud odyx at moszumanska.debian.org
Fri Jun 12 14:22:02 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 05bf5be6f4ce8db9cc77602e0d33ce6ea78964b8
Author: Tomasz Kapuściński <tomaszkax86 at gmail.com>
Date:   Wed May 6 13:02:44 2015 +0200

    Added atan2() function to CBot
---
 src/script/cbottoken.cpp  |  3 +++
 src/script/scriptfunc.cpp | 13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp
index b49869f..81c7187 100644
--- a/src/script/cbottoken.cpp
+++ b/src/script/cbottoken.cpp
@@ -248,6 +248,7 @@ std::string GetHelpFilename(const char *token)
     if ( strcmp(token, "asin"          ) == 0 )  return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
     if ( strcmp(token, "acos"          ) == 0 )  return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
     if ( strcmp(token, "atan"          ) == 0 )  return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
+    if ( strcmp(token, "atan2"         ) == 0 )  return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
     if ( strcmp(token, "sqrt"          ) == 0 )  return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
     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");
@@ -377,6 +378,7 @@ bool IsFunction(const char *token)
     if ( strcmp(token, "asin"         ) == 0 )  return true;
     if ( strcmp(token, "acos"         ) == 0 )  return true;
     if ( strcmp(token, "atan"         ) == 0 )  return true;
+    if ( strcmp(token, "atan2"        ) == 0 )  return true;
     if ( strcmp(token, "sqrt"         ) == 0 )  return true;
     if ( strcmp(token, "pow"          ) == 0 )  return true;
     if ( strcmp(token, "rand"         ) == 0 )  return true;
@@ -472,6 +474,7 @@ const char* GetHelpText(const char *token)
     if ( strcmp(token, "asin"      ) == 0 )  return "asin ( value );";
     if ( strcmp(token, "acos"      ) == 0 )  return "acos ( value );";
     if ( strcmp(token, "atan"      ) == 0 )  return "atan ( value );";
+    if ( strcmp(token, "atan2"     ) == 0 )  return "atan2 ( y, x );";
     if ( strcmp(token, "sqrt"      ) == 0 )  return "sqrt ( value );";
     if ( strcmp(token, "pow"       ) == 0 )  return "pow ( x, y );";
     if ( strcmp(token, "rand"      ) == 0 )  return "rand ( );";
diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp
index 77c622c..281a216 100644
--- a/src/script/scriptfunc.cpp
+++ b/src/script/scriptfunc.cpp
@@ -292,6 +292,18 @@ bool raTan(CBotVar* var, CBotVar* result, int& exception, void* user)
     return true;
 }
 
+// Instruction "atan2(y,x)".
+
+bool raTan2(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+    float y = var->GetValFloat();
+    var = var->GetNext();
+    float x = var->GetValFloat();
+    
+    result->SetValFloat(atan2(y, x) * 180.0f / Math::PI);
+    return true;
+}
+
 // Instruction "sqrt(value)".
 
 bool CScriptFunctions::rSqrt(CBotVar* var, CBotVar* result, int& exception, void* user)
@@ -3859,6 +3871,7 @@ void CScriptFunctions::Init()
     CBotProgram::AddFunction("asin",      raSin,      CScriptFunctions::cOneFloat);
     CBotProgram::AddFunction("acos",      raCos,      CScriptFunctions::cOneFloat);
     CBotProgram::AddFunction("atan",      raTan,      CScriptFunctions::cOneFloat);
+    CBotProgram::AddFunction("atan2",     raTan2,     CScriptFunctions::cTwoFloat);
     CBotProgram::AddFunction("sqrt",      rSqrt,      CScriptFunctions::cOneFloat);
     CBotProgram::AddFunction("pow",       rPow,       CScriptFunctions::cTwoFloat);
     CBotProgram::AddFunction("rand",      rRand,      CScriptFunctions::cNull);

-- 
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