src/ai/squirrel/squirrel.cpp
branchnoai
changeset 9387 4255a0a2d272
parent 9386 c8aa2ae117f5
child 9393 04bd925b9069
equal deleted inserted replaced
9386:c8aa2ae117f5 9387:4255a0a2d272
     5 #include "squirrel.hpp"
     5 #include "squirrel.hpp"
     6 #include <sqstdio.h>
     6 #include <sqstdio.h>
     7 #include <sqstdaux.h>
     7 #include <sqstdaux.h>
     8 #include <stdarg.h>
     8 #include <stdarg.h>
     9 #include "../../debug.h"
     9 #include "../../debug.h"
       
    10 
       
    11 #define SQUIRREL_CLASS
       
    12 #include "convert.hpp"
       
    13 #include "squirrel_class.hpp"
       
    14 #include "../core/ai_base.hpp"
       
    15 #include "../core/ai_company.hpp"
       
    16 #include "../core/ai_map.hpp"
       
    17 #include "../core/ai_town.hpp"
    10 
    18 
    11 /**
    19 /**
    12  * Here we handle errors that come from squirrel.
    20  * Here we handle errors that come from squirrel.
    13  */
    21  */
    14 static void Squirrel_CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
    22 static void Squirrel_CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
    61 	return SQ_ERROR;
    69 	return SQ_ERROR;
    62 }
    70 }
    63 
    71 
    64 SQInteger Squirrel::SQGetTick(HSQUIRRELVM vm)
    72 SQInteger Squirrel::SQGetTick(HSQUIRRELVM vm)
    65 {
    73 {
    66 	Squirrel *self;
    74 	SQUserPointer ptr;
    67 
    75 
    68 	/* Find the 'self' pointer */
    76 	/* Find the 'self' pointer */
    69 	if (SQ_FAILED(sq_getinstanceup(vm, 1, (SQUserPointer *)&self, 0))) {
    77 	if (SQ_FAILED(sq_getinstanceup(vm, 1, &ptr, 0))) {
    70 		DEBUG(ai, 0, "[squirrel] Failed to find the instance-pointer");
    78 		DEBUG(ai, 0, "[squirrel] Failed to find the instance-pointer");
    71 		return SQ_ERROR;
    79 		return SQ_ERROR;
    72 	}
    80 	}
    73 
    81 
    74 	/* Return the value */
    82 	/* Return the value */
    75 	sq_pushinteger(vm, self->GetTick());
    83 	sq_pushinteger(vm, ((Squirrel *)ptr)->GetTick());
    76 	return 1;
    84 	return 1;
    77 }
    85 }
    78 
    86 
    79 bool Squirrel::SQCreateClass(const char *classname)
    87 bool Squirrel::SQCreateClass(const char *classname)
    80 {
    88 {
   171 	sq_createslot(this->vm, -3);
   179 	sq_createslot(this->vm, -3);
   172 
   180 
   173 	/* Register the 'RegisterAI()' function */
   181 	/* Register the 'RegisterAI()' function */
   174 	sq_pushroottable(this->vm);
   182 	sq_pushroottable(this->vm);
   175 	this->SQAddMethod("RegisterAI", &Squirrel::SQRegisterAI, 2, "ts");
   183 	this->SQAddMethod("RegisterAI", &Squirrel::SQRegisterAI, 2, "ts");
       
   184 
       
   185 	SQAIBaseRegister(this->vm);
       
   186 	SQAICompanyRegister(this->vm);
       
   187 	SQAIMapRegister(this->vm);
       
   188 	SQAITownRegister(this->vm);
   176 
   189 
   177 	/* Reset top */
   190 	/* Reset top */
   178 	sq_settop(this->vm, top);
   191 	sq_settop(this->vm, top);
   179 }
   192 }
   180 
   193