mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r17564) [0.7] -Backport from trunk:
- Fix: Vehicles waiting for their time table did not load anymore after their initial load was completed [FS#3201] (r17551) - Fix: Aircraft were given an unfair advantage in station rating calculations (r17550) - Fix: [NewGRF] Sign extending of profit calculation did not work (r17546) - Fix: [NoAI] AIs had 'infinite' time when running code from the global scope [FS#3202] (r17545) - Fix: [NoAI] Crash when doing commands in the 'global' scope [FS#3202] (r17544)
This commit is contained in:
parent
a6251ba1a5
commit
803e452fab
|
@ -122,21 +122,31 @@ AIInstance::AIInstance(AIInfo *info) :
|
||||||
/* Register the API functions and classes */
|
/* Register the API functions and classes */
|
||||||
this->RegisterAPI();
|
this->RegisterAPI();
|
||||||
|
|
||||||
/* Load and execute the script for this AI */
|
try {
|
||||||
const char *main_script = info->GetMainScript();
|
AIObject::SetAllowDoCommand(false);
|
||||||
if (strcmp(main_script, "%_dummy") == 0) {
|
/* Load and execute the script for this AI */
|
||||||
extern void AI_CreateAIDummy(HSQUIRRELVM vm);
|
const char *main_script = info->GetMainScript();
|
||||||
AI_CreateAIDummy(this->engine->GetVM());
|
if (strcmp(main_script, "%_dummy") == 0) {
|
||||||
} else if (!this->engine->LoadScript(main_script)) {
|
extern void AI_CreateAIDummy(HSQUIRRELVM vm);
|
||||||
this->Died();
|
AI_CreateAIDummy(this->engine->GetVM());
|
||||||
return;
|
} else if (!this->engine->LoadScript(main_script) || this->engine->IsSuspended()) {
|
||||||
}
|
if (this->engine->IsSuspended()) AILog::Error("This AI took too long to load script. AI is not started.");
|
||||||
|
this->Died();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the main-class */
|
/* Create the main-class */
|
||||||
this->instance = MallocT<SQObject>(1);
|
this->instance = MallocT<SQObject>(1);
|
||||||
if (!this->engine->CreateClassInstance(info->GetInstanceName(), this->controller, this->instance)) {
|
if (!this->engine->CreateClassInstance(info->GetInstanceName(), this->controller, this->instance)) {
|
||||||
|
this->Died();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AIObject::SetAllowDoCommand(true);
|
||||||
|
} catch (AI_FatalError e) {
|
||||||
|
this->is_dead = true;
|
||||||
|
this->engine->ThrowError(e.GetErrorMessage());
|
||||||
|
this->engine->ResumeError();
|
||||||
this->Died();
|
this->Died();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1153,7 +1153,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C
|
||||||
int result = GB(callback, 0, 14);
|
int result = GB(callback, 0, 14);
|
||||||
|
|
||||||
/* Simulate a 15 bit signed value */
|
/* Simulate a 15 bit signed value */
|
||||||
if (HasBit(callback, 14)) result = 0x4000 - result;
|
if (HasBit(callback, 14)) result -= 0x4000;
|
||||||
|
|
||||||
/* "The result should be a signed multiplier that gets multiplied
|
/* "The result should be a signed multiplier that gets multiplied
|
||||||
* by the amount of cargo moved and the price factor, then gets
|
* by the amount of cargo moved and the price factor, then gets
|
||||||
|
@ -1563,9 +1563,6 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
|
||||||
{
|
{
|
||||||
assert(v->current_order.IsType(OT_LOADING));
|
assert(v->current_order.IsType(OT_LOADING));
|
||||||
|
|
||||||
/* When we've finished loading we're just staying here till the timetable 'runs' out */
|
|
||||||
if (HasBit(v->vehicle_flags, VF_LOADING_FINISHED)) return;
|
|
||||||
|
|
||||||
assert(v->load_unload_time_rem != 0);
|
assert(v->load_unload_time_rem != 0);
|
||||||
|
|
||||||
/* We have not waited enough time till the next round of loading/unloading */
|
/* We have not waited enough time till the next round of loading/unloading */
|
||||||
|
@ -1587,6 +1584,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
|
||||||
/* The train reversed in the station. Take the "easy" way
|
/* The train reversed in the station. Take the "easy" way
|
||||||
* out and let the train just leave as it always did. */
|
* out and let the train just leave as it always did. */
|
||||||
SetBit(v->vehicle_flags, VF_LOADING_FINISHED);
|
SetBit(v->vehicle_flags, VF_LOADING_FINISHED);
|
||||||
|
v->load_unload_time_rem = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1680,9 +1678,11 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
|
||||||
/* update stats */
|
/* update stats */
|
||||||
int t;
|
int t;
|
||||||
switch (u->type) {
|
switch (u->type) {
|
||||||
case VEH_TRAIN: t = u->u.rail.cached_max_speed; break;
|
case VEH_TRAIN: t = u->u.rail.cached_max_speed; break;
|
||||||
case VEH_ROAD: t = u->max_speed / 2; break;
|
case VEH_ROAD: t = u->max_speed / 2; break;
|
||||||
default: t = u->max_speed; break;
|
case VEH_SHIP: t = u->max_speed; break;
|
||||||
|
case VEH_AIRCRAFT: t = u->max_speed * 10 / 129; break; // convert to old units
|
||||||
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if last speed is 0, we treat that as if no vehicle has ever visited the station. */
|
/* if last speed is 0, we treat that as if no vehicle has ever visited the station. */
|
||||||
|
|
|
@ -466,7 +466,7 @@ static SQInteger _io_file_read(SQUserPointer file, SQUserPointer buf, SQInteger
|
||||||
/* Load and run the script */
|
/* Load and run the script */
|
||||||
if (SQ_SUCCEEDED(LoadFile(vm, script, SQTrue))) {
|
if (SQ_SUCCEEDED(LoadFile(vm, script, SQTrue))) {
|
||||||
sq_push(vm, -2);
|
sq_push(vm, -2);
|
||||||
if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
|
if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue, 100000))) {
|
||||||
sq_pop(vm, 1);
|
sq_pop(vm, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue