Page 1 of 2

Patch: Trip History

Posted: 01 Aug 2007 11:59
by Molp
Trip History Patch v0.2 (Works with nightly r10737+)

This patch is designed to show information about the last 10 trips that a vehicle has made.

The columns are:
Received: When the vehicle delivered the cargo
Profit: Profit from the cargo
Change: Shows the percentage difference between the current and last trips profits
TBT (Time between trips): Shows the time taken between each trip
Change: Shows the change (in days) between the TBT values

The screenshots should give you a better understanding.


This is a WIP - features requests etc are welcome.

CHANGELOG
v0.2
Fixed spelling mistakes
0% values are now shown in green
Transfer virtual profit is now shown (in yellow)
Fixed save game compatibility


v0.1
Initial release
Train and ship trip history
Train and ship trip history
Sadborough Transport, 30th Jul 2010.png (79.3 KiB) Viewed 15011 times
Road vehicle and aircraft trip history window
Road vehicle and aircraft trip history window
Sadborough Transport, 29th Jul 2010.png (85.32 KiB) Viewed 15012 times

Re: Patch: Trip History

Posted: 01 Aug 2007 12:08
by rav
/me likes

could you add the departure & arrival stations?

edit: welcome to the forums :]
edit2: change recieved to received <-- just a hint, great patch!

Re: Patch: Trip History

Posted: 01 Aug 2007 12:49
by XeryusTC
Ah very nice, I always liked it that you could see the amount of money a vehicle earned on its last trip :).

Maybe it would be nice to also add an average running costs per day next to the average earnings per day. It might be a nice comparison :).

Re: Patch: Trip History

Posted: 01 Aug 2007 14:45
by doghousedean
this is a really good addition, and something you can use to debug/improve your system with.


keep up the good work

Re: Patch: Trip History

Posted: 01 Aug 2007 15:01
by chrissicom
This is an awesome patch that should certainly be in ChrisIN if you don't mind :)) and also welcome to the forums!! Great first post!

Maybe a tip for not breaking savegame compatibility:

In saveload.cpp change the savegame version to 73 (72 is the current version in trunk iirc).

And then in vehicle.cpp

Code: Select all

65, SL_MAX_VERSION
should be
73, SL_MAX_VERSION
That way loading old savegames with your patch should be no problem :)

Re: Patch: Trip History

Posted: 01 Aug 2007 15:41
by MeusH
This patch is great :)

However, I'm wondering why values of "change" (in days) are not one row below? I think it would be better if values of last column were moved down by one row.

Also, I don't think 0% should be red - it isn't bad - it's rather neutral, but using too many colours (like extra yellow) isn't a good idea either. Making it green would be better, because I think that red colour is reserved for danger, or at least bad things

Re: Patch: Trip History

Posted: 01 Aug 2007 17:03
by Noldo
I'm personally interested about anything related to accounting and following the movement of money in the game so I like the idea too.

XeryusTC suggested comparing average running costs per day and average earnings per day, I'm not sure if he meant this to be per round trip comparison but I would like that. Also to add more Return On Investment feel to it the comparison should include the value of the vehicles lost while on the trip.

Re: Patch: Trip History

Posted: 02 Aug 2007 00:24
by Molp
chrissicom wrote:This is an awesome patch that should certainly be in ChrisIN if you don't mind :)) and also welcome to the forums!! Great first post!
You can certainly put it in ChrisIN. The only things needed to be changed would be moving the button in the train description window to not interfere with the routemarkers, and change the respective case statement number to the correct value.

try:
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 295, 369, 32, 43, STR_TRIP_HISTORY, STR_TRIP_HISTORY_TOOLTIP},
(does look a bit off with the Max T.E value above it, but you can change it to make it look better)


Updated the patch to v0.2

Re: Patch: Trip History

Posted: 02 Aug 2007 16:53
by Lupin III
Cool! Can't wait for the next ChrisIN!
Also, I don't think 0% should be red - it isn't bad - it's rather neutral
Actually the change is negative in this case if you compare the absolute values. So showing it red is correct. I assume there could also be green 0%.

Re: Patch: Trip History

Posted: 02 Aug 2007 18:26
by MeusH
Thank you Lupin III
Also please disregard my previous post, now I realised the dates are sorted in descending, causing my confusion because I was sure they are ascending.
By the way, how about ability to sort by date ascending/descending?

