Patch: Trip History

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Molp
Engineer
Engineer
Posts: 3
Joined: 27 Jul 2003 16:06

Patch: Trip History

Post by Molp » 01 Aug 2007 11:59

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
Sadborough Transport, 30th Jul 2010.png
Train and ship trip history
Sadborough Transport, 30th Jul 2010.png (79.3 KiB) Viewed 10780 times
Sadborough Transport, 29th Jul 2010.png
Road vehicle and aircraft trip history window
Sadborough Transport, 29th Jul 2010.png (85.32 KiB) Viewed 10781 times
Attachments
triphistory_v0.2_r10737.patch
(21.84 KiB) Downloaded 285 times
Last edited by Molp on 02 Aug 2007 00:17, edited 1 time in total.

User avatar
rav
Traffic Manager
Traffic Manager
Posts: 253
Joined: 17 May 2007 13:36
Location: Netherlands
Contact:

Re: Patch: Trip History

Post by rav » 01 Aug 2007 12:08

/me likes

could you add the departure & arrival stations?

edit: welcome to the forums :]
edit2: change recieved to received <-- just a hint, great patch!
Last edited by rav on 01 Aug 2007 12:56, edited 2 times in total.

User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Re: Patch: Trip History

Post by XeryusTC » 01 Aug 2007 12:49

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 :).
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image

doghousedean
Traffic Manager
Traffic Manager
Posts: 141
Joined: 30 Apr 2007 10:26

Re: Patch: Trip History

Post by doghousedean » 01 Aug 2007 14:45

this is a really good addition, and something you can use to debug/improve your system with.


keep up the good work

chrissicom
Route Supervisor
Route Supervisor
Posts: 415
Joined: 07 Oct 2004 10:05

Re: Patch: Trip History

Post by chrissicom » 01 Aug 2007 15:01

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 :)

MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Re: Patch: Trip History

Post by MeusH » 01 Aug 2007 15:41

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
Last edited by MeusH on 01 Aug 2007 18:32, edited 1 time in total.

Noldo
Engineer
Engineer
Posts: 75
Joined: 16 Jun 2005 13:17
Location: Lappeenranta, Finland

Re: Patch: Trip History

Post by Noldo » 01 Aug 2007 17:03

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.

Molp
Engineer
Engineer
Posts: 3
Joined: 27 Jul 2003 16:06

Re: Patch: Trip History

Post by Molp » 02 Aug 2007 00:24

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

User avatar
Lupin III
Engineer
Engineer
Posts: 66
Joined: 11 Jul 2007 16:36

Re: Patch: Trip History

Post by Lupin III » 02 Aug 2007 16:53

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%.

MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Re: Patch: Trip History

Post by MeusH » 02 Aug 2007 18:26

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?

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Patch: Trip History

Post by Bilbo » 02 Aug 2007 18:55

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 ....
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

User avatar
browneyedboy
Engineer
Engineer
Posts: 38
Joined: 26 Apr 2005 08:49
Location: Karlskrona, Sweden

Re: Patch: Trip History

Post by browneyedboy » 03 Aug 2007 11:40

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? :/
Last edited by browneyedboy on 03 Aug 2007 18:06, edited 1 time in total.

shagademis
Engineer
Engineer
Posts: 46
Joined: 06 Jun 2006 12:54

Re: Patch: Trip History

Post by shagademis » 03 Aug 2007 14:54

oo very useful. i like

chrissicom
Route Supervisor
Route Supervisor
Posts: 415
Joined: 07 Oct 2004 10:05

Re: Patch: Trip History

Post by chrissicom » 07 Aug 2007 10:20

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:
Attachments
debug crash.png
(586.07 KiB) Downloaded 115 times

DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Patch: Trip History

Post by DaleStan » 07 Aug 2007 21:45

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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser

chrissicom
Route Supervisor
Route Supervisor
Posts: 415
Joined: 07 Oct 2004 10:05

Re: Patch: Trip History

Post by chrissicom » 17 Aug 2007 17:27

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 :)

neuron
Engineer
Engineer
Posts: 19
Joined: 14 Aug 2007 07:47

Re: Patch: Trip History

Post by neuron » 19 Aug 2007 16:05

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

konrado345
Engineer
Engineer
Posts: 11
Joined: 02 Aug 2007 11:12

Re: Patch: Trip History

Post by konrado345 » 19 Aug 2007 18:31

Great patch!

But will it work in ChrisIN?

chrissicom
Route Supervisor
Route Supervisor
Posts: 415
Joined: 07 Oct 2004 10:05

Re: Patch: Trip History

Post by chrissicom » 20 Aug 2007 09:53

Yes it works in ChrisIN and is in my local build which will be published this week already :)

The Zero
Engineer
Engineer
Posts: 5
Joined: 26 Aug 2007 16:12

Re: Patch: Trip History

Post by The Zero » 26 Aug 2007 16:22

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.

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Captain Rand, Diesel Power, Google Adsense [Bot], Zainy521 and 1 guest