Skip to content

Commit

Permalink
Allow auto targeting mode for turrets only with installed turret cont…
Browse files Browse the repository at this point in the history
…rol unit (#34202)

* Added turret control unit

* Made it craftable (autolearn)

* Added corresponding vehicle part

* Added flag to bitflags set

* Added documentation

* Forcibly set turrets' targeting mode to manual if no turret control unit is present on turret's tile on loading save

* Allow changing turrets' targeting mode only if turret control unit is present

Also reworded targeting mode options a bit to reduce confusing.
Also removed a check for MANUAL flag as there is no items or vehicle parts with this flag.
Also reworded reason of why you can't aim automatic turrets and added a missing period.

* Turret controls must be installed on a turret

Also, on removing turret controls forcibly set targeting mode of affected turret to manual.

* Set turret control unit's state equal to turret's targeting mode

* Increased control unit power draw

* Added a requirement for laptop computer

Also inreased craft time to 2 hours.

* Added mechanics skill req for crafting TCU

Also increased its power consumption from 100W to 250W.
  • Loading branch information
Night-Pryanik authored and ZhilkinSerg committed Oct 16, 2019
1 parent 772f8c6 commit b914b50
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 5 deletions.
12 changes: 12 additions & 0 deletions data/json/items/vehicle/controls.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,17 @@
"bashing": 1,
"price": 20000,
"copy-from": "vehicle_controls"
},
{
"type": "GENERIC",
"id": "turret_controls",
"name": "turret control unit",
"description": "A set of motor, camera, and various electronic modules banded together to allow for tracking targets, friend-or-foe identification, and firing the connected turret in full automatic mode.",
"weight": "4000 g",
"color": "white",
"symbol": "&",
"volume": "9 L",
"price": 500000,
"copy-from": "vehicle_controls"
}
]
22 changes: 22 additions & 0 deletions data/json/recipes/recipe_vehicle.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,5 +392,27 @@
"using": [ [ "welding_standard", 1 ] ],
"qualities": [ { "id": "DRILL", "level": 3 } ],
"components": [ [ [ "scrap", 2 ] ] ]
},
{
"type": "recipe",
"result": "turret_controls",
"category": "CC_OTHER",
"subcategory": "CSC_OTHER_VEHICLE",
"skill_used": "electronics",
"skills_required": [ [ "computer", 5 ], [ "mechanics", 3 ] ],
"difficulty": 5,
"time": "2 h",
"autolearn": true,
"using": [ [ "soldering_standard", 10 ] ],
"qualities": [ { "id": "SCREW", "level": 1 } ],
"tools": [ [ [ "laptop", -1 ] ] ],
"components": [
[ [ "targeting_module", 1 ] ],
[ [ "ai_module", 1 ] ],
[ [ "gun_module", 1 ] ],
[ [ "cable", 10 ] ],
[ [ "omnicamera", 1 ] ],
[ [ "robot_controls", 1 ] ]
]
}
]
26 changes: 26 additions & 0 deletions data/json/vehicleparts/vehicle_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -3100,5 +3100,31 @@
"flags": [ "TURRET_MOUNT" ],
"breaks_into": [ { "item": "scrap", "count": [ 1, 4 ] } ],
"damage_reduction": { "all": 54 }
},
{
"type": "vehicle_part",
"id": "controls_turret",
"name": "turret control unit",
"symbol": "$",
"color": "yellow",
"broken_symbol": "$",
"broken_color": "red",
"damage_modifier": 10,
"durability": 50,
"epower": -250,
"item": "turret_controls",
"description": "A set of motor, camera, and an AI unit which allows for tracking targets, friend-or-foe identification, and firing the connected turret in full automatic mode. When installed over the turret, it will enable auto targeting mode for said turret.",
"folded_volume": 3,
"flags": [ "ENABLED_DRAINS_EPOWER", "TURRET_CONTROLS", "UNMOUNT_ON_DAMAGE" ],
"requirements": {
"install": {
"time": 120000,
"skills": [ [ "mechanics", 3 ], [ "electronics", 3 ] ],
"qualities": [ { "id": "SCREW", "level": 1 } ]
},
"repair": { "skills": [ [ "mechanics", 2 ] ], "time": 8000, "using": [ [ "adhesive", 1 ] ] },
"removal": { "skills": [ [ "mechanics", 3 ] ], "qualities": [ { "id": "SCREW", "level": 1 } ] }
},
"breaks_into": "ig_vp_device"
}
]
1 change: 1 addition & 0 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ Those flags are added by the game code to specific items (that specific welder,
- ```TOWEL``` Can be used to dry yourself up.
- ```TRACKED``` Contributes to steering effectiveness but doesn't count as a steering axle for install difficulty and still contributes to drag for the center of steering calculation.
- ```TRACK``` Allows the vehicle installed on, to be marked and tracked on map.
- ```TURRET_CONTROLS``` If part with this flag is installed over the turret, it allows to set said turret's targeting mode to full auto.
- ```TURRET_MOUNT``` Parts with this flag are suitable for installing turrets.
- ```TURRET``` Is a weapon turret. Can only be installed on a part with ```TURRET_MOUNT``` flag.
- ```UNMOUNT_ON_DAMAGE``` Part breaks off the vehicle when destroyed by damage.
Expand Down
9 changes: 9 additions & 0 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2514,6 +2514,15 @@ void vehicle::deserialize( JsonIn &jsin )

for( const vpart_reference &vp : get_any_parts( "TURRET" ) ) {
install_part( vp.mount(), vpart_id( "turret_mount" ), false );

//Forcibly set turrets' targeting mode to manual if no turret control unit is present on turret's tile on loading save
if( !has_part( global_part_pos3( vp.part() ), "TURRET_CONTROLS" ) ) {
vp.part().enabled = false;
}
//Set turret control unit's state equal to turret's targeting mode on loading save
for( const vpart_reference &turret_part : get_any_parts( "TURRET_CONTROLS" ) ) {
turret_part.part().enabled = vp.part().enabled;
}
}

// Add vehicle mounts to cars that are missing them.
Expand Down
23 changes: 18 additions & 5 deletions src/turret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,16 @@ void vehicle::turrets_set_targeting()
{
std::vector<vehicle_part *> turrets;
std::vector<tripoint> locations;
std::vector<vehicle_part *> turret_controls;

for( auto &p : parts ) {
if( p.base.is_gun() && !p.info().has_flag( "MANUAL" ) ) {
if( p.base.is_gun() ) {
turrets.push_back( &p );
locations.push_back( global_part_pos3( p ) );
}
if( part_flag( index_of_part( &p ), "TURRET_CONTROLS" ) ) {
turret_controls.push_back( &p );
}
}

pointmenu_cb callback( locations );
Expand All @@ -312,8 +316,11 @@ void vehicle::turrets_set_targeting()
menu.w_y = 2;

for( auto &p : turrets ) {
menu.addentry( -1, true, MENU_AUTOASSIGN, "%s [%s]", p->name(),
p->enabled ? _( "auto" ) : _( "manual" ) );
menu.addentry( -1, has_part( global_part_pos3( *p ), "TURRET_CONTROLS" ), MENU_AUTOASSIGN,
"%s [%s]", p->name(), p->enabled ?
_( "auto -> manual" ) : has_part( global_part_pos3( *p ), "TURRET_CONTROLS" ) ?
_( "manual -> auto" ) :
_( "manual (turret control unit required for auto mode)" ) );
}

menu.query();
Expand All @@ -322,7 +329,12 @@ void vehicle::turrets_set_targeting()
}

sel = menu.ret;
turrets[ sel ]->enabled = !turrets[ sel ]->enabled;
if( has_part( locations[ sel ], "TURRET_CONTROLS" ) ) {
turrets[sel]->enabled = !turrets[sel]->enabled;
turret_controls[sel]->enabled = turrets[sel]->enabled;
} else {
turrets[sel]->enabled = false;
}

// clear the turret's current targets to prevent unwanted auto-firing
tripoint pos = locations[ sel ];
Expand Down Expand Up @@ -381,7 +393,8 @@ bool vehicle::turrets_aim( bool manual, bool automatic, vehicle_part *tur_part )
} ), last );