Re: Patch: Trip History

Posted: 02 Aug 2007 18:55
by Bilbo
This will be very useful.

I also wonder if it is possible to have similar window also for vehicle groups? Showing either sum or average from these values ....

Re: Patch: Trip History

Posted: 03 Aug 2007 11:40
by browneyedboy
I tried patching this just now, but it wont work.

I use nightly r10753

I followed the steps on how to add a .patch/.diff-file

What am I doing wrong? :/

Re: Patch: Trip History

Posted: 03 Aug 2007 14:54
by shagademis
oo very useful. i like

Re: Patch: Trip History

Posted: 07 Aug 2007 10:20
by chrissicom
There's an assertion bug with this patch, although I couldn't find out yet why. I compiled a debug version of the patch with ChrisIN, and whenever I close any of the vehicle windows the game crashes with the following error message... maybe you have an idea :)

P.S.: If it wasn't clear, only the debug build crashes on closing a vehicle, vehicle details or trip history window, the release build works fine :) I had a similar problem with the copy & paste patch which I fixed, if I would just remember how :cry:

Re: Patch: Trip History

Posted: 07 Aug 2007 21:45
by DaleStan
That's usually caused by:
1) freeing a pointer that wasn't malloced (Did you step through an array by modifying the pointer instead of an index?)
2) freeing a pointer has already been freed, resp,
3) freeing a stack pointer (see #1)
(The same applies for new/delete and new[]/delete[]. All three heap allocation stytems must be kept separate.)

One thing it is notably NOT caused by is freeing/deleting/delete[]ing NULL. That is guaranteed to be a nop.

The release build doesn't assert because it's a release build, and those try to work, instead of trying to make debugging easy.

Re: Patch: Trip History

Posted: 17 Aug 2007 17:27
by chrissicom
The problem is this portion of code in the added triphistory_gui.cpp

Code: Select all

static void VehicleTripHistoryWndProc(Window *w, WindowEvent *e)
{
	Vehicle *v;
	v = GetVehicle(w->window_number);
	switch (e->event) {
		case WE_CREATE:
			CreateTripHistoryInformation(v);
			break;
		case WE_PAINT:
			DrawVehicleTripHistoryWindow(w);
			break;
		case WE_DESTROY:
			free(v->trip_history_pchange_array);
			free(v->trip_history_TBT_array);
			free(v->trip_history_TBT_change_array);
			v->trip_history_avg_daylength = 0;
			v->trip_history_profitpd = 0;
			v->trip_history_total_change = 0;
			v->trip_history_total_profit = 0;
			break;
	}
}
When I comment out the WE_DESTROY case everything works fine. The WE_DESTROY case will reset all the trip history values and is supposed to free the created arrays which is causing the crash in the debug version afaik. I think this whole WE_DESTROY is not needed anyway so I just removed it for ChrisIN :)

Re: Patch: Trip History

Posted: 19 Aug 2007 16:05
by neuron
valgrind trace shows all of those 3 free's as invalid.

Code: Select all

==19592== Invalid free() / delete / delete[]
==19592==    at 0x4A1F88A: free (in /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
==19592==    by 0x51816B: VehicleTripHistoryWndProc(Window*, WindowEvent*) (triphistory_gui.cpp:93)
(and identical for line 94 and 95), translating to:
free(v->trip_history_pchange_array);

free(v->trip_history_TBT_array);

free(v->trip_history_TBT_change_array);
in WE_DESTROY in VehicleTripHistoryWndProc.

//edit, just noticed the "v" (vehicle) it's freeing does not exist here, only in WE_CREATE

Re: Patch: Trip History

Posted: 19 Aug 2007 18:31
by konrado345
Great patch!

But will it work in ChrisIN?

Re: Patch: Trip History

Posted: 20 Aug 2007 09:53
by chrissicom
Yes it works in ChrisIN and is in my local build which will be published this week already :)

Re: Patch: Trip History

Posted: 26 Aug 2007 16:22
by The Zero
Thanks for the patch.

Just a small glitch: I'm using ChrisIN-r10982 (yes, already :D ) and when the train arrives at station with history window opened, new line is inserted, but only received and profit columns are added. Change and TBT columns don't move so they are displayed for wrong journey. Reopening history window helps.