Transation of comments complete
parent
0844a0f7bd
commit
0919796df7
|
@ -1,142 +1,144 @@
|
||||||
// * This file is part of the COLOBOT source code
|
// * This file is part of the COLOBOT source code
|
||||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||||
// *
|
// *
|
||||||
// * This program is free software: you can redistribute it and/or modify
|
// * 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
|
// * it under the terms of the GNU General Public License as published by
|
||||||
// * the Free Software Foundation, either version 3 of the License, or
|
// * the Free Software Foundation, either version 3 of the License, or
|
||||||
// * (at your option) any later version.
|
// * (at your option) any later version.
|
||||||
// *
|
// *
|
||||||
// * This program is distributed in the hope that it will be useful,
|
// * This program is distributed in the hope that it will be useful,
|
||||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
// expression du genre Opérande1 + Opérande2
|
|
||||||
// Opérande1 - Opérande2
|
///////////////////////////////////////////////////
|
||||||
|
// expressions of type Operand1 + Operand2
|
||||||
#include "CBot.h"
|
// Operand1 - Operand2
|
||||||
|
|
||||||
// divers constructeurs
|
#include "CBot.h"
|
||||||
|
|
||||||
CBotAddExpr::CBotAddExpr()
|
// various constructors
|
||||||
{
|
|
||||||
m_leftop =
|
CBotAddExpr::CBotAddExpr()
|
||||||
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
|
{
|
||||||
name = "CBotAddExpr"; // debug
|
m_leftop =
|
||||||
}
|
m_rightop = NULL; // NULL to be able to delete without further
|
||||||
|
name = "CBotAddExpr"; // debug
|
||||||
CBotAddExpr::~CBotAddExpr()
|
}
|
||||||
{
|
|
||||||
delete m_leftop;
|
CBotAddExpr::~CBotAddExpr()
|
||||||
delete m_rightop;
|
{
|
||||||
}
|
delete m_leftop;
|
||||||
|
delete m_rightop;
|
||||||
|
}
|
||||||
// compile une instruction de type A + B
|
|
||||||
|
|
||||||
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
|
// compile une instruction de type A + B
|
||||||
{
|
|
||||||
CBotStack* pStk = pStack->TokenStack(); // un bout de pile svp
|
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
|
||||||
|
{
|
||||||
// cherche des instructions qui peuvent convenir à gauche de l'opération + ou -
|
CBotStack* pStk = pStack->TokenStack(); // one end of stack please
|
||||||
|
|
||||||
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B à gauche
|
// looking statements that may be suitable to the left of the operation + or -
|
||||||
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
|
|
||||||
|
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B left
|
||||||
// est-ce qu'on a le token + ou - ensuite ?
|
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
|
||||||
|
|
||||||
if ( p->GetType() == ID_ADD ||
|
// do we have the token + or - next?
|
||||||
p->GetType() == ID_SUB) // plus ou moins
|
|
||||||
{
|
if ( p->GetType() == ID_ADD ||
|
||||||
CBotAddExpr* inst = new CBotAddExpr(); // élément pour opération
|
p->GetType() == ID_SUB) // more or less
|
||||||
inst->SetToken(p); // mémorise l'opération
|
{
|
||||||
|
CBotAddExpr* inst = new CBotAddExpr(); // element for operation
|
||||||
int type1, type2;
|
inst->SetToken(p); // stores the operation
|
||||||
type1 = pStack->GetType(); // de quel type le premier opérande ?
|
|
||||||
|
int type1, type2;
|
||||||
p = p->Next(); // saute le token de l'opération
|
type1 = pStack->GetType(); // what kind of the first operand?
|
||||||
|
|
||||||
// cherche des instructions qui peuvent convenir à droite
|
p = p->Next(); // skip the token of the operation
|
||||||
|
|
||||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) à droite
|
// looking statements that may be suitable for right
|
||||||
{
|
|
||||||
// il y a un second opérande acceptable
|
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) rigth
|
||||||
|
{
|
||||||
type2 = pStack->GetType(); // de quel type le résultat ?
|
// there is an acceptable second operand
|
||||||
|
|
||||||
if ( type1 == type2 ) // les résultats sont-ils compatibles
|
type2 = pStack->GetType(); // what kind of results?
|
||||||
{
|
|
||||||
// si ok, enregistre l'opérande dans l'objet
|
if ( type1 == type2 ) // are the results consistent ?
|
||||||
inst->m_leftop = left;
|
{
|
||||||
// et rend l'object à qui l'a demandé
|
// ok so, saves the operand in the object
|
||||||
return pStack->Return(inst, pStk);
|
inst->m_leftop = left;
|
||||||
}
|
// and makes the object on demand
|
||||||
}
|
return pStack->Return(inst, pStk);
|
||||||
|
}
|
||||||
// en cas d'erreur, libère les éléments
|
}
|
||||||
delete left;
|
|
||||||
delete inst;
|
// in case of error, free the elements
|
||||||
// et transmet l'erreur qui se trouve sur la pile
|
delete left;
|
||||||
return pStack->Return(NULL, pStk);
|
delete inst;
|
||||||
}
|
// and transmits the error that is on the stack
|
||||||
|
return pStack->Return(NULL, pStk);
|
||||||
// si on n'a pas affaire à une opération + ou -
|
}
|
||||||
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
|
|
||||||
// à la place de l'objet "addition"
|
// if we are not dealing with an operation + or -
|
||||||
return pStack->Return(left, pStk);
|
// goes to that requested, the operand (left) found
|
||||||
}
|
// place the object "addition"
|
||||||
|
return pStack->Return(left, pStk);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// fait l'opération d'addition ou de soustraction
|
|
||||||
|
|
||||||
bool CBotAddExpr::Execute(CBotStack* &pStack)
|
// operation is addition or subtraction
|
||||||
{
|
|
||||||
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
|
bool CBotAddExpr::Execute(CBotStack* &pStack)
|
||||||
// ou le retrouve en cas de reprise
|
{
|
||||||
// if ( pSk1 == EOX ) return TRUE;
|
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
|
||||||
|
// or is found in case of recovery
|
||||||
|
// if ( pSk1 == EOX ) return TRUE;
|
||||||
// selon la reprise, on peut être dans l'un des 2 états
|
|
||||||
|
|
||||||
if ( pStk1->GetState() == 0 && // 1er état, évalue l'opérande de gauche
|
// according to recovery, it may be in one of two states
|
||||||
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
|
||||||
|
if ( pStk1->GetState() == 0 && // first state, evaluates the left operand
|
||||||
// passe à l'étape suivante
|
!m_leftop->Execute(pStk1) ) return FALSE; // interrupted here?
|
||||||
pStk1->SetState(1); // prêt pour la suite
|
|
||||||
|
// passes to the next step
|
||||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
pStk1->SetState(1); // ready for further
|
||||||
// qui se trouve sur la pile, justement.
|
|
||||||
|
// requires a little more stack to not touch the result of the left
|
||||||
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
|
// which is on the stack, precisely.
|
||||||
// ou le retrouve en cas de reprise
|
|
||||||
|
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
|
||||||
// 2e état, évalue l'opérande de droite
|
// or is found in case of recovery
|
||||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
|
||||||
|
// Second state, evaluates the right operand
|
||||||
int type1 = pStk1->GetType(); // de quels types les résultats ?
|
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here?
|
||||||
int type2 = pStk2->GetType();
|
|
||||||
|
int type1 = pStk1->GetType(); // what kind of results?
|
||||||
// crée une variable temporaire pour y mettre le résultat
|
int type2 = pStk2->GetType();
|
||||||
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
|
|
||||||
|
// creates a temporary variable to put the result
|
||||||
// fait l'opération selon la demande
|
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
|
||||||
switch (GetTokenType())
|
|
||||||
{
|
// is the operation as requested
|
||||||
case ID_ADD:
|
switch (GetTokenType())
|
||||||
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
|
{
|
||||||
break;
|
case ID_ADD:
|
||||||
case ID_SUB:
|
result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition
|
||||||
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
|
break;
|
||||||
break;
|
case ID_SUB:
|
||||||
}
|
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction
|
||||||
pStk2->SetVar(result); // met le résultat sur la pile
|
break;
|
||||||
|
}
|
||||||
pStk1->Return(pStk2); // libère la pile
|
pStk2->SetVar(result); // puts the result on the stack
|
||||||
return pStack->Return(pStk1); // transmet le résultat
|
|
||||||
}
|
pStk1->Return(pStk2); // frees the stack
|
||||||
|
return pStack->Return(pStk1); // transmits the result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,131 +1,133 @@
|
||||||
// * This file is part of the COLOBOT source code
|
// * This file is part of the COLOBOT source code
|
||||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||||
// *
|
// *
|
||||||
// * This program is free software: you can redistribute it and/or modify
|
// * 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
|
// * it under the terms of the GNU General Public License as published by
|
||||||
// * the Free Software Foundation, either version 3 of the License, or
|
// * the Free Software Foundation, either version 3 of the License, or
|
||||||
// * (at your option) any later version.
|
// * (at your option) any later version.
|
||||||
// *
|
// *
|
||||||
// * This program is distributed in the hope that it will be useful,
|
// * This program is distributed in the hope that it will be useful,
|
||||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
// expression du genre Opérande1 > Opérande2
|
|
||||||
// Opérande1 != Opérande2
|
///////////////////////////////////////////////////
|
||||||
// etc.
|
// expression of type Opérande1 > Opérande2
|
||||||
|
// Opérande1 != Opérande2
|
||||||
#include "CBot.h"
|
// etc.
|
||||||
|
|
||||||
// divers constructeurs
|
#include "CBot.h"
|
||||||
|
|
||||||
CBotCompExpr::CBotCompExpr()
|
// various constructeurs
|
||||||
{
|
|
||||||
m_leftop =
|
CBotCompExpr::CBotCompExpr()
|
||||||
m_rightop = NULL;
|
{
|
||||||
name = "CBotCompExpr";
|
m_leftop =
|
||||||
}
|
m_rightop = NULL;
|
||||||
|
name = "CBotCompExpr";
|
||||||
CBotCompExpr::~CBotCompExpr()
|
}
|
||||||
{
|
|
||||||
delete m_leftop;
|
CBotCompExpr::~CBotCompExpr()
|
||||||
delete m_rightop;
|
{
|
||||||
}
|
delete m_leftop;
|
||||||
|
delete m_rightop;
|
||||||
fichier plus utilise;
|
}
|
||||||
|
|
||||||
// compile une instruction de type A < B
|
fichier plus utilise;
|
||||||
|
|
||||||
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
// compile instruction of type A < B
|
||||||
{
|
|
||||||
CBotCStack* pStk = pStack->AddStack();
|
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
|
{
|
||||||
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B à gauche
|
CBotCStack* pStk = pStack->AddStack();
|
||||||
if (left == NULL) return pStack->Return(NULL, pStk); // erreur
|
|
||||||
|
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B left
|
||||||
if ( p->GetType() == ID_HI ||
|
if (left == NULL) return pStack->Return(NULL, pStk); // error
|
||||||
p->GetType() == ID_LO ||
|
|
||||||
p->GetType() == ID_HS ||
|
if ( p->GetType() == ID_HI ||
|
||||||
p->GetType() == ID_LS ||
|
p->GetType() == ID_LO ||
|
||||||
p->GetType() == ID_EQ ||
|
p->GetType() == ID_HS ||
|
||||||
p->GetType() == ID_NE) // les diverses comparaisons
|
p->GetType() == ID_LS ||
|
||||||
{
|
p->GetType() == ID_EQ ||
|
||||||
CBotCompExpr* inst = new CBotCompExpr(); // élément pour opération
|
p->GetType() == ID_NE) // the various comparisons
|
||||||
inst->SetToken(p); // mémorise l'opération
|
{
|
||||||
|
CBotCompExpr* inst = new CBotCompExpr(); // element for operation
|
||||||
int type1, type2;
|
inst->SetToken(p); // stores the operation
|
||||||
type1 = pStack->GetType();
|
|
||||||
|
int type1, type2;
|
||||||
p = p->Next();
|
type1 = pStack->GetType();
|
||||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B à droite
|
|
||||||
{
|
p = p->Next();
|
||||||
type2 = pStack->GetType();
|
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B right
|
||||||
// les résultats sont-ils compatibles
|
{
|
||||||
if ( type1 == type2 )
|
type2 = pStack->GetType();
|
||||||
{
|
// are the results compatible
|
||||||
inst->m_leftop = left;
|
if ( type1 == type2 )
|
||||||
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
|
{
|
||||||
// le résultat est un boolean
|
inst->m_leftop = left;
|
||||||
return pStack->Return(inst, pStk);
|
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
|
||||||
}
|
// the result is a boolean
|
||||||
}
|
return pStack->Return(inst, pStk);
|
||||||
|
}
|
||||||
delete left;
|
}
|
||||||
delete inst;
|
|
||||||
return pStack->Return(NULL, pStk);
|
delete left;
|
||||||
}
|
delete inst;
|
||||||
|
return pStack->Return(NULL, pStk);
|
||||||
return pStack->Return(left, pStk);
|
}
|
||||||
}
|
|
||||||
|
return pStack->Return(left, pStk);
|
||||||
|
}
|
||||||
// fait l'opération
|
|
||||||
|
|
||||||
bool CBotCompExpr::Execute(CBotStack* &pStack)
|
// perform the operation
|
||||||
{
|
|
||||||
CBotStack* pStk1 = pStack->AddStack(this);
|
bool CBotCompExpr::Execute(CBotStack* &pStack)
|
||||||
// if ( pStk1 == EOX ) return TRUE;
|
{
|
||||||
|
CBotStack* pStk1 = pStack->AddStack(this);
|
||||||
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
// if ( pStk1 == EOX ) return TRUE;
|
||||||
|
|
||||||
pStk1->SetState(1); // opération terminée
|
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here ?
|
||||||
|
|
||||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
pStk1->SetState(1); // finished
|
||||||
CBotStack* pStk2 = pStk1->AddStack();
|
|
||||||
|
// requires a little more stack to not touch the result of the left
|
||||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
CBotStack* pStk2 = pStk1->AddStack();
|
||||||
|
|
||||||
int type1 = pStk1->GetType();
|
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ?
|
||||||
int type2 = pStk2->GetType();
|
|
||||||
|
int type1 = pStk1->GetType();
|
||||||
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
|
int type2 = pStk2->GetType();
|
||||||
|
|
||||||
switch (GetTokenType())
|
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
|
||||||
{
|
|
||||||
case ID_LO:
|
switch (GetTokenType())
|
||||||
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // inférieur
|
{
|
||||||
break;
|
case ID_LO:
|
||||||
case ID_HI:
|
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower
|
||||||
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // supérieur
|
break;
|
||||||
break;
|
case ID_HI:
|
||||||
case ID_LS:
|
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher
|
||||||
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // inférieur ou égal
|
break;
|
||||||
break;
|
case ID_LS:
|
||||||
case ID_HS:
|
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal
|
||||||
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // supérieur ou égal
|
break;
|
||||||
break;
|
case ID_HS:
|
||||||
case ID_EQ:
|
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal
|
||||||
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // égal
|
break;
|
||||||
break;
|
case ID_EQ:
|
||||||
case ID_NE:
|
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal
|
||||||
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // différent
|
break;
|
||||||
break;
|
case ID_NE:
|
||||||
}
|
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal
|
||||||
pStk2->SetVar(result); // met le résultat sur la pile
|
break;
|
||||||
|
}
|
||||||
pStk1->Return(pStk2); // libère la pile
|
pStk2->SetVar(result); // puts the result on the stack
|
||||||
return pStack->Return(pStk1); // transmet le résultat
|
|
||||||
}
|
pStk1->Return(pStk2); // frees the stack
|
||||||
|
return pStack->Return(pStk1); // transmit the result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
2234
src/CBot/CBotDll.h
2234
src/CBot/CBotDll.h
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -12,7 +12,8 @@
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/./////////////////////////////////////////////////////
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
//strings management
|
//strings management
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
// x
|
// x
|
||||||
// )
|
// )
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
|
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
|
||||||
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);
|
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -65,10 +65,10 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
||||||
CBotString mode;
|
CBotString mode;
|
||||||
|
|
||||||
// accepts no parameters
|
// accepts no parameters
|
||||||
if ( pVar == NULL ) return TRUE;
|
if ( pVar == NULL ) return true;
|
||||||
|
|
||||||
// must be a string
|
// must be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||||
|
|
||||||
CBotString filename = pVar->GivValString();
|
CBotString filename = pVar->GivValString();
|
||||||
PrepareFilename(filename); //DR
|
PrepareFilename(filename); //DR
|
||||||
|
@ -79,10 +79,10 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
||||||
{
|
{
|
||||||
// recovers the mode
|
// recovers the mode
|
||||||
mode = pVar->GivValString();
|
mode = pVar->GivValString();
|
||||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
|
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
|
||||||
|
|
||||||
// no third parameter, only two or one possible
|
// no third parameter, only two or one possible
|
||||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the file name
|
// save the file name
|
||||||
|
@ -93,7 +93,7 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
||||||
{
|
{
|
||||||
// open the called file
|
// open the called file
|
||||||
FILE* pFile = fopen( filename, mode );
|
FILE* pFile = fopen( filename, mode );
|
||||||
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return FALSE; }
|
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return false; }
|
||||||
|
|
||||||
m_CompteurFileOpen ++;
|
m_CompteurFileOpen ++;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
||||||
pVar->SetValInt((long)pFile);
|
pVar->SetValInt((long)pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -126,7 +126,7 @@ CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||||
}
|
}
|
||||||
|
|
||||||
// le résultat est de type void (constructeur)
|
// le r<EFBFBD>sultat est de type void (constructeur)
|
||||||
return CBotTypResult( 0 );
|
return CBotTypResult( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
// not open? no problem
|
// not open? no problem
|
||||||
if ( pVar->GivInit() != IS_DEF) return TRUE;
|
if ( pVar->GivInit() != IS_DEF) return true;
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
|
@ -148,7 +148,7 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
||||||
|
|
||||||
pVar->SetInit(IS_NAN);
|
pVar->SetInit(IS_NAN);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,10 +159,10 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
||||||
bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
{
|
{
|
||||||
// there must be a parameter
|
// there must be a parameter
|
||||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
|
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
|
||||||
|
|
||||||
// must be a string
|
// must be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||||
|
|
||||||
// there may be a second parameter
|
// there may be a second parameter
|
||||||
if ( pVar->GivNext() != NULL )
|
if ( pVar->GivNext() != NULL )
|
||||||
|
@ -180,16 +180,16 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotString mode = pVar->GivValString();
|
CBotString mode = pVar->GivValString();
|
||||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
|
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
|
||||||
|
|
||||||
// No third parameter
|
// No third parameter
|
||||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||||
|
|
||||||
// retrieves the element "handle"
|
// retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
// which must not be initialized
|
// which must not be initialized
|
||||||
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return FALSE; }
|
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return false; }
|
||||||
|
|
||||||
// contains filename
|
// contains filename
|
||||||
pVar = pThis->GivItem("filename");
|
pVar = pThis->GivItem("filename");
|
||||||
|
@ -201,8 +201,8 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
FILE* pFile = fopen( filename, mode );
|
FILE* pFile = fopen( filename, mode );
|
||||||
if ( pFile == NULL ) //DR
|
if ( pFile == NULL ) //DR
|
||||||
{
|
{
|
||||||
pResult->SetValInt(FALSE); //DR
|
pResult->SetValInt(false); //DR
|
||||||
return TRUE; //DR
|
return true; //DR
|
||||||
}
|
}
|
||||||
|
|
||||||
m_CompteurFileOpen ++;
|
m_CompteurFileOpen ++;
|
||||||
|
@ -211,8 +211,8 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
pVar->SetValInt((long)pFile);
|
pVar->SetValInt((long)pFile);
|
||||||
|
|
||||||
pResult->SetValInt(TRUE); //DR
|
pResult->SetValInt(true); //DR
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -253,7 +253,7 @@ bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
// retrieves the element "handle"
|
// retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
|
@ -261,7 +261,7 @@ bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
|
|
||||||
pVar->SetInit(IS_NAN);
|
pVar->SetInit(IS_NAN);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -280,26 +280,26 @@ CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
|
||||||
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
{
|
{
|
||||||
// there must be a parameter
|
// there must be a parameter
|
||||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
|
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
|
||||||
|
|
||||||
// must be a string
|
// must be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||||
|
|
||||||
CBotString param = pVar->GivValString();
|
CBotString param = pVar->GivValString();
|
||||||
|
|
||||||
//retrieves the element "handle"
|
//retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
|
|
||||||
int res = fputs(param+CBotString("\n"), pFile);
|
int res = fputs(param+CBotString("\n"), pFile);
|
||||||
|
|
||||||
// on error throws an exception
|
// on error throws an exception
|
||||||
if ( res < 0 ) { Exception = CBotErrWrite; return FALSE; }
|
if ( res < 0 ) { Exception = CBotErrWrite; return false; }
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -324,12 +324,12 @@ CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
|
||||||
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
{
|
{
|
||||||
// there shouldn't be any parameter
|
// there shouldn't be any parameter
|
||||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||||
|
|
||||||
//retrieves the element "handle"
|
//retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
|
|
||||||
|
@ -342,11 +342,11 @@ bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0;
|
for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0;
|
||||||
|
|
||||||
// on error throws an exception
|
// on error throws an exception
|
||||||
if ( ferror(pFile) ) { Exception = CBotErrRead; return FALSE; }
|
if ( ferror(pFile) ) { Exception = CBotErrRead; return false; }
|
||||||
|
|
||||||
pResult->SetValString( chaine );
|
pResult->SetValString( chaine );
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -365,18 +365,18 @@ CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
|
||||||
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
{
|
{
|
||||||
// there shouldn't be any parameter
|
// there shouldn't be any parameter
|
||||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||||
|
|
||||||
// retrieves the element "handle"
|
// retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
|
|
||||||
pResult->SetValInt( feof( pFile ) );
|
pResult->SetValInt( feof( pFile ) );
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
|
|
@ -1,434 +1,436 @@
|
||||||
// * This file is part of the COLOBOT source code
|
// * This file is part of the COLOBOT source code
|
||||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||||
// *
|
// *
|
||||||
// * This program is free software: you can redistribute it and/or modify
|
// * 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
|
// * it under the terms of the GNU General Public License as published by
|
||||||
// * the Free Software Foundation, either version 3 of the License, or
|
// * the Free Software Foundation, either version 3 of the License, or
|
||||||
// * (at your option) any later version.
|
// * (at your option) any later version.
|
||||||
// *
|
// *
|
||||||
// * This program is distributed in the hope that it will be useful,
|
// * This program is distributed in the hope that it will be useful,
|
||||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.// définition des fonctions sur les chaînes
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
|
|
||||||
|
// definition of string functions
|
||||||
// donne la longueur d'une chaîne
|
|
||||||
// exécution
|
|
||||||
|
// gives the length of a chain
|
||||||
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
// execution
|
||||||
{
|
|
||||||
// il faut un paramètre
|
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// pas de second paramètre
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
|
||||||
|
// no second parameter
|
||||||
// recupére le contenu de la string
|
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||||
CBotString s = pVar->GivValString();
|
|
||||||
|
// get the contents of the string
|
||||||
// met la longueur sur la pile
|
CBotString s = pVar->GivValString();
|
||||||
pResult->SetValInt( s.GivLength() );
|
|
||||||
return true;
|
// puts the length of the stack
|
||||||
}
|
pResult->SetValInt( s.GivLength() );
|
||||||
|
return true;
|
||||||
// int xxx ( string )
|
}
|
||||||
// compilation
|
|
||||||
|
// int xxx ( string )
|
||||||
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
|
// compilation
|
||||||
{
|
|
||||||
// il faut un paramètre
|
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() != CBotTypString )
|
|
||||||
return CBotTypResult( TX_BADPARAM );
|
// to be a string
|
||||||
|
if ( pVar->GivType() != CBotTypString )
|
||||||
// pas de second paramètre
|
return CBotTypResult( TX_BADPARAM );
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
|
||||||
|
// no second parameter
|
||||||
// le résultat final est un nombre entier
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
return CBotTypResult( CBotTypInt );
|
|
||||||
}
|
// the end result is an integer
|
||||||
|
return CBotTypResult( CBotTypInt );
|
||||||
|
}
|
||||||
// donne la partie gauche d'une chaîne
|
|
||||||
// exécution
|
|
||||||
|
// gives the left side of a chain
|
||||||
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
// execution
|
||||||
{
|
|
||||||
// il faut un paramètre
|
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// recupére le contenu de la string
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
CBotString s = pVar->GivValString();
|
|
||||||
|
// get the contents of the string
|
||||||
// il faut un second paramètre
|
CBotString s = pVar->GivValString();
|
||||||
pVar = pVar->GivNext();
|
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
// it takes a second parameter
|
||||||
|
pVar = pVar->GivNext();
|
||||||
// qui doit être un nombre
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
|
||||||
|
// which must be a number
|
||||||
// récupère ce nombre
|
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||||
int n = pVar->GivValInt();
|
|
||||||
|
// retrieves this number
|
||||||
// pas de 3e paramètre
|
int n = pVar->GivValInt();
|
||||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
|
||||||
|
// no third parameter
|
||||||
// prend la partie intéressante
|
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||||
s = s.Left( n );
|
|
||||||
|
// takes the interesting part
|
||||||
// la met sur la pile
|
s = s.Left( n );
|
||||||
pResult->SetValString( s );
|
|
||||||
return true;
|
// puts on the stack
|
||||||
}
|
pResult->SetValString( s );
|
||||||
|
return true;
|
||||||
// string xxx ( string, int )
|
}
|
||||||
// compilation
|
|
||||||
|
// string xxx ( string, int )
|
||||||
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
|
// compilation
|
||||||
{
|
|
||||||
// il faut un paramètre
|
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() != CBotTypString )
|
|
||||||
return CBotTypResult( TX_BADSTRING );
|
// to be a string
|
||||||
|
if ( pVar->GivType() != CBotTypString )
|
||||||
// il faut un second paramètre
|
return CBotTypResult( TX_BADSTRING );
|
||||||
pVar = pVar->GivNext();
|
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
// it takes a second parameter
|
||||||
|
pVar = pVar->GivNext();
|
||||||
// qui doit être un nombre
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() > CBotTypDouble )
|
|
||||||
return CBotTypResult( TX_BADNUM );
|
// which must be a number
|
||||||
|
if ( pVar->GivType() > CBotTypDouble )
|
||||||
// pas de 3e paramètre
|
return CBotTypResult( TX_BADNUM );
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
|
||||||
|
// no third parameter
|
||||||
// le résultat final est une string
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
return CBotTypResult( CBotTypString );
|
|
||||||
}
|
// the end result is a string
|
||||||
|
return CBotTypResult( CBotTypString );
|
||||||
// donne la partie droite d'une chaîne
|
}
|
||||||
// exécution
|
|
||||||
|
// gives the right of a string
|
||||||
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
// execution
|
||||||
{
|
|
||||||
// il faut un paramètre
|
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// recupére le contenu de la string
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
CBotString s = pVar->GivValString();
|
|
||||||
|
// get the contents of the string
|
||||||
// il faut un second paramètre
|
CBotString s = pVar->GivValString();
|
||||||
pVar = pVar->GivNext();
|
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
// it takes a second parameter
|
||||||
|
pVar = pVar->GivNext();
|
||||||
// qui doit être un nombre
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
|
||||||
|
// which must be a number
|
||||||
// récupère ce nombre
|
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||||
int n = pVar->GivValInt();
|
|
||||||
|
// retrieves this number
|
||||||
// pas de 3e paramètre
|
int n = pVar->GivValInt();
|
||||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
|
||||||
|
// no third parameter
|
||||||
// prend la partie intéressante
|
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||||
s = s.Right( n );
|
|
||||||
|
// takes the interesting part
|
||||||
// la met sur la pile
|
s = s.Right( n );
|
||||||
pResult->SetValString( s );
|
|
||||||
return true;
|
// puts on the stack
|
||||||
}
|
pResult->SetValString( s );
|
||||||
|
return true;
|
||||||
// donne la partie centrale d'une chaîne
|
}
|
||||||
// exécution
|
|
||||||
|
// gives the central part of a chain
|
||||||
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
// execution
|
||||||
{
|
|
||||||
// il faut un paramètre
|
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// recupére le contenu de la string
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
CBotString s = pVar->GivValString();
|
|
||||||
|
// get the contents of the string
|
||||||
// il faut un second paramètre
|
CBotString s = pVar->GivValString();
|
||||||
pVar = pVar->GivNext();
|
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
// it takes a second parameter
|
||||||
|
pVar = pVar->GivNext();
|
||||||
// qui doit être un nombre
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
|
||||||
|
// which must be a number
|
||||||
// récupère ce nombre
|
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||||
int n = pVar->GivValInt();
|
|
||||||
|
// retrieves this number
|
||||||
// 3e paramètre optionnel
|
int n = pVar->GivValInt();
|
||||||
if ( pVar->GivNext() != NULL )
|
|
||||||
{
|
// third parameter optional
|
||||||
pVar = pVar->GivNext();
|
if ( pVar->GivNext() != NULL )
|
||||||
|
{
|
||||||
// qui doit être un nombre
|
pVar = pVar->GivNext();
|
||||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
|
||||||
|
// which must be a number
|
||||||
// récupère ce nombre
|
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||||
int l = pVar->GivValInt();
|
|
||||||
|
// retrieves this number
|
||||||
// mais pas de 4e paramètre
|
int l = pVar->GivValInt();
|
||||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
|
||||||
|
// but no fourth parameter
|
||||||
// prend la partie intéressante
|
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||||
s = s.Mid( n, l );
|
|
||||||
}
|
// takes the interesting part
|
||||||
else
|
s = s.Mid( n, l );
|
||||||
{
|
}
|
||||||
// prend la partie intéressante
|
else
|
||||||
s = s.Mid( n );
|
{
|
||||||
}
|
// takes the interesting part
|
||||||
|
s = s.Mid( n );
|
||||||
// la met sur la pile
|
}
|
||||||
pResult->SetValString( s );
|
|
||||||
return true;
|
// puts on the stack
|
||||||
}
|
pResult->SetValString( s );
|
||||||
|
return true;
|
||||||
// donne la partie centrale d'une chaîne
|
}
|
||||||
// compilation
|
|
||||||
|
// gives the central part of a chain
|
||||||
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
|
// compilation
|
||||||
{
|
|
||||||
// il faut un paramètre
|
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() != CBotTypString )
|
|
||||||
return CBotTypResult( TX_BADSTRING );
|
// to be a string
|
||||||
|
if ( pVar->GivType() != CBotTypString )
|
||||||
// il faut un second paramètre
|
return CBotTypResult( TX_BADSTRING );
|
||||||
pVar = pVar->GivNext();
|
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
// it takes a second parameter
|
||||||
|
pVar = pVar->GivNext();
|
||||||
// qui doit être un nombre
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() > CBotTypDouble )
|
|
||||||
return CBotTypResult( TX_BADNUM );
|
// which must be a number
|
||||||
|
if ( pVar->GivType() > CBotTypDouble )
|
||||||
// 3e paramètre optionnel
|
return CBotTypResult( TX_BADNUM );
|
||||||
if ( pVar->GivNext() != NULL )
|
|
||||||
{
|
// third parameter optional
|
||||||
|
if ( pVar->GivNext() != NULL )
|
||||||
pVar = pVar->GivNext();
|
{
|
||||||
// qui doit être un nombre
|
|
||||||
if ( pVar->GivType() > CBotTypDouble )
|
pVar = pVar->GivNext();
|
||||||
return CBotTypResult( TX_BADNUM );
|
// which must be a number
|
||||||
|
if ( pVar->GivType() > CBotTypDouble )
|
||||||
// pas de 4e paramètre
|
return CBotTypResult( TX_BADNUM );
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
|
||||||
}
|
// no fourth parameter
|
||||||
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
// le résultat final est une string
|
}
|
||||||
return CBotTypResult( CBotTypString );
|
|
||||||
}
|
// the end result is a string
|
||||||
|
return CBotTypResult( CBotTypString );
|
||||||
|
}
|
||||||
// donne le nombre contenu dans une chaîne
|
|
||||||
// exécution
|
|
||||||
|
// gives the number stored in a string
|
||||||
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
// execution
|
||||||
{
|
|
||||||
// il faut un paramètre
|
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// recupére le contenu de la string
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
CBotString s = pVar->GivValString();
|
|
||||||
|
// get the contents of the string
|
||||||
// mais pas de 2e paramètre
|
CBotString s = pVar->GivValString();
|
||||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
|
||||||
|
// but no second parameter
|
||||||
float val = GivNumFloat(s);
|
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
// la met la valeur sur la pile
|
float val = GivNumFloat(s);
|
||||||
pResult->SetValFloat( val );
|
|
||||||
return true;
|
// puts the value on the stack
|
||||||
}
|
pResult->SetValFloat( val );
|
||||||
|
return true;
|
||||||
// float xxx ( string )
|
}
|
||||||
// compilation
|
|
||||||
|
// float xxx ( string )
|
||||||
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
|
// compilation
|
||||||
{
|
|
||||||
// il faut un paramètre
|
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() != CBotTypString )
|
|
||||||
return CBotTypResult( TX_BADSTRING );
|
// to be a string
|
||||||
|
if ( pVar->GivType() != CBotTypString )
|
||||||
// pas de 2e paramètre
|
return CBotTypResult( TX_BADSTRING );
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
|
||||||
|
// no second parameter
|
||||||
// le résultat final est un nombre
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
return CBotTypResult( CBotTypFloat );
|
|
||||||
}
|
// the end result is a number
|
||||||
|
return CBotTypResult( CBotTypFloat );
|
||||||
|
}
|
||||||
// trouve une chaine dans une autre
|
|
||||||
// exécution
|
|
||||||
|
// find string in other
|
||||||
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
// exécution
|
||||||
{
|
|
||||||
// il faut un paramètre
|
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// recupére le contenu de la string
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
CBotString s = pVar->GivValString();
|
|
||||||
|
// get the contents of the string
|
||||||
// il faut un second paramètre
|
CBotString s = pVar->GivValString();
|
||||||
pVar = pVar->GivNext();
|
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
// it takes a second parameter
|
||||||
|
pVar = pVar->GivNext();
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// récupère ce nombre
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
CBotString s2 = pVar->GivValString();
|
|
||||||
|
// retrieves this number
|
||||||
// pas de 3e paramètre
|
CBotString s2 = pVar->GivValString();
|
||||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
|
||||||
|
// no third parameter
|
||||||
// met le résultat sur la pile
|
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||||
int res = s.Find(s2);
|
|
||||||
pResult->SetValInt( res );
|
// puts the result on the stack
|
||||||
if ( res < 0 ) pResult->SetInit( IS_NAN );
|
int res = s.Find(s2);
|
||||||
return true;
|
pResult->SetValInt( res );
|
||||||
}
|
if ( res < 0 ) pResult->SetInit( IS_NAN );
|
||||||
|
return true;
|
||||||
// int xxx ( string, string )
|
}
|
||||||
// compilation
|
|
||||||
|
// int xxx ( string, string )
|
||||||
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
|
// compilation
|
||||||
{
|
|
||||||
// il faut un paramètre
|
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() != CBotTypString )
|
|
||||||
return CBotTypResult( TX_BADSTRING );
|
// to be a string
|
||||||
|
if ( pVar->GivType() != CBotTypString )
|
||||||
// il faut un second paramètre
|
return CBotTypResult( TX_BADSTRING );
|
||||||
pVar = pVar->GivNext();
|
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
// it takes a second parameter
|
||||||
|
pVar = pVar->GivNext();
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() != CBotTypString )
|
|
||||||
return CBotTypResult( TX_BADSTRING );
|
// to be a string
|
||||||
|
if ( pVar->GivType() != CBotTypString )
|
||||||
// pas de 3e paramètre
|
return CBotTypResult( TX_BADSTRING );
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
|
||||||
|
// no third parameter
|
||||||
// le résultat final est un nombre
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
return CBotTypResult( CBotTypInt );
|
|
||||||
}
|
// the end result is a number
|
||||||
|
return CBotTypResult( CBotTypInt );
|
||||||
// donne une chaine en majuscule
|
}
|
||||||
// exécution
|
|
||||||
|
// gives a string to uppercase
|
||||||
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
// exécution
|
||||||
{
|
|
||||||
// il faut un paramètre
|
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// recupére le contenu de la string
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
CBotString s = pVar->GivValString();
|
|
||||||
|
// get the contents of the string
|
||||||
// mais pas de 2e paramètre
|
CBotString s = pVar->GivValString();
|
||||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
|
||||||
|
// but no second parameter
|
||||||
|
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||||
s.MakeUpper();
|
|
||||||
|
|
||||||
// la met la valeur sur la pile
|
s.MakeUpper();
|
||||||
pResult->SetValString( s );
|
|
||||||
return true;
|
// puts the value on the stack
|
||||||
}
|
pResult->SetValString( s );
|
||||||
|
return true;
|
||||||
// donne une chaine en minuscules
|
}
|
||||||
// exécution
|
|
||||||
|
// gives a string to lowercase
|
||||||
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
// exécution
|
||||||
{
|
|
||||||
// il faut un paramètre
|
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
|
||||||
|
// to be a string
|
||||||
// recupére le contenu de la string
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
CBotString s = pVar->GivValString();
|
|
||||||
|
// get the contents of the string
|
||||||
// mais pas de 2e paramètre
|
CBotString s = pVar->GivValString();
|
||||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
|
||||||
|
// but no second parameter
|
||||||
|
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||||
s.MakeLower();
|
|
||||||
|
|
||||||
// la met la valeur sur la pile
|
s.MakeLower();
|
||||||
pResult->SetValString( s );
|
|
||||||
return true;
|
// puts the value on the stack
|
||||||
}
|
pResult->SetValString( s );
|
||||||
|
return true;
|
||||||
// string xxx ( string )
|
}
|
||||||
// compilation
|
|
||||||
|
// string xxx ( string )
|
||||||
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
|
// compilation
|
||||||
{
|
|
||||||
// il faut un paramètre
|
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
{
|
||||||
|
// it takes a parameter
|
||||||
// qui doit être une string
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
if ( pVar->GivType() != CBotTypString )
|
|
||||||
return CBotTypResult( TX_BADSTRING );
|
// to be a string
|
||||||
|
if ( pVar->GivType() != CBotTypString )
|
||||||
// pas de 2e paramètre
|
return CBotTypResult( TX_BADSTRING );
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
|
||||||
|
// no second parameter
|
||||||
// le résultat final est une string
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
return CBotTypResult( CBotTypString );
|
|
||||||
}
|
// the end result is a string
|
||||||
|
return CBotTypResult( CBotTypString );
|
||||||
|
}
|
||||||
void InitStringFunctions()
|
|
||||||
{
|
|
||||||
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
|
void InitStringFunctions()
|
||||||
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
|
{
|
||||||
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
|
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
|
||||||
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
|
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
|
||||||
|
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
|
||||||
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
|
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
|
||||||
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
|
|
||||||
|
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
|
||||||
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
|
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
|
||||||
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
|
|
||||||
}
|
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
|
||||||
|
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue