Skip to content

Commit

Permalink
CHG: Records are now saved so less spamming with new records
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11304 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Jun 21, 2024
1 parent 5534615 commit 04af624
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
48 changes: 42 additions & 6 deletions src/simutrans/dataobj/records.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,45 @@
*/

#include "records.h"
#include "../dataobj/translator.h"
#include "loadsave.h"
#include "translator.h"
#include "../player/simplay.h"
#include "../simcolor.h"
#include "../simmesg.h"
#include "../simconvoi.h"
#include "../utils/cbuffer.h"
#include "../utils/simstring.h"
#include "../vehicle/vehicle.h"

#include "../macros.h"


void records_t::speed_record_t::rdwr(loadsave_t* f)
{
f->rdwr_long(speed);
f->rdwr_long(year_month);
pos.rdwr(f);
f->rdwr_byte(player_nr);
if (f->is_loading()) {
// for now it is not saved
cnv = convoihandle_t();
}
f->rdwr_str(name, lengthof(name));
}


void records_t::rdwr(loadsave_t* f)
{
max_rail_speed.rdwr(f);
max_monorail_speed.rdwr(f);
max_maglev_speed.rdwr(f);
max_narrowgauge_speed.rdwr(f);
max_road_speed.rdwr(f);
max_ship_speed.rdwr(f);
max_air_speed.rdwr(f);
}


sint32 records_t::get_record_speed( waytype_t w ) const
{
switch(w) {
Expand All @@ -27,6 +58,7 @@ sint32 records_t::get_record_speed( waytype_t w ) const
}
}


void records_t::clear_speed_records()
{
max_road_speed.speed = 0;
Expand All @@ -38,6 +70,7 @@ void records_t::clear_speed_records()
max_air_speed.speed = 0;
}


void records_t::notify_record( convoihandle_t cnv, sint32 max_speed, koord3d k, uint32 current_month )
{
speed_record_t *sr = NULL;
Expand All @@ -60,23 +93,25 @@ void records_t::notify_record( convoihandle_t cnv, sint32 max_speed, koord3d k,

// really new/faster?
if(k!=sr->pos || sr->speed+1<max_speed) {
// update it
// update it first and notify if a repeat was achieved to avoid spamming messages
sr->cnv = cnv;
sr->speed = max_speed-1;
sr->year_month = current_month;
sr->pos = k;
sr->owner = NULL; // will be set, when accepted
sr->player_nr = PLAYER_UNOWNED; // will be set, when accepted
}
else {
// repeted same speed, same place
sr->cnv = cnv;
sr->speed = max_speed-1;
sr->pos = k;

// same convoi and same position
if(sr->owner==NULL && current_month!=sr->year_month) {
if(sr->player_nr==PLAYER_UNOWNED && current_month!=sr->year_month) {
// notify the world of this new record
sr->speed = max_speed-1;
sr->owner = cnv->get_owner();
sr->player_nr = cnv->get_owner()->get_player_nr();
tstrncpy(sr->name, cnv->get_internal_name(), lengthof(sr->name));
const char* text;
switch (cnv->front()->get_waytype()) {
default: NOT_REACHED
Expand All @@ -91,7 +126,8 @@ void records_t::notify_record( convoihandle_t cnv, sint32 max_speed, koord3d k,
}
cbuffer_t buf;
buf.printf( translator::translate(text), speed_to_kmh(10*sr->speed)/10.0, sr->cnv->get_name() );
msg->add_message( buf, sr->pos, message_t::new_vehicle|message_t::DO_NOT_SAVE_MSG, PLAYER_FLAG|sr->owner->get_player_nr() );

msg->add_message( buf, sr->pos, message_t::new_vehicle, PLAYER_FLAG|sr->player_nr );
}
}
}
12 changes: 9 additions & 3 deletions src/simutrans/dataobj/records.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class message_t;
class player_t;
class loadsave_t;

/**
* World record speed management.
Expand All @@ -32,6 +33,8 @@ class records_t {
/** Resets all speed records. */
void clear_speed_records();

void rdwr(loadsave_t* f);

private:
// Destination for world record notifications.
message_t *msg;
Expand All @@ -42,12 +45,15 @@ class records_t {
class speed_record_t {
public:
convoihandle_t cnv;
char name[128];
sint32 speed;
koord3d pos;
player_t *owner; // Owner
koord3d pos;
sint8 player_nr; // Owner
uint32 year_month;

speed_record_t() : cnv(), speed(0), pos(koord3d::invalid), owner(NULL), year_month(0) {}
speed_record_t() : cnv(), speed(0), pos(koord3d::invalid), player_nr(PLAYER_UNOWNED), year_month(0) { name[0] = 0; }

void rdwr(loadsave_t* f);
};

/// World rail speed record
Expand Down
6 changes: 3 additions & 3 deletions src/simutrans/simversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#define SIM_VERSION_MAJOR 124
#define SIM_VERSION_MINOR 1
#define SIM_VERSION_PATCH 1
#define SIM_VERSION_BUILD SIM_BUILD_NIGHTLY
#define SIM_VERSION_BUILD SIM_BUILD_RELEASE_CANDIDATE

// Beware: SAVEGAME minor is often ahead of version minor when there were patches.
// ==> These have no direct connection at all!
#define SIM_SAVE_MINOR 1
#define SIM_SERVER_MINOR 1
#define SIM_SAVE_MINOR 2
#define SIM_SERVER_MINOR 2
// NOTE: increment before next release to enable save/load of new features

#define MAKEOBJ_VERSION "60.7"
Expand Down
8 changes: 8 additions & 0 deletions src/simutrans/world/simworld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3707,6 +3707,10 @@ DBG_MESSAGE("karte_t::save(loadsave_t *file)", "motd filename %s", env_t::server
chat_msg->rdwr(file);
}

if (file->is_version_atleast(124, 2)) {
records->rdwr(file);
}

file->rdwr_byte( active_player_nr );

// save all open windows (upon request)
Expand Down Expand Up @@ -4251,6 +4255,10 @@ DBG_MESSAGE("karte_t::load()", "%d factories loaded", fab_list.get_count());
// maybe move messages into chat_messages?
}

if (file->is_version_atleast(124, 2)) {
records->rdwr(file);
}

if( file->is_version_atleast(102, 4) ) {
if( env_t::restore_UI ) {
file->rdwr_byte( active_player_nr );
Expand Down

0 comments on commit 04af624

Please sign in to comment.