static */
| 283 | } |
| 284 | |
| 285 | /* static */ bool ScriptObject::DoCommandProcessResult(const CommandCost &res, Script_SuspendCallbackProc *callback, bool estimate_only, bool asynchronous) |
| 286 | { |
| 287 | /* Set the default callback to return a true/false result of the DoCommand */ |
| 288 | if (callback == nullptr) callback = &ScriptInstance::DoCommandReturn; |
| 289 | |
| 290 | /* We failed; set the error and bail out */ |
| 291 | if (res.Failed()) { |
| 292 | SetLastError(ScriptError::StringToError(res.GetErrorMessage())); |
| 293 | return false; |
| 294 | } |
| 295 | |
| 296 | /* No error, then clear it. */ |
| 297 | SetLastError(ScriptError::ERR_NONE); |
| 298 | |
| 299 | /* Estimates, update the cost for the estimate and be done */ |
| 300 | if (estimate_only) { |
| 301 | IncreaseDoCommandCosts(res.GetCost()); |
| 302 | return true; |
| 303 | } |
| 304 | |
| 305 | /* Costs of this operation. */ |
| 306 | SetLastCost(res.GetCost()); |
| 307 | SetLastCommandRes(true); |
| 308 | |
| 309 | if (_generating_world || asynchronous) { |
| 310 | IncreaseDoCommandCosts(res.GetCost()); |
| 311 | if (!_generating_world) { |
| 312 | /* Charge a nominal fee for asynchronously executed commands */ |
| 313 | Squirrel &engine = *ScriptObject::GetActiveInstance().engine; |
| 314 | Squirrel::DecreaseOps(engine.GetVM(), 100); |
| 315 | } |
| 316 | if (callback != nullptr) { |
| 317 | /* Insert return value into to stack and throw a control code that |
| 318 | * the return value in the stack should be used. */ |
| 319 | callback(GetActiveInstance()); |
| 320 | throw SQInteger(1); |
| 321 | } |
| 322 | return true; |
| 323 | } else if (_networking) { |
| 324 | /* Suspend the script till the command is really executed. */ |
| 325 | throw Script_Suspend(-(int)GetDoCommandDelay(), callback); |
| 326 | } else { |
| 327 | IncreaseDoCommandCosts(res.GetCost()); |
| 328 | |
| 329 | /* Suspend the script player for 1+ ticks, so it simulates multiplayer. This |
| 330 | * both avoids confusion when a developer launched the script in a |
| 331 | * multiplayer game, but also gives time for the GUI and human player |
| 332 | * to interact with the game. */ |
| 333 | throw Script_Suspend(GetDoCommandDelay(), callback); |
| 334 | } |
| 335 | |
| 336 | NOT_REACHED(); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | /* static */ ScriptObject::RandomizerArray ScriptObject::random_states; |
nothing calls this directly
no test coverage detected