Back to Index Page generated: Nov 12, 2024, 11:02:04 PM

Expansion LogEvents

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Write messages into Latest.log using all event handlers to help debugging and review battles and messages. Write messages into Latest.log using all event handlers to help debugging and review battles and messages.
Identifier oolite.oxp.Norby.LogEvents oolite.oxp.Norby.LogEvents
Title LogEvents LogEvents
Category Miscellaneous Miscellaneous
Author Norby Norby
Version 1.4 1.4
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/LogEvents n/a
Download URL https://wiki.alioth.net/img_auth.php/8/83/LogEvents_1.4.oxz n/a
License CC BY-NC-SA 4.0 CC BY-NC-SA 4.0
File Size n/a
Upload date 1610873351

Documentation

Also read http://wiki.alioth.net/index.php/LogEvents

LogEvents readme.txt

LogEvents OXP

This script catch all available handlers and write into the Logs/Latest.log to help developing
and to review a battle, or find out why the police attacking you suddenly.

Originally maded to log all laser hits earned in the built-in mini game in the HUDRequests OXP,
but separated due to it is useful to everybody, while usually realize it after something happened.


Dependencies:
Oolite v1.77 or later.

Instructions:
Unzip the file, then move the folder named ".oxp" in the end to the AddOns directory of your Oolite installation.

License:
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License version 4.0
If you are re-using any piece of this OXP, please let me know by sending an e-mail to norbylite@gmail.com .

Changelog:
2018.07.27. v1.4 - Added a new event for Oolite 1.87.
                   Removed Player word from each message to reduce log size.
                   A minor fix in systemInformationChanged by cag.
2018.01.29. v1.3 - Added new events of Oolite 1.86. Minor fixes by cag.
2017.06.24. v1.2 - Better log of targets without name like moons, thanks to cag.
2017.03.13. v1.1 - Updated with new events which are added into the game meantime.
2013.06.04. v1.0 - First release.

Equipment

This expansion declares no equipment.

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
Scripts/logevents.js
"use strict";
this.name        = "logevents";
this.author      = "Norby";
this.copyright   = "Norbert Nagy";
this.licence     = "CC BY-NC-SA 4.0";
this.description = "Log player events to review a battle, with added ShipVersion OXP support.";

this.$LogEvents_On = true; //turn off means no event logging at all
this.$LogEvents_Prefix = "LogEvents"; //this will be the messageClass string in the log

this.$LogEvents_Ships = []; //store the ships spawned during timer
this.$LogEvents_Timer = null; //store the timer pointer


//these documented as ship script events but usually works as a world script event for the player also
this.shipTargetAcquired = function(target) {
	this.$LogEvents_Player( "targeted", target, "who has "+this.$LogEvents_NPCLeft( target ) );
}

this.shipTakingDamage = function(amount, whom, type) {
	var s = "shield damage";
	if( amount > 0 ) s = Math.round( amount ) + " " + type;
	this.$LogEvents_Player( "taking "+s+" from", whom, this.$LogEvents_PlayerLeft() );
}

this.cascadeWeaponDetected = function(weapon) {
	this.$LogEvents_Player( "detected cascade weapon "+weapon );
}

this.shipBeingAttackedUnsuccessfully = function(whom) {
	this.$LogEvents_Player( "attacked unsuccessfully by", whom );
}

this.shipCloakActivated = function() {
	this.$LogEvents_Player( "cloak is activated" );
}

this.shipCloakDectivated = function() {
	this.$LogEvents_Player( "cloak is deactivated" );
}

this.shipEnergyBecameFull = function() {
	this.$LogEvents_Player( "energy is full" );
}

this.shipEnergyIsLow = function() {
	this.$LogEvents_Player( "energy is low" );
}

this.shipHitByECM = function(pulsesRemaining) {
	this.$LogEvents_Player( "hit by ECM, "+pulsesRemaining+" remaining" );
}

