void vm_sleep(const ScriptArguments& args) { args.getThread()->wakeCounter = args[0].integerValue(); if( args.getThread()->wakeCounter == 0 ) { args.getThread()->wakeCounter = -1; } }
void vm_if(const ScriptArguments& args) { auto n = args[0].integer; if( n <= 7 ) { args.getThread()->conditionCount = n+1; args.getThread()->conditionMask = 0xFF; args.getThread()->conditionAND = true; } else { args.getThread()->conditionCount = n-19; args.getThread()->conditionMask = 0x00; args.getThread()->conditionAND = false; } }
void game_create_vehicle(const ScriptArguments& args) { auto id = args[0].integer; glm::vec3 position(args[1].real, args[2].real, args[3].real); if( position.z < -99.f ) { position = args.getWorld()->getGroundAtPosition(position); } position += spawnMagic; auto vehicle = args.getWorld()->createVehicle(id, position); if ( args.getThread()->isMission ) { args.getState()->missionObjects.push_back(vehicle->getGameObjectID()); } *args[4].globalInteger = vehicle->getGameObjectID(); }
void game_create_character(const ScriptArguments& args) { auto type = args[0].integer; auto id = args[1].integer; glm::vec3 position(args[2].real, args[3].real, args[4].real); if( type == 21 ) { } if( position.z < -99.f ) { position = args.getWorld()->getGroundAtPosition(position); } auto character = args.getWorld()->createPedestrian(id, position + spawnMagic); /* Controller will give ownership to character */ new DefaultAIController(character); if ( args.getThread()->isMission ) { args.getState()->missionObjects.push_back(character->getGameObjectID()); } *args[5].globalInteger = character->getGameObjectID(); }
void vm_global_int_eq_int(const ScriptArguments& args) { args.getThread()->conditionResult = *args[0].globalInteger == args[1].integerValue(); }
void vm_global_int_ge_int(const ScriptArguments& args) { args.getThread()->conditionResult = *args[0].globalInteger >= args[1].integer; }
void vm_global_float_gt_float(const ScriptArguments& args) { args.getThread()->conditionResult = *args[0].globalReal > args[1].real; }
void vm_name_thread(const ScriptArguments& args) { strncpy(args.getThread()->name, args[0].string, 16); }
void vm_jump(const ScriptArguments& args) { args.getThread()->programCounter = localizeLabel(args.getThread(), args[0].integer); }
void vm_return(const ScriptArguments& args) { args.getThread()->programCounter = args.getThread()->calls[--args.getThread()->stackDepth]; }
void vm_call(const ScriptArguments& args) { args.getThread()->calls[args.getThread()->stackDepth++] = args.getThread()->programCounter; args.getThread()->programCounter = localizeLabel(args.getThread(), args[0].integer); }
void vm_halt_thread(const ScriptArguments& args) { // ensure the thread is immediately yeilded args.getThread()->wakeCounter = -1; args.getThread()->finished = true; }
void vm_jump_if_false(const ScriptArguments& args) { if( ! args.getThread()->conditionResult ) { args.getThread()->programCounter = localizeLabel(args.getThread(), args[0].integer); } }