Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Talker vehicle and EOCs for vehicles #77564

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Ramza13
Copy link
Contributor

@Ramza13 Ramza13 commented Nov 3, 2024

Summary

Infrastructure "EOCs for vehicles"

Purpose of change

Implements #74511
Allow EOCs on vehicles

Describe the solution

Added talker vehicle and implemented some new talker functions for it. Right now the only way to access a vehicle with EOC's is to us the new "u_run_vehicle_eocs" eoc effect or when the "vehicle_moves" event fires. The only effect that works on vehicles is teleport.

Describe alternatives you've considered

So, so many. There are all kinds of powers I could hook up but I'm not sure what would actually get used and design choices would need to be made. Stuff like having vehicles run EOC's the way characters do, turning on/off power/engines. Please comment on this or create an issue and tag me if there is something you'd like to see added to this.

Testing

I used the following json


  {
    "type": "effect_on_condition",
    "id": "TEST_VEHICLE",
    "eoc_type": "EVENT",
    "required_event": "vehicle_moves",
    "condition":"u_is_vehicle",
    "effect": [ 
      { "math": [ "test_veh", "=", "u_val('pos_x')" ] },
      { "math": [ "test_veh_facing", "=", "u_val('vehicle_facing')" ] },
      { "math": [ "test_veh_speed", "=", "u_val('current_speed')" ] },
      { "math": [ "test_veh_unloaded_weight", "=", "u_val('unloaded_weight')" ] },
      { "math": [ "test_veh_friends", "=", "u_val('friendly_passenger_count')" ] },
      { "math": [ "test_veh_foes", "=", "u_val('hostile_passenger_count')" ] }
    ]
  },  
  {
    "type": "effect_on_condition",
    "id": "AAATEST_VEHICLE_Activate_Far",
    "effect": [ 
      {"u_run_vehicle_eocs":["TEST_NOT_VEHICLE"]}
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "TEST_NOT_VEHICLE",
    "condition":"u_is_vehicle",
    "effect": [ 
      { "u_location_variable": { "global_val": "stuck_teleport" }, "min_radius": 0, "max_radius": 0, "x_adjust": -200 },
      { "u_teleport": { "global_val": "stuck_teleport" }, "success_message": "The car moves.", "fail_message": "The car does not move." } ]
  },
  {
    "type": "effect_on_condition",
    "id": "AAATEST_VEHICLE_Activate_Close",
    "effect": [ 
      {"u_run_vehicle_eocs":["TEST_NOT_VEHICLE_Close"]}
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "TEST_NOT_VEHICLE_Close",
    "condition":"u_is_vehicle",
    "effect": [ 
      { "u_location_variable": { "global_val": "stuck_teleport" }, "min_radius": 0, "max_radius": 0, "x_adjust": -2 },
      { "u_teleport": { "global_val": "stuck_teleport" }, "success_message": "The car moves.", "fail_message": "The car does not move." } ]
  },
  {
    "type": "effect_on_condition",
    "id": "AAATEST_VEHICLE_Activate_Up",
    "effect": [ 
      {"u_run_vehicle_eocs":["TEST_NOT_VEHICLE_Up"]}
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "TEST_NOT_VEHICLE_Up",
    "condition":"u_is_vehicle",
    "effect": [ 
      { "u_location_variable": { "global_val": "stuck_teleport" }, "min_radius": 0, "max_radius": 0, "z_adjust": 2 },
      { "u_teleport": { "global_val": "stuck_teleport" }, "success_message": "The car moves.", "fail_message": "The car does not move." } ]
  }

Additional context

@GuardianDll
Copy link
Member

i guess it would conflict with #77485 much?

@github-actions github-actions bot added <Documentation> Design documents, internal info, guides and help. NPC / Factions NPCs, AI, Speech, Factions, Ownership Translation I18n Bionics CBM (Compact Bionic Modules) Vehicles Vehicles, parts, mechanics & interactions [C++] Changes (can be) made in C++. Previously named `Code` Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. [Markdown] Markdown issues and PRs [Python] Code made in Python Mechanics: Enchantments / Spells Enchantments and spells EOC: Effects On Condition Anything concerning Effects On Condition Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Nov 3, 2024
@github-actions github-actions bot requested a review from KorGgenT November 3, 2024 19:33
Copy link
Contributor

@andrei8l andrei8l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick review only. IMO this should wait for #77485 because that PR is already enormous.

Comment on lines +265 to +285
// first, let's find our position in current vehicles vector
size_t our_i = 0;
bool found = false;
for( submap *&smap : here.grid ) {
for( size_t i = 0; i < smap->vehicles.size(); i++ ) {
if( smap->vehicles[i].get() == &veh ) {
our_i = i;
src_submap = smap;
found = true;
break;
}
}
if( found ) {
break;
}
}

if( !found ) {
add_msg_debug( debugmode::DF_MAP, "displace_vehicle [%s] failed", veh.name );
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// first, let's find our position in current vehicles vector
size_t our_i = 0;
bool found = false;
for( submap *&smap : here.grid ) {
for( size_t i = 0; i < smap->vehicles.size(); i++ ) {
if( smap->vehicles[i].get() == &veh ) {
our_i = i;
src_submap = smap;
found = true;
break;
}
}
if( found ) {
break;
}
}
if( !found ) {
add_msg_debug( debugmode::DF_MAP, "displace_vehicle [%s] failed", veh.name );
return false;
}
src_submap = here.get_submap_at_grid( veh.sm_pos.xy() );

For master it's probably src_submap = here.get_submap_at_grid( point_rel_sm{ veh.sm_pos.xy() } ); though. It needs the change below too.

dst_submap->ensure_nonuniform();
veh.set_submap_moved( tripoint( here.bub_from_abs( dp ).x() / SEEX,
here.bub_from_abs( dp ).y() / SEEY, dp.z() ) );
auto src_submap_veh_it = src_submap->vehicles.begin() + our_i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto src_submap_veh_it = src_submap->vehicles.begin() + our_i;
auto src_submap_veh_it =
std::find_if( src_submap->vehicles.begin(), src_submap->vehicles.end(),
[&veh]( std::unique_ptr<vehicle> const & v ) {
return v.get() == &veh;
} );

@@ -217,3 +222,195 @@ bool teleport::teleport_to_point( Creature &critter, tripoint target, bool safe,
}
return true;
}

bool teleport::teleport_vehicle( vehicle &veh, const tripoint_abs_ms &dp )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you break this function down into logical units?


class Creature;

namespace teleport
class vehicle;

This comment was marked as resolved.

Comment on lines +5472 to +5474
if( jo.has_int( "vehicle_range" ) ) {
vehicle_range = jo.get_int( "vehicle_range" );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs more selection criteria to be useful. But for that we need an in-game use case.

@Ramza13 Ramza13 marked this pull request as draft November 6, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bionics CBM (Compact Bionic Modules) [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style <Documentation> Design documents, internal info, guides and help. EOC: Effects On Condition Anything concerning Effects On Condition Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. [Markdown] Markdown issues and PRs Mechanics: Enchantments / Spells Enchantments and spells NPC / Factions NPCs, AI, Speech, Factions, Ownership [Python] Code made in Python Translation I18n Vehicles Vehicles, parts, mechanics & interactions
Projects
Status: Abandoned PRs with no one to pick them up
Development

Successfully merging this pull request may close these issues.

3 participants