this.commsMessageReceived = function(message, sender) {
	this.$LogEvents_Player( "got message from", sender, ": "+message );
}

this.distressMessageReceived = function(aggressor, sender) {
	this.$LogEvents_Player( "got distress message from", sender,
			     ": Help! "+this.$LogEvents_TargetName(aggressor)+" attacking me!" );
}

this.shipBountyChanged = function(delta, reason) {
	if(delta != 0) this.$LogEvents_Player( "bounty is changed by "+delta+
		" to "+player.bounty+" due to "+reason );
}

this.shipCloseContact = function(otherShip) {
	this.$LogEvents_Player( "is in close contact with", otherShip);
}

this.shipReachedEndPoint = function() {
	this.$LogEvents_Player( "reached endpoint" );
}

this.shipReachedNavPoint = function() {
	this.$LogEvents_Player( "reached navpoint" );
}



//world script events, in the same order than in the wiki (grouped by type)

//Game State
this.gamePaused = function() {
	this.$LogEvents_Player( "paused the game" );
}

this.gameResumed = function() {
	this.$LogEvents_Player( "resumed the game" );
}

this.playerWillSaveGame = function(message) {
	this.$LogEvents_Player( message );
}

this.startUpComplete  = function(target) {
	this.$LogEvents_Populators();
}

//Docking 
this.shipWillDockWithStation = function(station) {
	this.$LogEvents_Player( "will dock to", station );
}

this.shipDockedWithStation = function(station) {
	this.$LogEvents_Player( "docked to", station );
}

this.shipWillLaunchFromStation = function(station) {
	var m2 = "";
	if( player.ship ) m2 = "flying "+this.$LogEvents_TargetName(player.ship);
	this.$LogEvents_Player( "will launch from", station, m2 );
}

this.shipLaunchedFromStation = function(station) {
	this.$LogEvents_Player( "launched from", station );
}

this.playerStartedAutoPilot = function() {
	this.$LogEvents_Player( "started AutoPilot" );
}

this.playerCancelledAutoPilot = function() {
	this.$LogEvents_Player( "cancelled AutoPilot" );
}

this.playerChangedPrimedEquipment = function(equipmentKey) {
	this.$LogEvents_Player( "primed "+equipmentKey );
}

this.playerDockingClearanceCancelled = function() {
	this.$LogEvents_Player( "docking clearance cancelled" );
}

this.playerDockingClearanceExpired = function() {
	this.$LogEvents_Player( "docking clearance expired" );
}

this.playerDockingClearanceGranted = function() {
	this.$LogEvents_Player( "docking clearance granted" );
}

this.playerDockingRefused = function() {
	this.$LogEvents_Player( "docking refused" );
}

this.playerRequestedDockingClearance = function(message) {
	this.$LogEvents_Player( "requested docking clearance and "+message);
}

this.playerRescuedEscapePod = function(fee, reason, occupant) {
	var m = "";
	if( reason == "slave" ) m = "with a slave";
	else m = "for "+(fee/10)+" credits "+reason; //insurance or bounty
	this.$LogEvents_Player( "rescued escape pod "+m+" occuped by ", occupant);
}

this.playerCompletedContract = function(type, result, fee, contract) {
	this.$LogEvents_Player( "completed "+type+" contract with "+result
		+" result, got "+(fee/10)+" credits ", contract);
}

this.playerEnteredContract = function(type, contract) {
	this.$LogEvents_Player( "entereted "+type+" contract", contract);
}

//Witchspace Jumps 
this.playerStartedJumpCountdown = function(type, seconds) {
	this.$LogEvents_Player( "started "+seconds+" seconds "+type+" jump countdown");
}

this.playerCancelledJumpCountdown = function() {
	this.$LogEvents_Player( "cancelled jump countdown");
}

this.playerJumpFailed = function(reason) {
	this.$LogEvents_Player( "jump failed due to "+reason);
}

