From fee07e0afa65106b190a1d971e6f67642c2b7ec7 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Sat, 23 Feb 2008 15:58:50 +0000
Subject: [PATCH] Clean up port/planet records on exit as well.

---
 xtrn/tw2/players.js |  7 +++++++
 xtrn/tw2/tw2.js     | 18 +++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/xtrn/tw2/players.js b/xtrn/tw2/players.js
index 92fca76209..fbd5dcfbd6 100644
--- a/xtrn/tw2/players.js
+++ b/xtrn/tw2/players.js
@@ -95,6 +95,12 @@ var PlayerProperties=[
 				,type:"Boolean"
 				,def:false
 			}
+			,{
+				 prop:"TimeToday"
+				,name:"Time used today (secs)"
+				,type:"Integer"
+				,def:0
+			}
 		];
 
 var PlayerLocation = [
@@ -637,6 +643,7 @@ function LoadPlayer()
 		}
 		else {
 			player.TurnsLeft=Settings.TurnsPerDay;
+			player.TimeToday=0;
 		}
 		player.LastOnDay=system.datestr();
 		if(player.KilledBy != 0) {
diff --git a/xtrn/tw2/tw2.js b/xtrn/tw2/tw2.js
index 7d606a8d4c..5a75c131a4 100644
--- a/xtrn/tw2/tw2.js
+++ b/xtrn/tw2/tw2.js
@@ -199,8 +199,21 @@ function Menu()
 function do_exit()
 {
 	player.Online=false;
-	player.Ported=false;
-	player.Landed=false;
+	if(player.Ported || player.Landed) {
+		var sector=sectors.Get(player.Sector);
+		if(player.Ported) {
+			player.Ported=false;
+			var port=ports.Get(sector.Port);
+			port.OccupiedBy=0;
+			port.Put();
+		}
+		if(player.Landed) {
+			player.Landed=false;
+			var planet=planets.Get(sector.Planet);
+			planet.OccupiedBy=0;
+			planet.Put();
+		}
+	}
 	player.Put();
 	console.writeln("Returning to Door monitor...");
 	TWRank();
@@ -234,4 +247,3 @@ function Production(place)
 	place.LastUpdate=newupd;
 	place.Put();
 }
-
-- 
GitLab