if( opts.empty() ) {
add_msg( m_warning, _( "Can't aim turrets: all turrets are offline" ) );
add_msg( m_warning,
_( "Can't aim turrets: all turrets are offline or set to manual targeting mode." ) );
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/veh_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static const std::unordered_map<std::string, vpart_bitflags> vpart_bitflag_map =
{ "FLUIDTANK", VPFLAG_FLUIDTANK },
{ "REACTOR", VPFLAG_REACTOR },
{ "RAIL", VPFLAG_RAIL },
{ "TURRET_CONTROLS", VPFLAG_TURRET_CONTROLS },
};

static const std::vector<std::pair<std::string, veh_ter_mod>> standard_terrain_mod = {{
Expand Down
1 change: 1 addition & 0 deletions src/veh_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum vpart_bitflags : int {
VPFLAG_FLUIDTANK,
VPFLAG_REACTOR,
VPFLAG_RAIL,
VPFLAG_TURRET_CONTROLS,

NUM_VPFLAGS
};
Expand Down
17 changes: 17 additions & 0 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,20 @@ bool vehicle::can_mount( const point &dp, const vpart_id &id ) const
}
}

//Turret controls must be installed on a turret
if( part.has_flag( "TURRET_CONTROLS" ) ) {
bool anchor_found = false;
for( const auto &elem : parts_in_square ) {
if( part_info( elem ).has_flag( "TURRET" ) ) {
anchor_found = true;
break;
}
}
if( !anchor_found ) {
return false;
}
}

//Anything not explicitly denied is permitted
return true;
}
Expand Down Expand Up @@ -5289,6 +5303,9 @@ void vehicle::refresh()
} else if( !camera_on && vpi.has_flag( "CAMERA" ) ) {
vp.part().enabled = false;
}
if( vpi.has_flag( "TURRET" ) && !has_part( global_part_pos3( vp.part() ), "TURRET_CONTROLS" ) ) {
vp.part().enabled = false;
}
}

rail_wheel_bounding_box.p1 = point( railwheel_xmin, railwheel_ymin );
Expand Down

0 comments on commit b914b50

Please sign in to comment.