this.shipWillEnterWitchspace = function(cause, destination) {
	var dest = "";
	if( destination ) {
		if( cause == "galactic jump" ) dest = " to galaxy "+destination;
                else dest = " to system "+destination;
        }
	this.$LogEvents_Player( "will enter witchspace "+dest+" due to "+cause);
}

this.shipWillExitWitchspace = function() {
	this.$LogEvents_Populators();
	this.$LogEvents_Player( "will exit witchspace");
}

this.shipExitedWitchspace = function() {
	this.$LogEvents_Player( "exited from witchspace");
}

this.playerEnteredNewGalaxy = function(galaxyNumber) {
	this.$LogEvents_Player( "entered "+galaxyNumber+". galaxy");
}

//Enter/Exit Aegis
this.shipEnteredStationAegis = function(station) {
	this.$LogEvents_Player( "entered to the aegis of", station);
}

this.shipExitedStationAegis = function(station) {
	this.$LogEvents_Player( "exited from aegis of", station);
}

this.shipEnteredPlanetaryVicinity = function(planet) {
	this.$LogEvents_Player( "entered to the vicinity of "+planet.toString());
}

this.shipExitedPlanetaryVicinity = function(planet) {
	this.$LogEvents_Player( "exited from the vicinity of "+planet.toString());
}

this.shipApproachingPlanetSurface = function(planet) {
	this.$LogEvents_Player( "approaching the surface of "+planet.toString());
}

this.shipLeavingPlanetSurface = function(planet) {
	this.$LogEvents_Player( "leaving the surface of "+planet.toString());
}

//Combat
this.alertConditionChanged = function(newCondition, oldCondition) {
	this.$LogEvents_Player( "alert condition changed from "+oldCondition+" to "+newCondition);
}

this.playerTargetedMissile = function(missile) {
	this.$LogEvents_Player( "targeted missile "+missile.name );
}

this.shipAttackedOther = function(other) {
	this.$LogEvents_Player( "attacked", other, "who has "+this.$LogEvents_NPCLeft( other ) );
}

this.shipAttackedWithMissile = function(missile, whom) {
	this.$LogEvents_Player( "attacked with "+missile.name+" from", whom );
}

this.shipBeingAttacked = function(whom) {
	this.$LogEvents_Player( "attacked by", whom, this.$LogEvents_PlayerLeft() );
}

this.shipBeingAttackedByCloaked = function() {
	this.$LogEvents_Player( "attacked by a cloaked ship "+this.$LogEvents_PlayerLeft() );
}

this.shipKilledOther = function(whom, damageType) {
	this.$LogEvents_Player( "killed", whom, "with "+damageType);
}

this.shipReleasedEquipment = function(mine) {
	this.$LogEvents_Player( "released equipment ", mine);
}

this.shipTargetDestroyed = function(target) {
	this.$LogEvents_Player( "target", target, "is destroyed");
}

this.shipDied = function(whom, why) {
	this.$LogEvents_Player( "got "+why+" from", whom, "and died!");
}

this.shipFiredMissile = function(missile, target) {
	this.$LogEvents_Player( "fired missile "+missile.name+" to", target);
}

this.shipTargetLost = function(target) {
	if( target ) this.$LogEvents_Player( "lost lock on", target);
}

this.shipTargetCloaked = function() {
	this.$LogEvents_Player( "target cloaked");
}

this.weaponsSystemsToggled = function(state) {
	this.$LogEvents_Player( "weapons systems toggled to "+state);
}

//Equipment and Cargo 
this.equipmentAdded = function(equipmentKey) {
	this.$LogEvents_Player( "ship got "+equipmentKey );
}

this.equipmentDamaged = function(equipment) {
//	if( equipment.isVisible ) //to avoid HUD control equipments
		this.$LogEvents_Player( equipment.toString()+" damaged" );
}

