Behemoth carrier update for OSE

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Behemoth carrier update for OSE

Post by pmw57 »

The behemoth carrier script has been updated to protect it from crashing Oolite.
scripts/behemoth-carrier.js

The code has been updated so that it is easier to consistently maintain and is formatted in a more stable manner.

Timer events have been updated so that they will fail elegantly, rather than crashing the system.

Code: Select all

	if (this.cloakingTimer) {
		this.cloakingTimer.start();
	} else {
		this.cloakingTimer = new Timer(this, this.statusCheck, 1, 1);
	}
The end of the code has had added to it the following cleanup code:

Code: Select all

this.playerWillEnterWitchspace = function () {
	if (this.cloakingTimer) {
		this.cloakingTimer.stop();
		delete this.cloakingTimer;
	}
};
Last edited by pmw57 on Thu Oct 15, 2009 9:47 am, edited 5 times in total.
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

A significant change has occurred to the statusCheck method.

Here is how the original statusCheck code was structured

Code: Select all

this.statusCheck = function () {
	if (!this.cloakedTarget) {
		if (this.cloakingTimer) {
			this.cloakingTimer.stop();
			delete this.cloakingTimer;
		}
	} else {
		if (!this.cloakedTarget.isCloaked) {
			this.ship.target = this.cloakedTarget;
			this.ship.reactToAIMessage("TARGET_DECLOAKED");
			if (this.cloakingTimer) {
				this.cloakingTimer.stop();
				delete this.cloakingTimer;
			}
		}
	}
};
Notice that the timer is being stopped in two different places.

If we chart the two conditions, cloakedTarget and isCloaked, we will see that the timer is allowed to continue only when there is a currently cloaked target.
Likewise, the decloaked message occurs only when the ship is not cloaked.

That led to this update in the code:

Code: Select all

this.statusCheck = function () {
	if (this.cloakedTarget) {
		if (this.cloakedTarget.isCloaked) {
			return;
		} else {
			this.ship.target = this.cloakedTarget;
			this.ship.reactToAIMessage("TARGET_DECLOAKED");
		}
	}
	if (this.cloakingTimer) {
		this.cloakingTimer.stop();
		delete this.cloakingTimer;
	}
};
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
Post Reply