Fix some daylength issues, possible division by zero in main menu.
[openttd-joker.git] / src / triphistory.h
blobbbc6c306a2f9b9229a55660e5c1f0e2c45d6b9ec
1 /** @file triphistory.h */
3 #ifndef TRIPHISTORY_H
4 #define TRIPHISTORY_H
6 #include <deque>
7 #include "window_gui.h"
8 #include "strings_type.h"
9 #include "economy_type.h"
10 #include "date_type.h"
12 // entries to save
13 #define TRIP_LENGTH 10
15 static inline int TripHistoryRound( float x )
17 return int( x > 0.0 ? x + 0.5 : x - 0.5 );
20 struct TripHistoryEntry {
21 Money profit; // Saved
22 Date date; // Saved
23 int32 profit_change; // Calculated
24 Date TBT; // Calculated
25 int32 TBT_change; // Calculated
27 TripHistoryEntry( ) : profit( 0 ), date( 0 ), profit_change( 0 ), TBT( 0 ), TBT_change( 0 ) { };
30 /** Structure to hold data for each vehicle */
31 struct TripHistory {
32 // a lot of saveload stuff for std::deque. So...
33 TripHistoryEntry t[ TRIP_LENGTH ];
35 Money total_profit;
36 int32 avg_daylength;
37 int32 total_change;
38 Money profit_per_day;
40 TripHistory( ) :
41 total_profit( 0 ),
42 avg_daylength( 0 ),
43 total_change( 0 ),
44 profit_per_day( 0 ) { }
46 void NewRound();
48 void AddValue( Money mvalue, Date dvalue );
51 /**
52 * Init info for GUI
54 * @return size_t number of valid rows
56 size_t UpdateCalculated( );
58 int32 FindPercentChange( Money v1, Money v2 ) {
59 float temp;
61 if ( v1 > v2 ) {
62 temp = v1 - v2;
63 return TripHistoryRound( ( float ) temp * 100 / ( float ) v1 );
66 if ( v2 > v1 ) {
67 temp = v1 - v2;
68 return TripHistoryRound( ( float ) temp * 100 / ( float ) v2 );
71 return 0;
75 #endif /* TRIPHISTORY_H */