this.equipmentRemoved = function(equipmentKey) {
	this.$LogEvents_Player( "ship lost "+equipmentKey );
}

this.equipmentDestroyed = function(equipment) {
//	if( equipment.isVisible ) //to avoid HUD control equipments
		this.$LogEvents_Player( equipment.toString()+" destroyed" );
}

this.equipmentRepaired = function(equipment){
//	if( equipment.isVisible ) //to avoid HUD control equipments
		this.$LogEvents_Player( equipment.toString()+" repaired" );
}

this.playerBoughtCargo = function(commodity, units, price) {
	this.$LogEvents_Player( "bought "+units+" "
		+expandDescription("[commodity-name "+commodity+"]")
		+" for "+(price/10)+" credits");
}

this.playerBoughtEquipment = function(equipment) {
	this.$LogEvents_Player( "bought "+equipment.toString() );
}

this.playerBoughtNewShip = function(ship) {
	this.$LogEvents_Player( "bought new ship:", ship );
}

this.playerSoldCargo = function(commodity, units, price) {
     	this.$LogEvents_Player( "sold "+units+" "
		+expandDescription("[commodity-name "+commodity+"]")
		+" for "+(price/10)+" credits");
}

this.shipScoopedFuel = function() {
	this.$LogEvents_Player( "scooped 0.1 LY fuel" );
}

this.shipScoopedOther = function(whom) {
	this.$LogEvents_Player( "scooped", whom );
}

//Other
this.chartHightlightModeChanged = function(newMode){
	this.$LogEvents_Player( "chartHightlightMode is changed to "+newMode );
}

this.compassTargetChanged = function(whom, mode) {
	this.$LogEvents_Player( "compass targeted", whom, "in mode "+mode );
}

this.dayChanged = function(newday) {
	this.$LogEvents_Player( "new day "+newday );
}

this.escapePodSequenceOver = function() {
	this.$LogEvents_Player( "escape pod sequence over");
}

this.guiScreenChanged = function(to, from) {
	this.$LogEvents_Player( "gui screen changed from "+from+" to "+to );
}

this.guiScreenWillChange = function(to, from) {
	this.$LogEvents_Player( "gui screen will change from "+from+" to "+to );
}

this.infoSystemChanged = function(to, from) {
	this.$LogEvents_Player( "info system changed from "+from+" to "+to );
}

this.infoSystemWillChange = function(to, from) {
	this.$LogEvents_Player( "info system will change from "+from+" to "+to );
}

this.mfdKeyChanged = function(activeMFD, mfdKey) {
	this.$LogEvents_Player( "mfd "+activeMFD+" changed to "+mfdKey );
}

this.missionChoiceWasReset= function() {
	this.$LogEvents_Player( "mission choice was reset" );
}

this.missionScreenEnded = function() {
	this.$LogEvents_Player( "mission screen ended" );
}

this.missionScreenOpportunity= function() {
	this.$LogEvents_Player( "mission screen opportunity" );
}

this.reportScreenEnded = function() {
	this.$LogEvents_Player( "report screen ended" );
}

this.selectedMFDChanged = function(activeMFD) {
	this.$LogEvents_Player( "selected mfd "+activeMFD );
}

this.shipCollided = function(otherShip) {
	this.$LogEvents_Player( "collided with", otherShip );
}

this.shipSpawned = function(ship) {
	this.$LogEvents_Ships[ this.$LogEvents_Ships.length ] = ship;
	if( !this.$LogEvents_Timer ) //give some time to run all shipSpawned before get ShipVersion
		this.$LogEvents_Timer = new Timer(this, this.$LogEvents_Timed, 0.1, 0);
}

this.shipLaunchedEscapePod = function(escapepod) {
	this.$LogEvents_Player( "launched Escape Pod" );
}

