2012-03-19 11:44:39 +00:00
|
|
|
|
// * This file is part of the COLOBOT source code
|
2012-03-09 16:08:05 +00:00
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
|
// *
|
|
|
|
|
// * 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
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2012-07-10 20:58:52 +00:00
|
|
|
|
#ifndef _CBOTDLL_H_
|
|
|
|
|
#define _CBOTDLL_H_
|
|
|
|
|
/**
|
|
|
|
|
* \file CBotDll.h
|
|
|
|
|
* \brief Library for interpretation of CBOT language
|
|
|
|
|
*/
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-07-10 20:58:52 +00:00
|
|
|
|
#include "resource.h"
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <cstring>
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
#define CBOTVERSION 104
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// forward declaration of needed classes
|
|
|
|
|
|
|
|
|
|
class CBotToken; // program turned into "tokens
|
|
|
|
|
class CBotStack; // for the execution stack
|
|
|
|
|
class CBotClass; // class of object
|
|
|
|
|
class CBotInstr; // instruction to be executed
|
|
|
|
|
class CBotFunction; // user functions
|
|
|
|
|
class CBotVar; // variables
|
|
|
|
|
class CBotVarClass; // instance of class
|
|
|
|
|
class CBotVarPointer; // pointer to an instance of class
|
2012-08-07 10:46:19 +00:00
|
|
|
|
class CBotCall; // functions
|
2012-07-10 20:58:52 +00:00
|
|
|
|
class CBotCallMethode; // methods
|
|
|
|
|
class CBotDefParam; // parameter list
|
|
|
|
|
class CBotCStack; // stack
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// Variables management
|
2012-03-08 18:32:05 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
/** \brief CBotType Defines known types. This types are modeled on Java types. Do not change the order of elements */
|
2012-03-08 18:32:05 +00:00
|
|
|
|
enum CBotType
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotTypVoid = 0,
|
2012-07-20 21:13:02 +00:00
|
|
|
|
CBotTypByte = 1, //n
|
|
|
|
|
CBotTypShort = 2, //n
|
|
|
|
|
CBotTypChar = 3, //n
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotTypInt = 4,
|
2012-07-20 21:13:02 +00:00
|
|
|
|
CBotTypLong = 5, //n
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotTypFloat = 6,
|
2012-07-20 21:13:02 +00:00
|
|
|
|
CBotTypDouble = 7, //n
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotTypBoolean = 8,
|
|
|
|
|
CBotTypString = 9,
|
|
|
|
|
|
|
|
|
|
CBotTypArrayPointer = 10, // array of variables
|
|
|
|
|
CBotTypArrayBody = 11, // same but creates an instance
|
|
|
|
|
|
|
|
|
|
CBotTypPointer = 12, // pointer to an instance
|
|
|
|
|
CBotTypNullPointer = 13, // null pointer is special
|
|
|
|
|
CBotTypClass = 15,
|
|
|
|
|
CBotTypIntrinsic = 16 // instance of a class intrinsic
|
2012-03-08 18:32:05 +00:00
|
|
|
|
};
|
2012-07-20 21:13:02 +00:00
|
|
|
|
//n = not implemented yet
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
// for SetUserPtr when deleting an object
|
2012-03-08 18:32:05 +00:00
|
|
|
|
#define OBJECTDELETED ((void*)-1)
|
2012-07-20 21:13:02 +00:00
|
|
|
|
// value set before initialization
|
2012-03-08 18:32:05 +00:00
|
|
|
|
#define OBJECTCREATED ((void*)-2)
|
|
|
|
|
|
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
/** \brief CBotTypResult class to define the complete type of a result*/
|
2012-03-08 18:32:05 +00:00
|
|
|
|
class CBotTypResult
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-07-20 21:13:02 +00:00
|
|
|
|
/**
|
2012-08-07 10:46:19 +00:00
|
|
|
|
* \brief CBotTypResult constructor for simple types (CBotTypInt to CBotTypString)
|
2012-07-20 21:13:02 +00:00
|
|
|
|
* \param type type of created result, see CBotType
|
|
|
|
|
*/
|
|
|
|
|
CBotTypResult(int type);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// for simple types (CBotTypInt à CBotTypString)
|
2012-07-20 21:13:02 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
CBotTypResult(int type, const char* name);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// for pointer types and intrinsic classes
|
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
CBotTypResult(int type, CBotClass* pClass);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// for the instance of a class
|
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
CBotTypResult(int type, CBotTypResult elem);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// for arrays of variables
|
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
CBotTypResult(const CBotTypResult& typ);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// for assignments
|
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
CBotTypResult();
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// for default
|
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
~CBotTypResult();
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
int GivType(int mode = 0) const;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// returns type CBotType* as a result
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
void SetType(int n);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// modifies a type
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
CBotClass* GivClass() const;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// makes the pointer to the class (for CBotTypClass, CBotTypPointer)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
int GivLimite() const;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// returns limit size of table (CBotTypArray)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
void SetLimite(int n);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// set limit to the table
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
void SetArray(int* max );
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// set limits for a list of dimensions (arrays of arrays)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
CBotTypResult& GivTypElem() const;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// returns type of array elements (CBotTypArray)
|
|
|
|
|
// rend le type des éléments du tableau (CBotTypArray)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
bool Compare(const CBotTypResult& typ) const;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// compares whether the types are compatible
|
2012-07-10 20:58:52 +00:00
|
|
|
|
bool Eq(int type) const;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// compare type
|
|
|
|
|
|
|
|
|
|
CBotTypResult& operator=(const CBotTypResult& src);
|
|
|
|
|
// copy a complete type in another
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
private:
|
|
|
|
|
int m_type;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotTypResult* m_pNext; // for the types of type
|
|
|
|
|
CBotClass* m_pClass; // for the derivatives of class
|
|
|
|
|
int m_limite; // limits of tables
|
2012-07-20 21:13:02 +00:00
|
|
|
|
friend class CBotVarClass;
|
|
|
|
|
friend class CBotVarPointer;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// to define a result as output, using for example
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// to return a simple Float
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return CBotTypResult( CBotTypFloat );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// to return a string array
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return CBotTypResult( CBotTypArray, CBotTypResult( CBotTypString ) );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// to return un array of array of "point" class
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotTypResult typPoint( CBotTypIntrinsic, "point" );
|
|
|
|
|
CBotTypResult arrPoint( CBotTypArray, typPoint );
|
|
|
|
|
return CBotTypResult( CBotTypArray, arrPoint );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// Error Handling of compilation and execution
|
2012-03-08 18:32:05 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// Here are the list of errors that can be returned by the module
|
|
|
|
|
// for compilation
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
#define CBotErrOpenPar 5000 // missing the opening parenthesis
|
|
|
|
|
#define CBotErrClosePar 5001 // missing the closing parenthesis
|
|
|
|
|
#define CBotErrNotBoolean 5002 // expression must be a boolean
|
|
|
|
|
#define CBotErrUndefVar 5003 // undeclared variable
|
|
|
|
|
#define CBotErrBadLeft 5004 // assignment impossible ( 5 = ... )
|
|
|
|
|
#define CBotErrNoTerminator 5005 // semicolon expected
|
|
|
|
|
#define CBotErrCaseOut 5006 // case outside a switch
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// CBotErrNoTerm 5007, plus utile
|
2012-08-07 10:46:19 +00:00
|
|
|
|
#define CBotErrCloseBlock 5008 // missing " } "
|
|
|
|
|
#define CBotErrElseWhitoutIf 5009 // else without matching if
|
|
|
|
|
#define CBotErrOpenBlock 5010 // missing " { "
|
|
|
|
|
#define CBotErrBadType1 5011 // wrong type for the assignment
|
|
|
|
|
#define CBotErrRedefVar 5012 // redefinition of the variable
|
|
|
|
|
#define CBotErrBadType2 5013 // Two operands are incompatible
|
|
|
|
|
#define CBotErrUndefCall 5014 // routine undefined
|
|
|
|
|
#define CBotErrNoDoubleDots 5015 // " : " expected
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// CBotErrWhile 5016, plus utile
|
2012-08-07 10:46:19 +00:00
|
|
|
|
#define CBotErrBreakOutside 5017 // break outside of a loop
|
|
|
|
|
#define CBotErrUndefLabel 5019 // label udnefined
|
|
|
|
|
#define CBotErrLabel 5018 // label ne peut se mettre ici (label can not get here)
|
|
|
|
|
#define CBotErrNoCase 5020 // missing " case "
|
|
|
|
|
#define CBotErrBadNum 5021 // expected number
|
|
|
|
|
#define CBotErrVoid 5022 // " void " not possible here
|
|
|
|
|
#define CBotErrNoType 5023 // type declaration expected
|
|
|
|
|
#define CBotErrNoVar 5024 // variable name expected
|
|
|
|
|
#define CBotErrNoFunc 5025 // expected function name
|
|
|
|
|
#define CBotErrOverParam 5026 // too many parameters
|
|
|
|
|
#define CBotErrRedefFunc 5027 // this function already exists
|
|
|
|
|
#define CBotErrLowParam 5028 // not enough parameters
|
|
|
|
|
#define CBotErrBadParam 5029 // wrong types of parameters
|
|
|
|
|
#define CBotErrNbParam 5030 // wrong number of parameters
|
|
|
|
|
#define CBotErrUndefItem 5031 // element does not exist in the class
|
|
|
|
|
#define CBotErrUndefClass 5032 // variable is not a class
|
|
|
|
|
#define CBotErrNoConstruct 5033 // no appropriate constructor
|
|
|
|
|
#define CBotErrRedefClass 5034 // class already exists
|
|
|
|
|
#define CBotErrCloseIndex 5035 // " ] " expected
|
|
|
|
|
#define CBotErrReserved 5036 // reserved word (for a DefineNum)
|
|
|
|
|
#define CBotErrBadNew 5037 // wrong setting for new
|
|
|
|
|
#define CBotErrOpenIndex 5038 // " [ " expected
|
|
|
|
|
#define CBotErrBadString 5039 // expected string
|
|
|
|
|
#define CBotErrBadIndex 5040 // wrong index type "[ false ]"
|
|
|
|
|
#define CBotErrPrivate 5041 // protected item
|
|
|
|
|
#define CBotErrNoPublic 5042 // missing word "public"
|
|
|
|
|
|
|
|
|
|
// here is the list of errors that can be returned by the module
|
|
|
|
|
// for the execution
|
|
|
|
|
|
|
|
|
|
#define CBotErrZeroDiv 6000 // division by zero
|
|
|
|
|
#define CBotErrNotInit 6001 // uninitialized variable
|
|
|
|
|
#define CBotErrBadThrow 6002 // throw a negative value
|
|
|
|
|
#define CBotErrNoRetVal 6003 // function did not return results
|
|
|
|
|
#define CBotErrNoRun 6004 // Run() without active function
|
|
|
|
|
#define CBotErrUndefFunc 6005 // calling a function that no longer exists
|
|
|
|
|
#define CBotErrNotClass 6006 // this class does not exist
|
|
|
|
|
#define CBotErrNull 6007 // null pointer
|
|
|
|
|
#define CBotErrNan 6008 // calculation with a NAN
|
|
|
|
|
#define CBotErrOutArray 6009 // index out of array
|
|
|
|
|
#define CBotErrStackOver 6010 // stack overflow
|
|
|
|
|
#define CBotErrDeletedPtr 6011 // pointer to an object destroyed
|
|
|
|
|
|
|
|
|
|
#define CBotErrFileOpen 6012 // cannot open the file
|
|
|
|
|
#define CBotErrNotOpen 6013 // channel not open
|
|
|
|
|
#define CBotErrRead 6014 // error while reading
|
|
|
|
|
#define CBotErrWrite 6015 // writing error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// other values may be returned
|
|
|
|
|
// for example exceptions returned by external routines
|
|
|
|
|
// and " throw " with any number.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2012-07-20 21:13:02 +00:00
|
|
|
|
//
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// as part of MFC CString not used here.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
//
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// ( all functions are not implemented yet )
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-20 21:13:02 +00:00
|
|
|
|
/** \brief CBotString Class used to work on strings */
|
2012-03-08 18:32:05 +00:00
|
|
|
|
class CBotString
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
public:
|
|
|
|
|
CBotString();
|
|
|
|
|
CBotString(const char* p);
|
|
|
|
|
CBotString(const CBotString& p);
|
|
|
|
|
~CBotString();
|
|
|
|
|
|
|
|
|
|
void Empty();
|
|
|
|
|
bool IsEmpty() const;
|
|
|
|
|
int GivLength();
|
|
|
|
|
int Find(const char c);
|
|
|
|
|
int Find(const char* lpsz);
|
|
|
|
|
int ReverseFind(const char c);
|
|
|
|
|
int ReverseFind(const char* lpsz);
|
|
|
|
|
bool LoadString(unsigned int id);
|
|
|
|
|
CBotString Mid(int nFirst, int nCount) const;
|
|
|
|
|
CBotString Mid(int nFirst) const;
|
|
|
|
|
CBotString Mid(int start, int lg=-1);
|
|
|
|
|
CBotString Left(int nCount) const;
|
|
|
|
|
CBotString Right(int nCount) const;
|
|
|
|
|
int Compare(const char* lpsz) const;
|
|
|
|
|
void MakeUpper();
|
|
|
|
|
void MakeLower();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Overloaded oprators to work on CBotString classes
|
|
|
|
|
*/
|
|
|
|
|
const CBotString& operator=(const CBotString& stringSrc);
|
|
|
|
|
const CBotString& operator=(const char ch);
|
|
|
|
|
const CBotString& operator=(const char* pString);
|
|
|
|
|
const CBotString& operator+(const CBotString& str);
|
|
|
|
|
friend CBotString operator+(const CBotString& string, const char* lpsz);
|
|
|
|
|
|
|
|
|
|
const CBotString& operator+=(const char ch);
|
|
|
|
|
const CBotString& operator+=(const CBotString& str);
|
|
|
|
|
bool operator==(const CBotString& str);
|
|
|
|
|
bool operator==(const char* p);
|
|
|
|
|
bool operator!=(const CBotString& str);
|
|
|
|
|
bool operator!=(const char* p);
|
|
|
|
|
bool operator>(const CBotString& str);
|
|
|
|
|
bool operator>(const char* p);
|
|
|
|
|
bool operator>=(const CBotString& str);
|
|
|
|
|
bool operator>=(const char* p);
|
|
|
|
|
bool operator<(const CBotString& str);
|
|
|
|
|
bool operator<(const char* p);
|
|
|
|
|
bool operator<=(const CBotString& str);
|
|
|
|
|
bool operator<=(const char* p);
|
|
|
|
|
|
|
|
|
|
operator const char*() const; // as a C string
|
|
|
|
|
|
|
|
|
|
|
2012-03-08 18:32:05 +00:00
|
|
|
|
private:
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
/** \brief Pointer to string */
|
|
|
|
|
char* m_ptr;
|
|
|
|
|
|
|
|
|
|
/** \brief Length of the string */
|
|
|
|
|
int m_lg;
|
|
|
|
|
|
|
|
|
|
/** \brief Keeps the string corresponding to keyword ID */
|
2012-07-20 21:13:02 +00:00
|
|
|
|
static const std::map<EID, char *> s_keywordString;
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief MapIdToString maps given ID to its string equivalent
|
|
|
|
|
* \param id Provided identifier
|
|
|
|
|
* \return string if found, else NullString
|
|
|
|
|
*/
|
|
|
|
|
static const char * MapIdToString(EID id);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// Class used to array management
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
class CBotStringArray : public CBotString
|
|
|
|
|
{
|
|
|
|
|
private:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int m_nSize; // number of elements
|
|
|
|
|
int m_nMaxSize; // reserved size
|
|
|
|
|
CBotString* m_pData; // ^data
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStringArray();
|
|
|
|
|
~CBotStringArray();
|
|
|
|
|
void SetSize(int nb);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int GivSize();
|
2012-07-10 20:58:52 +00:00
|
|
|
|
void Add(const CBotString& str);
|
|
|
|
|
CBotString& operator[](int nIndex);
|
|
|
|
|
|
|
|
|
|
CBotString& ElementAt(int nIndex);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// different modes for GetPosition
|
2012-03-08 18:32:05 +00:00
|
|
|
|
enum CBotGet
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
GetPosExtern = 1,
|
|
|
|
|
GetPosNom = 2,
|
|
|
|
|
GetPosParam = 3,
|
|
|
|
|
GetPosBloc = 4
|
2012-03-08 18:32:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// main class managing CBot program
|
2012-03-08 18:32:05 +00:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
class CBotProgram
|
|
|
|
|
{
|
|
|
|
|
private:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotFunction* m_Prog; // the user-defined functions
|
|
|
|
|
CBotFunction* m_pRun; // the basic function for the execution
|
|
|
|
|
CBotClass* m_pClass; // classes defined in this part
|
|
|
|
|
CBotStack* m_pStack; // execution stack
|
|
|
|
|
CBotVar* m_pInstance; // instance of the parent class
|
2012-07-10 20:58:52 +00:00
|
|
|
|
friend class CBotFunction;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int m_ErrorCode;
|
|
|
|
|
int m_ErrorStart;
|
|
|
|
|
int m_ErrorEnd;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
long m_Ident; // associated identifier
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
static CBotString m_DebugVarStr; // end of a debug
|
|
|
|
|
bool m_bDebugDD; // idem déclanchable par robot \TODO ???
|
|
|
|
|
bool m_bCompileClass;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
static void Init();
|
|
|
|
|
// initializes the module (defined keywords for errors)
|
|
|
|
|
// should be done once (and only one) at the beginning
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
|
|
|
|
void Free();
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// frees the static memory areas
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int GivVersion();
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// gives the version of the library CBOT
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CBotProgram();
|
|
|
|
|
CBotProgram(CBotVar* pInstance);
|
|
|
|
|
~CBotProgram();
|
|
|
|
|
|
|
|
|
|
bool Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = NULL);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// compiles the program given in text
|
|
|
|
|
// returns false if an error at compile
|
|
|
|
|
// see GetCompileError () to retrieve the error
|
|
|
|
|
// ListFonctions returns the names of functions declared as extern
|
|
|
|
|
// pUser can pass a pointer to routines defined by AddFunction
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
void SetIdent(long n);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// associates an identifier with the instance CBotProgram
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
long GivIdent();
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// gives the identifier
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
int GivError();
|
|
|
|
|
bool GetError(int& code, int& start, int& end);
|
|
|
|
|
bool GetError(int& code, int& start, int& end, CBotProgram* &pProg);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// if true
|
|
|
|
|
// gives the error found in the compilation
|
|
|
|
|
// or execution
|
|
|
|
|
// delimits the start and end block where the error
|
|
|
|
|
// pProg lets you know what "module" has produced runtime error
|
|
|
|
|
static CBotString GivErrorText(int code);
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Start(const char* name);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// defines what function should be executed
|
|
|
|
|
// returns false if the funtion name is not found
|
|
|
|
|
// the program does nothing, we must call Run () for this
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
bool Run(void* pUser = NULL, int timer = -1);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// executes the program
|
|
|
|
|
// returns false if the program was suspended
|
|
|
|
|
// returns true if the program ended with or without error
|
|
|
|
|
// timer = 0 allows to advance step by step
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
bool GetRunPos(const char* &FunctionName, int &start, int &end);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// gives the position in the executing program
|
|
|
|
|
// returns false if it is not running (program completion)
|
|
|
|
|
// FunctionName is a pointer made to the name of the function
|
|
|
|
|
// start and end position in the text of the token processing
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
CBotVar* GivStackVars(const char* &FunctionName, int level);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// provides the pointer to the variables on the execution stack
|
|
|
|
|
// level is an input parameter, 0 for the last level, -1, -2, etc. for the other levels
|
|
|
|
|
// the return value (CBotVar *) is a variable list (or NULL)
|
|
|
|
|
// that can be processed as the list of parameters received by a routine
|
|
|
|
|
// FunctionName gives the name of the function where are these variables
|
|
|
|
|
// FunctionName == NULL means that is more in a program (depending on level)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
void Stop();
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// stops execution of the program
|
|
|
|
|
// therefore quits "suspend" mode
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void SetTimer(int n);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// defines the number of steps (parts of instructions) to done
|
|
|
|
|
// in Run() before rendering hand "false" \TODO avant de rendre la main "false"
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
bool AddFunction(const char* name,
|
|
|
|
|
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
|
|
|
|
|
CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// call this to add externally (**)
|
|
|
|
|
// a new function used by the program CBoT
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
bool DefineNum(const char* name, long val);
|
|
|
|
|
|
|
|
|
|
bool SaveState(FILE* pf);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// backup the execution status in the file
|
|
|
|
|
// the file must have been opened with the fopen call this dll (\TODO this library??)
|
|
|
|
|
// if the system crashes
|
2012-07-10 20:58:52 +00:00
|
|
|
|
bool RestoreState(FILE* pf);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// restores the state of execution from file
|
|
|
|
|
// the compiled program must obviously be the same
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
bool GetPosition(const char* name, int& start, int& stop,
|
|
|
|
|
CBotGet modestart = GetPosExtern,
|
|
|
|
|
CBotGet modestop = GetPosBloc);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// gives the position of a routine in the original text
|
|
|
|
|
// the user can select the item to find from the beginning to the end
|
|
|
|
|
// see the above modes in CBotGet
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CBotFunction* GivFunctions();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// routines for file management (* FILE)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
FILE* fOpen(const char* name, const char* mode);
|
|
|
|
|
int fClose(FILE* filehandle);
|
|
|
|
|
size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle);
|
|
|
|
|
size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
/*
|
|
|
|
|
(**) Note:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
To define an external function, proceed as follows:
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
a) define a routine for compilation
|
|
|
|
|
this routine receive list of parameters (no values)
|
|
|
|
|
and either returns a result type (CBotTyp... or 0 = void)
|
|
|
|
|
or an error number
|
|
|
|
|
b) define a routine for the execution
|
|
|
|
|
this routine receive list of parameters (with valeurs),
|
|
|
|
|
a variable to store the result (according to the given type at compile time)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
For example, a routine which calculates the mean of a parameter list */
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int cMean(CBotVar* &pVar, CBotString& ClassName)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-08-07 10:46:19 +00:00
|
|
|
|
if ( pVar == NULL ) return 6001; // there is no parameter!
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
while ( pVar != NULL )
|
|
|
|
|
{
|
2012-08-07 10:46:19 +00:00
|
|
|
|
if ( pVar->GivType() > CBotTypDouble ) return 6002; // this is not a number
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pVar = pVar -> GivNext();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
return CBotTypFloat; // the type of the result may depend on the parameters!
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
bool rMean(CBotVar* pVar, CBotVar* pResult, int& Exception)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
float total = 0;
|
|
|
|
|
int nb = 0;
|
|
|
|
|
while (pVar != NULL)
|
|
|
|
|
{
|
|
|
|
|
total += pVar->GivValFloat();
|
|
|
|
|
pVar = pVar->GivNext();
|
|
|
|
|
nb++;
|
|
|
|
|
}
|
2012-08-07 10:46:19 +00:00
|
|
|
|
pResult->SetValFloat(total/nb); // returns the mean value
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
return true; // operation fully completed
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// Class for managing variables
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// may be useful to the outside of the module
|
|
|
|
|
// ( it is currently not expected to be able to create these objects in outer )
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// results of GivInit()
|
|
|
|
|
#define IS_UNDEF 0 // undefined variable
|
|
|
|
|
#define IS_DEF 1 // variable defined
|
|
|
|
|
#define IS_NAN 999 // variable defined as not a number
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// variable type SetPrivate / IsPrivate
|
|
|
|
|
#define PR_PUBLIC 0 // public variable
|
2012-07-10 20:58:52 +00:00
|
|
|
|
#define PR_READ 1 // read only
|
2012-08-07 10:46:19 +00:00
|
|
|
|
#define PR_PROTECT 2 // protected (inheritance)
|
|
|
|
|
#define PR_PRIVATE 3 // strictly private
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
class CBotVar
|
|
|
|
|
{
|
|
|
|
|
protected:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotToken* m_token; // the corresponding token
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotVar* m_next; // list of variables
|
2012-07-10 20:58:52 +00:00
|
|
|
|
friend class CBotStack;
|
|
|
|
|
friend class CBotCStack;
|
|
|
|
|
friend class CBotInstrCall;
|
|
|
|
|
friend class CBotProgram;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotTypResult m_type; // type of value
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int m_binit; // not initialized?
|
|
|
|
|
CBotVarClass* m_pMyThis; // ^ corresponding this element
|
|
|
|
|
void* m_pUserPtr; // ^user data if necessary
|
|
|
|
|
bool m_bStatic; // static element (in class)
|
|
|
|
|
int m_mPrivate; // element public, protected or private?
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotInstr* m_InitExpr; // expression for the original content
|
|
|
|
|
CBotInstr* m_LimExpr; // list of limits for a table
|
2012-07-10 20:58:52 +00:00
|
|
|
|
friend class CBotClass;
|
|
|
|
|
friend class CBotVarClass;
|
|
|
|
|
friend class CBotVarPointer;
|
|
|
|
|
friend class CBotVarArray;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
long m_ident; // unique identifier
|
|
|
|
|
static long m_identcpt; // counter
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar();
|
2012-08-07 10:46:19 +00:00
|
|
|
|
virtual ~CBotVar( ); // destructor
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
CBotVar* Create( const char* name, CBotTypResult type);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// creates from a complete type
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
CBotVar* Create( const char* name, CBotClass* pClass);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// creates from one instance of a known class
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
CBotVar* Create( const CBotToken* name, int type );
|
|
|
|
|
static
|
|
|
|
|
CBotVar* Create( const CBotToken* name, CBotTypResult type );
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
CBotVar* Create( const char* name, int type, CBotClass* pClass);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
|
|
|
|
CBotVar* Create( CBotVar* pVar );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
void SetUserPtr(void* pUser);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// associate a user pointer to an instance
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual void SetIdent(long UniqId);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// associates a unique identifier to an instance
|
|
|
|
|
// ( it is used to ensure that the id is unique)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
void* GivUserPtr();
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// makes the pointer associated with the variable
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotString GivName(); // the name of the variable, if known
|
2012-07-10 20:58:52 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
2012-08-07 10:46:19 +00:00
|
|
|
|
void SetName(const char* name); // changes the name of the variable
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int GivType(int mode = 0); // returns the base type (int) of the variable
|
|
|
|
|
// TODO check it
|
2012-07-10 20:58:52 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotTypResult GivTypResult(int mode = 0); // returns the complete type of the variable
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotToken* GivToken();
|
|
|
|
|
void SetType(CBotTypResult& type);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
void SetInit(int bInit); // is the variable in the state IS_UNDEF, IS_DEF, IS_NAN
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int GivInit(); // gives the state of the variable
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
void SetStatic(bool bStatic);
|
|
|
|
|
bool IsStatic();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
void SetPrivate(int mPrivate);
|
|
|
|
|
bool IsPrivate(int mode = PR_PROTECT);
|
|
|
|
|
int GivPrivate();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual
|
|
|
|
|
void ConstructorSet();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
void SetVal(CBotVar* var); // remprend une valeur
|
|
|
|
|
// TODO remprend value
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotVar* GivItem(const char* name); // returns an element of a class according to its name (*)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotVar* GivItemRef(int nIdent); // idem à partir du n° ref
|
|
|
|
|
// TODO ditto from ref no.
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual
|
|
|
|
|
CBotVar* GivItem(int row, bool bGrow = false);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotVar* GivItemList(); // lists the elements
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotVar* GivStaticVar(); // makes the pointer to the variable if it is static
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
bool IsElemOfClass(const char* name);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// said if the element belongs to the class "name"
|
|
|
|
|
// makes true if the object is a subclass
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotVar* GivNext(); // next variable in the list (parameters)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
void AddNext(CBotVar* pVar); // added to a list
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual
|
2012-08-07 10:46:19 +00:00
|
|
|
|
void Copy(CBotVar* pSrc, bool bName = true); // makes a copy of the variable
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual void SetValInt(int val, const char* name = NULL);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// initialized with an integer value (#)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
virtual void SetValFloat(float val); // initialized with a real value (#)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
virtual void SetValString(const char* p);// initialized with a string value (#)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
virtual int GivValInt(); // request the full value (#)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
virtual float GivValFloat(); // gets real value (#)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotString GivValString(); // request the string value (#)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual void SetClass(CBotClass* pClass);
|
|
|
|
|
virtual
|
|
|
|
|
CBotClass* GivClass();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual void SetPointer(CBotVar* p);
|
|
|
|
|
virtual
|
|
|
|
|
CBotVarClass* GivPointer();
|
|
|
|
|
// virtual void SetIndirection(CBotVar* pVar);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual void Add(CBotVar* left, CBotVar* right); // addition
|
2012-08-07 10:46:19 +00:00
|
|
|
|
virtual void Sub(CBotVar* left, CBotVar* right); // subtraction
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual void Mul(CBotVar* left, CBotVar* right); // multiplication
|
|
|
|
|
virtual int Div(CBotVar* left, CBotVar* right); // division
|
2012-08-07 10:46:19 +00:00
|
|
|
|
virtual int Modulo(CBotVar* left, CBotVar* right); // remainder of division
|
|
|
|
|
virtual void Power(CBotVar* left, CBotVar* right); // power
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual bool Lo(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual bool Hi(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual bool Ls(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual bool Hs(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual bool Eq(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual bool Ne(CBotVar* left, CBotVar* right);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual void And(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual void Or(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual void XOr(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual void ASR(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual void SR(CBotVar* left, CBotVar* right);
|
|
|
|
|
virtual void SL(CBotVar* left, CBotVar* right);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual void Neg();
|
|
|
|
|
virtual void Not();
|
|
|
|
|
virtual void Inc();
|
|
|
|
|
virtual void Dec();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
virtual bool Save0State(FILE* pf);
|
|
|
|
|
virtual bool Save1State(FILE* pf);
|
|
|
|
|
static bool RestoreState(FILE* pf, CBotVar* &pVar);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
void debug();
|
|
|
|
|
|
|
|
|
|
// virtual
|
|
|
|
|
// CBotVar* GivMyThis();
|
|
|
|
|
|
|
|
|
|
virtual
|
|
|
|
|
void Maj(void* pUser = NULL, bool bContinue = true);
|
|
|
|
|
|
|
|
|
|
void SetUniqNum(long n);
|
|
|
|
|
long GivUniqNum();
|
|
|
|
|
static long NextUniqNum();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* NOTE (#)
|
2012-08-07 10:46:19 +00:00
|
|
|
|
methods SetValInt() SetValFloat() et SetValString()
|
|
|
|
|
can be called with objects which are respectively integer, real or string
|
|
|
|
|
Always be sure of the type of the variable before calling these methods
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pVar->GivType() == CBotInt() ) pVar->SetValFloat( 3.3 ); // plante !!
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
methods GivValInt(), GivValFloat() et GivValString()
|
|
|
|
|
use value conversions,
|
|
|
|
|
GivValString() works on numbers (makes the corresponding string)
|
|
|
|
|
but do not make GivValInt () with a string variable!
|
2012-03-08 18:32:05 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// management of classes
|
2012-03-08 18:32:05 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// class to define new classes in the language CBOT
|
|
|
|
|
// for example to define the class CPoint (x, y)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
class CBotClass
|
|
|
|
|
{
|
|
|
|
|
private:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotClass* m_ExClass; // list of classes existing at a given time
|
|
|
|
|
CBotClass* m_ExNext; // for this general list
|
|
|
|
|
CBotClass* m_ExPrev; // for this general list
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotClass* m_pParent; // parent class
|
|
|
|
|
CBotString m_name; // name of this class
|
|
|
|
|
int m_nbVar; // number of variables in the chain
|
|
|
|
|
CBotVar* m_pVar; // content of the class
|
|
|
|
|
bool m_bIntrinsic; // intrinsic class
|
|
|
|
|
CBotClass* m_next; // the string class
|
|
|
|
|
CBotCallMethode* m_pCalls; // list of methods defined in external
|
|
|
|
|
CBotFunction* m_pMethod; // compiled list of methods
|
2012-07-10 20:58:52 +00:00
|
|
|
|
void (*m_rMaj) ( CBotVar* pThis, void* pUser );
|
|
|
|
|
friend class CBotVarClass;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int m_cptLock; // for Lock / UnLock
|
|
|
|
|
int m_cptOne; // Lock for reentrancy
|
|
|
|
|
CBotProgram* m_ProgInLock[5];// processes waiting for sync
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
bool m_IsDef; // mark if is set or not
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
CBotClass( const char* name,
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotClass* pParent, bool bIntrinsic = false ); // constructor
|
|
|
|
|
// Once a class is created, it is known
|
|
|
|
|
// around CBoT
|
|
|
|
|
// intrinsic mode gives a class that is not managed by pointers
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
~CBotClass( ); // destructor
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
bool AddFunction(const char* name,
|
|
|
|
|
bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
|
|
|
|
|
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// this call allows to add as external (**)
|
|
|
|
|
// new method used by the objects of this class
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
bool AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) );
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// defines routine to be called to update the elements of the class
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// adds an element to the class
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// bool AddItem(CBotString name, CBotClass* pClass);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// the same for elements belonging to pClass
|
2012-07-10 20:58:52 +00:00
|
|
|
|
bool AddItem(CBotVar* pVar);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// adds an item by passing the pointer to an instance of a variable
|
|
|
|
|
// the object is taken as is, so do not destroyed
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// adds an element by giving an element of type CBotVar
|
2012-07-10 20:58:52 +00:00
|
|
|
|
void AddNext(CBotClass* pClass);
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotString GivName(); // gives the name of the class
|
|
|
|
|
CBotClass* GivParent(); // gives the parent class (or NULL)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// true if a class is derived (Extends) of another
|
|
|
|
|
// return true also if the classes are identical
|
2012-07-10 20:58:52 +00:00
|
|
|
|
bool IsChildOf(CBotClass* pClass);
|
|
|
|
|
|
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotClass* Find(CBotToken* &pToken); // trouve une classe d'après son nom
|
|
|
|
|
// return a class by it's its name
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
|
|
|
|
CBotClass* Find(const char* name);
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotVar* GivVar(); // return the list of variables
|
|
|
|
|
CBotVar* GivItem(const char* name); // one of the variables according to its name
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* GivItemRef(int nIdent);
|
|
|
|
|
|
|
|
|
|
CBotTypResult CompileMethode(const char* name, CBotVar* pThis, CBotVar** ppParams,
|
|
|
|
|
CBotCStack* pStack, long& nIdent);
|
|
|
|
|
|
|
|
|
|
bool ExecuteMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotVar* &pResult, CBotStack* &pStack, CBotToken* pToken);
|
|
|
|
|
void RestoreMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotStack* &pStack);
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// compiles a class declared by the user
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
|
|
|
|
CBotClass* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
|
static
|
|
|
|
|
CBotClass* Compile1(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
|
|
|
|
|
|
bool CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond);
|
|
|
|
|
|
|
|
|
|
bool IsIntrinsic();
|
|
|
|
|
void Purge();
|
|
|
|
|
static
|
|
|
|
|
void Free();
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
bool SaveStaticState(FILE* pf);
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
bool RestoreStaticState(FILE* pf);
|
|
|
|
|
|
|
|
|
|
bool Lock(CBotProgram* p);
|
|
|
|
|
void Unlock();
|
|
|
|
|
static
|
|
|
|
|
void FreeLock(CBotProgram* p);
|
|
|
|
|
|
|
|
|
|
bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
#define MAXDEFNUM 1000 // limited number of DefineNum
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// Token management (tokens)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
#define TokenTypKeyWord 1 // a keyword of the language (see TokenKeyWord)
|
|
|
|
|
#define TokenTypNum 2 // number
|
|
|
|
|
#define TokenTypString 3 // string
|
|
|
|
|
#define TokenTypVar 4 // a variable name
|
|
|
|
|
#define TokenTypDef 5 // value according DefineNum
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
#define TokenKeyWord 2000 // keywords of the language
|
|
|
|
|
#define TokenKeyDeclare 2100 // keywords of declarations (int, float,..)
|
|
|
|
|
#define TokenKeyVal 2200 // keywords representing the value (true, false, null, nan)
|
|
|
|
|
#define TokenKeyOp 2300 // operators
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/** \class Responsible for token management */
|
2012-03-08 18:32:05 +00:00
|
|
|
|
class CBotToken
|
|
|
|
|
{
|
|
|
|
|
private:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotStringArray m_ListKeyWords; // list of keywords of language
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int m_ListIdKeyWords[200]; // the corresponding codes
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotStringArray m_ListKeyDefine; // names defined by a DefineNum
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
long m_ListKeyNums[MAXDEFNUM]; // the associated values
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotToken* m_next; // following in the list
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotToken* m_prev;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int m_type; // type of Token
|
|
|
|
|
long m_IdKeyWord; // number of the keyword if it is a
|
|
|
|
|
// or value of the "define"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
CBotString m_Text; // word found as token
|
|
|
|
|
CBotString m_Sep; // following separators
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int m_start; // position in the original text (program)
|
|
|
|
|
int m_end; // the same for the end of the token
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Check whether given parameter is a keyword
|
|
|
|
|
*/
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
int GivKeyWords(const char* w); // is it a keyword?
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
|
|
|
|
bool GivKeyDefNum(const char* w, CBotToken* &token);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief Loads the list of keywords
|
|
|
|
|
*/
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
void LoadKeyWords();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief Constructors
|
|
|
|
|
*/
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotToken();
|
|
|
|
|
CBotToken(const CBotToken* pSrc);
|
|
|
|
|
CBotToken(const CBotString& mot, const CBotString& sep, int start=0, int end=0);
|
|
|
|
|
CBotToken(const char* mot, const char* sep = NULL);
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief Destructor
|
|
|
|
|
*/
|
|
|
|
|
~CBotToken();
|
|
|
|
|
/**
|
|
|
|
|
* \brief Returns the type of token
|
|
|
|
|
*/
|
|
|
|
|
int GivType();
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief makes the string corresponding to this token
|
|
|
|
|
*/
|
|
|
|
|
CBotString& GivString();
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief makes the following separator token
|
|
|
|
|
*/
|
|
|
|
|
CBotString& GivSep();
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief position of the beginning in the text
|
|
|
|
|
*/
|
|
|
|
|
int GivStart();
|
|
|
|
|
/**
|
|
|
|
|
* \brief end position in the text
|
|
|
|
|
*/
|
|
|
|
|
int GivEnd();
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief gives the next token in the list
|
|
|
|
|
*/
|
|
|
|
|
CBotToken* GivNext();
|
|
|
|
|
/**
|
|
|
|
|
* \brief gives the previous token in a list
|
|
|
|
|
*/
|
|
|
|
|
CBotToken* GivPrev();
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief transforms the entire program
|
|
|
|
|
*/
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
|
|
|
|
CBotToken* CompileTokens(const char* p, int& error);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief releases the list
|
|
|
|
|
*/
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
2012-08-07 10:46:19 +00:00
|
|
|
|
void Delete(CBotToken* pToken); // libère la liste
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fonctions non utiles en export
|
|
|
|
|
static
|
|
|
|
|
bool DefineNum(const char* name, long val);
|
|
|
|
|
void SetString(const char* name);
|
|
|
|
|
|
|
|
|
|
void SetPos(int start, int end);
|
|
|
|
|
long GivIdKey();
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief adds a token (a copy)
|
|
|
|
|
*/
|
|
|
|
|
void AddNext(CBotToken* p);
|
2012-07-10 20:58:52 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* finds the next token
|
|
|
|
|
*/
|
2012-07-10 20:58:52 +00:00
|
|
|
|
static
|
|
|
|
|
CBotToken* NextToken(char* &program, int& error, bool first = false);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
const CBotToken&
|
|
|
|
|
operator=(const CBotToken& src);
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void Free();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// Examples of use
|
|
|
|
|
// Definition classes and functions
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// define the global class CPoint
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// --------------------------------
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassPoint = new CBotClass("CPoint", NULL);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// adds the component ".x"
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassPoint->AddItem("x", CBotTypResult(CBotTypFloat));
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// adds the component ".y"
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassPoint->AddItem("y", CBotTypResult(CBotTypFloat));
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// the player can then use the instructions
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// CPoint position; position.x = 12; position.y = -13.6
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// define class CColobotObject
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// --------------------------------
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// This class manages all the objects in the world of COLOBOT
|
|
|
|
|
// the "main" user program belongs to this class
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassObject = new CBotClass("CColobotObject", m_pClassBase);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// adds the component ".position"
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassObject->AddItem("position", m_pClassPoint);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// adds the component ".type"
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassObject->AddItem("type", CBotTypResult(CBotTypShort));
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// adds a definition of constant
|
|
|
|
|
m_pClassObject->AddConst("ROBOT", CBotTypShort, 1); // ROBOT equivalent to the value 1
|
|
|
|
|
// adds the FIND routine
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassObject->AddFunction( rCompFind, rDoFind );
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// the player can now use the instructions
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// CColobotObject chose; chose = FIND( ROBOT )
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// define class CColobotRobot derived from CColobotObject
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// ---------------------------------------------------------
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// programs "main" associated with robots as a part of this class
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassRobot = new CBotClass("CColobotRobot", m_pClassObject);
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// add routine GOTO
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_pClassRobot->AddFunction( rCompGoto, rDoGoto );
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// the player can now use
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// GOTO( FIND ( ROBOT ) );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// creates an instance of the class Robot
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// ------------------------------------
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// for example a new robot which has just been manufactured
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* m_pMonRobot = new CBotVar("MonRobot", m_pClassRobot);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// compiles the program by hand for this robot
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// ------------------------------------------
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CString LeProgramme( "void main() {GOTO(0, 0); return 0;}" );
|
2012-08-07 10:46:19 +00:00
|
|
|
|
if ( !m_pMonRobot->Compile( LeProgramme ) ) {error handling ...};
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// build a stack for interpreter
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// --------------------------------------
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pStack = new CBotStack(NULL);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// executes the main program
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// -------------------------
|
2012-07-10 20:58:52 +00:00
|
|
|
|
while( false = m_pMonRobot->Execute( "main", pStack ))
|
|
|
|
|
{
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// program suspended
|
|
|
|
|
// could be pass a handle to another (safeguarding pstack for the robot one)
|
2012-07-10 20:58:52 +00:00
|
|
|
|
};
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// programme "main" finished !
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// routine that implements the GOTO (CPoint pos)
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool rDoGoto( CBotVar* pVar, CBotVar* pResult, int& exception )
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (pVar->GivType() != CBotTypeClass ||
|
|
|
|
|
pVar->IsElemOfClas("CPoint") ) { exception = 6522; return false; )
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// the parameter is not the right class?
|
|
|
|
|
// in fact the control is done to the routine of compilation
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
m_PosToGo.Copy( pVar ); // keeps the target position (object type CBotVar)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
// or so
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* temp;
|
2012-08-07 10:46:19 +00:00
|
|
|
|
temp = pVar->GivItem("x"); // is necessary for the object of type CPoint
|
2012-07-10 20:58:52 +00:00
|
|
|
|
ASSERT (temp != NULL && temp->GivType() == CBotTypFloat);
|
|
|
|
|
m_PosToGo.x = temp->GivValFloat();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
temp = pVar->GivItem("y"); // is necessary for the object of type CPoint
|
2012-07-10 20:58:52 +00:00
|
|
|
|
ASSERT (temp != NULL && temp->GivType() == CBotTypFloat);
|
|
|
|
|
m_PosToGo.y = temp->GivValFloat();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-08-07 10:46:19 +00:00
|
|
|
|
return (m_CurentPos == m_PosToGo); // makes true if the position is reached
|
|
|
|
|
// returns false if one had wait yet
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
#endif
|
2012-07-10 20:58:52 +00:00
|
|
|
|
#endif //_CBOTDLL_H_
|
|
|
|
|
|