Skip to content

Commit 6b23cd4

Browse files
committed
FIX: Public player cannot replace wayobjs of other players
Fix the behaiour to match the one for ways. Normal players were already allowed to replace wayobjs belonging to the public player. git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11727 8aca7d54-2c30-db11-9de9-000461428c89
1 parent 8246850 commit 6b23cd4

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

simutrans/history.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
FIX: multitile city building totally renovated, 3x faster city growth (at the start of the map in debug mode)
1414
ADD: (mostly Yona-TYT) flowtext recognised img tag. For now only tags "#?XXX" are supported, where ? is one of these letter GSDTW and XXX a number. G is a general tool icon, S and simple tool, D is dialog tool, T a toolbar and W and window gadget.
1515
CHG: default signal spacing for dragiing to 5 (as 4 and smaller can slow down trains faster than 200 km/h)
16+
FIX: Public player cannot replace wayobjs of other players
1617

1718

1819
Release of 124.3.1 (r11671 on 5-Apr-2025):

src/simutrans/obj/wayobj.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,16 @@ void wayobj_t::calc_image()
361361

362362
/* better use this constrcutor for new wayobj; it will extend a matching obj or make an new one
363363
*/
364-
void wayobj_t::extend_wayobj(koord3d pos, player_t *owner, ribi_t::ribi dir, const way_obj_desc_t *desc, bool keep_existing_faster_way)
364+
void wayobj_t::extend_wayobj(koord3d pos, player_t *new_owner, ribi_t::ribi dir, const way_obj_desc_t *desc, bool keep_existing_faster_way)
365365
{
366366
grund_t *gr=welt->lookup(pos);
367367
if(gr) {
368368
wayobj_t *existing_wayobj = gr->get_wayobj( desc->get_wtyp() );
369369
if( existing_wayobj ) {
370-
if( ( existing_wayobj->get_desc()->get_topspeed() < desc->get_topspeed() || !keep_existing_faster_way) && player_t::check_owner(owner, existing_wayobj->get_owner())
371-
&& existing_wayobj->get_desc() != desc )
372-
{
370+
const bool is_speed_ok = existing_wayobj->get_desc()->get_topspeed() < desc->get_topspeed() || !keep_existing_faster_way;
371+
const bool is_owner_ok = player_t::check_owner(new_owner, existing_wayobj->get_owner()) || new_owner == welt->get_public_player();
372+
373+
if( is_speed_ok && is_owner_ok && existing_wayobj->get_desc() != desc) {
373374
// replace slower by faster if desired
374375
dir = dir | existing_wayobj->get_dir();
375376
gr->set_flag(grund_t::dirty);
@@ -386,13 +387,13 @@ void wayobj_t::extend_wayobj(koord3d pos, player_t *owner, ribi_t::ribi dir, con
386387
}
387388

388389
// nothing found => make a new one
389-
wayobj_t *wo = new wayobj_t(pos,owner,dir,desc);
390+
wayobj_t *wo = new wayobj_t(pos,new_owner,dir,desc);
390391
gr->obj_add(wo);
391392
wo->finish_rd();
392393
wo->calc_image();
393394
wo->mark_image_dirty( wo->get_front_image(), 0 );
394395
wo->set_flag(obj_t::dirty);
395-
player_t::book_construction_costs( owner, -desc->get_price(), pos.get_2d(), desc->get_wtyp());
396+
player_t::book_construction_costs( new_owner, -desc->get_price(), pos.get_2d(), desc->get_wtyp());
396397

397398
for( uint8 i = 0; i < 4; i++ ) {
398399
// Extend wayobjects around the new one, that aren't already connected.

tests/all_tests.nut

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,6 @@ all_tests <- [
233233
test_wayobj_build_straight,
234234
test_wayobj_build_disconnected,
235235
test_wayobj_upgrade_downgrade,
236+
test_wayobj_upgrade_change_owner,
236237
test_wayobj_electrify_depot
237238
]

tests/tests/test_wayobj.nut

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,55 @@ function test_wayobj_upgrade_downgrade()
234234
}
235235

236236

237+
function test_wayobj_upgrade_change_owner()
238+
{
239+
local pl = player_x(0)
240+
local public_pl = player_x(1)
241+
242+
local wobj_remover = command_x(tool_remove_wayobj)
243+
local rail = way_desc_x.get_available_ways(wt_rail, st_flat)[0]
244+
local catenaries = wayobj_desc_x.get_available_wayobjs(wt_rail).filter(@(idx, wobj) wobj.is_overhead_line())
245+
catenaries.sort(@(a, b) a.get_topspeed() <=> b.get_topspeed())
246+
247+
// FIXME need at least 2 catenaries
248+
ASSERT_TRUE(catenaries.len() >= 1)
249+
local slow_cat = catenaries[0]
250+
local fast_cat = catenaries[1]
251+
252+
ASSERT_EQUAL(command_x.build_way(pl, coord3d(3, 4, 0), coord3d(5, 4, 0), rail, true), null)
253+
254+
// public player: replace catenary of normal player
255+
{
256+
local builder = command_x(tool_build_wayobj)
257+
258+
ASSERT_EQUAL(command_x.build_wayobj(pl, coord3d(3, 4, 0), coord3d(5, 4, 0), slow_cat), null)
259+
ASSERT_EQUAL(command_x.build_wayobj(public_pl, coord3d(3, 4, 0), coord3d(5, 4, 0), fast_cat), null)
260+
261+
ASSERT_TRUE(tile_x(3, 4, 0).find_object(mo_wayobj).get_desc().is_equal(fast_cat))
262+
ASSERT_EQUAL(tile_x(3, 4, 0).find_object(mo_wayobj).get_owner().get_name(), public_pl.get_name())
263+
264+
ASSERT_EQUAL(wobj_remover.work(public_pl, coord3d(3, 4, 0), coord3d(5, 4, 0), "" + wt_rail), null)
265+
}
266+
267+
// normal player: replace caterary of public player
268+
{
269+
local builder = command_x(tool_build_wayobj)
270+
271+
ASSERT_EQUAL(command_x.build_wayobj(public_pl, coord3d(3, 4, 0), coord3d(5, 4, 0), slow_cat), null)
272+
ASSERT_EQUAL(command_x.build_wayobj(pl, coord3d(3, 4, 0), coord3d(5, 4, 0), fast_cat), null)
273+
274+
ASSERT_TRUE(tile_x(3, 4, 0).find_object(mo_wayobj).get_desc().is_equal(fast_cat))
275+
ASSERT_EQUAL(tile_x(3, 4, 0).find_object(mo_wayobj).get_owner().get_name(), pl.get_name())
276+
277+
ASSERT_EQUAL(wobj_remover.work(pl, coord3d(3, 4, 0), coord3d(5, 4, 0), "" + wt_rail), null)
278+
}
279+
280+
// clean up
281+
ASSERT_EQUAL(command_x(tool_remove_way).work(pl, coord3d(3, 4, 0), coord3d(5, 4, 0), "" + wt_rail), null)
282+
RESET_ALL_PLAYER_FUNDS()
283+
}
284+
285+
237286
function test_wayobj_electrify_depot()
238287
{
239288
local pl = player_x(0)

0 commit comments

Comments
 (0)