this.systemInformationChanged = function(galaxy,system,key,newValue) {
	if( key == "concealment") return; //prevent too many logs
	this.$LogEvents_Player( "system information changed in galaxy "+galaxy
		+" system "+system+" key "+key+" to "+newValue );
}

this.viewDirectionChanged = function(viewString) {
	this.$LogEvents_Player( viewString );
}


//LogEvents functions
this.$LogEvents_NPCLeft = function( target ) {
	if( !target ) return("unknown energy");
	var sh = "";
	if( worldScripts["customshields"] && target && target.script
		&& target.script.customshieldsforwardshieldlevel ) { //asteroids have no shield
		sh = Math.round( target.script.customshieldsforwardshieldlevel ) + "+" +
			Math.round( target.script.customshieldsaftshieldlevel ) + " shield and ";
	}
	return( sh + Math.round( target.energy ) + " energy" );
}

this.$LogEvents_Player = function( message1, target, message2, nolosttarget ) { //with target
	if( worldScripts["logevents"].$LogEvents_On ) {
		var n = "";
		if( typeof( target ) != 'undefined' ) //give "lost target" message only if null
			n = worldScripts["logevents"].$LogEvents_TargetName( target );
		var s = "";
		if( n && n.length > 0 ) s += " "+n;
		if( message2 && message2.length > 0 ) s += " " + message2;
		if( message1 ) ;//message1 = " " + message1;
		else message1 = "";
		log( this.$LogEvents_Prefix, message1 + s ); //assume Player by default
	}
}

this.$LogEvents_PlayerLeft = function() {
	if( player.ship ) return( Math.round( player.ship.forwardShield ) + "+" +
		+ Math.round( player.ship.aftShield ) + " shield and "
		+ Math.round( player.ship.energy ) + " energy left");
}

this.$LogEvents_Populators = function() {
	log( this.$LogEvents_Prefix, "Populators:\n " 
		+ JSON.stringify(system.populatorSettings).replace(/},/g, "},\n  ") );
}

this.$LogEvents_TargetName = function( target ) { //support for ShipVersion OXP to log ship version also
	if( !target ) return("lost target");
        var n = "";
        if( target.dataKey ) n = target.dataKey; //fallback to key if no name nor stringify
        if( target.name ) n = target.name;
        else {
	    try {
	        n = JSON.stringify(target); //sometimes get TypeError: cyclic object value, for example if dataKey is planetaryCompass_moon
	    } catch( err ) {
	        //log(this.name, '**************************************************************************************' );
		//log(this.name, 'in LogEvents_TargetName, caught error: ' + err + '    target = ' + target );
		//if( err /*instanceof TypeError*/ ) this._rpt_error( err );
		//log(this.name, '**************************************************************************************' );
		//throw err;//do not stop here, log dataKey instead
	    }
	}
	if( target.script && target.script.$Detectors_Origname )
		n = target.script.$Detectors_Origname;
	var p = target.entityPersonality;
	if( !p ) p = target.beaconLabel; //for moons
	return( n + " " + p );
}

this.$LogEvents_Timed = function $LogEvents_Timed() {
	for(var i = 0; i < this.$LogEvents_Ships.length; i++ ) {
		var ship = this.$LogEvents_Ships[i];
		if( !ship.isVisualEffect && ship.isVisible && ship.name.indexOf("customshields") == -1 ) {
			var d = "unknown";
			if( player.ship && player.ship.position && ship && ship.position ) //no ship when died
				d = Math.round( player.ship.position.distanceTo( ship.position ) /1000 );
			var o = "";
			var owner = this.$LogEvents_Ships[i].owner;
			if( owner ) o = " from " + this.$LogEvents_TargetName( owner );
			log( this.$LogEvents_Prefix,
			     this.$LogEvents_TargetName( ship ) + o + " spawned at " + d + " km" );
		}
	}
	this.$LogEvents_Ships = []; //start new array
	this.$LogEvents_Timer.stop();
	delete this.$LogEvents_Timer;
}