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

Prone move mode #46750

Merged
merged 33 commits into from
Aug 8, 2021
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1a5c01b
Added lying down on the ground, is_on_ground() returns true for lying…
J-Cieplinski Jan 14, 2021
7ca6a4a
Merge branch 'master' into proneSleep
J-Cieplinski Jan 14, 2021
51393c8
astyle run
J-Cieplinski Jan 14, 2021
fd41d6e
Update src/activity_actor.cpp
J-Cieplinski Jan 15, 2021
a48274d
changed lying down to prone where appropiate, sound change when prone
J-Cieplinski Jan 15, 2021
7a04ee8
changes position to prone if trying to move with both legs broken and…
J-Cieplinski Jan 16, 2021
50d6fdc
creature should be less visible when prone
J-Cieplinski Jan 16, 2021
52dc27a
astyle run and value initialization
J-Cieplinski Jan 16, 2021
e693355
changed on the ground check for roller blade knockdown and being on fire
J-Cieplinski Jan 16, 2021
d5fb976
changed splints to crutches, added crutch flag, added crutch item, ad…
J-Cieplinski Jan 22, 2021
1a58a46
rename, crutch flag check
J-Cieplinski Jan 22, 2021
1020898
astyle run
J-Cieplinski Jan 22, 2021
471409f
removed unnecessary comments
J-Cieplinski Jan 22, 2021
4483773
Merge branch 'master' into proneSleep
J-Cieplinski Jan 25, 2021
02119f2
Update data/json/items/melee/bludgeons.json
J-Cieplinski Jan 25, 2021
7671474
Update data/json/move_modes.json
J-Cieplinski Jan 25, 2021
f832851
removed duplicate crtuches id flag
J-Cieplinski Jan 25, 2021
e148aae
cannot melee attack with crutches when legs are broken
J-Cieplinski Jan 25, 2021
b33be5e
changed to check only for working leg count. It doesnt matter if you …
J-Cieplinski Jan 25, 2021
6af0ae9
Update src/move_mode.cpp
J-Cieplinski Jan 26, 2021
50bc506
Update src/avatar_action.cpp
J-Cieplinski Jan 26, 2021
e59d533
Update data/json/move_modes.json
J-Cieplinski Jan 26, 2021
583e81c
getting up after waking up, prone move type in json, text after falli…
J-Cieplinski Jan 27, 2021
019b9a6
Merge branch 'proneSleep' of https://github.com/J-Cieplinski/Cataclys…
J-Cieplinski Jan 27, 2021
d6a5b12
Update src/melee.cpp
J-Cieplinski Jan 28, 2021
f99eb17
Update src/melee.cpp
J-Cieplinski Jan 28, 2021
69e7fd9
Update src/avatar_action.cpp
J-Cieplinski Jan 28, 2021
cc55bc7
astyle check
J-Cieplinski Jan 29, 2021
76d2579
Update src/move_mode.cpp
J-Cieplinski Mar 12, 2021
1e35df7
Update src/avatar_action.cpp
J-Cieplinski Mar 12, 2021
039765b
Update data/json/items/melee/bludgeons.json
J-Cieplinski Mar 12, 2021
21f8f35
Merge branch 'master' into proneSleep
J-Cieplinski Jul 11, 2021
b7bc3ef
Apply suggestions from code review
ZhilkinSerg Aug 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/json/flags.json
Original file line number Diff line number Diff line change
@@ -1218,6 +1218,11 @@
"type": "json_flag",
"context": [ ]
},
{
"id": "CRUTCHES",
"type": "json_flag",
"context": [ ]
},
J-Cieplinski marked this conversation as resolved.
Show resolved Hide resolved
{
"id": "CUSTOM_EXPLOSION",
"type": "json_flag",
21 changes: 20 additions & 1 deletion data/json/items/melee/bludgeons.json
Original file line number Diff line number Diff line change
@@ -337,13 +337,32 @@
"symbol": "/",
"material": [ "wood", "aluminum" ],
"techniques": [ "WBLOCK_1" ],
"flags": [ "NONCONDUCTIVE" ],
"flags": [ "NONCONDUCTIVE", "CRUTCHES" ],
"volume": "1 L",
"longest_side": "80 cm",
"bashing": 10,
"price": 16000,
"price_postapoc": 100
},
{
"id": "crutches",
"type": "GENERIC",
"symbol": "/",
"color": "dark_gray",
"name": { "str": "crutches", "str_pl": "pairs of crutches" },
"description": "A pair of crutches.",
"price": 2500,
"material": [ "aluminum" ],
"techniques": [ "WBLOCK_1", "SWEEP" ],
"flags": [ "CRUTCHES" ],
"weight": "2200 g",
"volume": "1500 ml",
"longest_side": "150 cm",
"bashing": 24,
J-Cieplinski marked this conversation as resolved.
Show resolved Hide resolved
J-Cieplinski marked this conversation as resolved.
Show resolved Hide resolved
"to_hit": 2,
"price_postapoc": 1250,
"category": "weapons"
},
{
"type": "GENERIC",
"id": "cudgel",
17 changes: 17 additions & 0 deletions data/json/move_modes.json
Original file line number Diff line number Diff line change
@@ -52,5 +52,22 @@
"sound_multiplier": 0.5,
"move_speed_multiplier": 0.5,
"swim_speed_mod": 50
},
{
"type": "movement_mode",
"id": "prone",
"character": "p",
"panel_char": "P",
"name": "prone",
"panel_color": "green",
"symbol_color": "blue",
"exertion_level": "NO_EXERCISE",
"change_good_none": "You lie down.",
"change_good_animal": "You stop your steed.",
"change_good_mech": "You turn off your mech's leg servos.",
"move_type": "prone",
"sound_multiplier": 0.2,
"move_speed_multiplier": 0.2,
"swim_speed_mod": 50
}
]
2 changes: 2 additions & 0 deletions src/action.h
Original file line number Diff line number Diff line change
@@ -66,6 +66,8 @@ enum action_id : int {
ACTION_TOGGLE_RUN,
/** Toggle crouch on/off */
ACTION_TOGGLE_CROUCH,
/** Toggle lying down on/off */
ACTION_TOGGLE_PRONE,
/** Open movement mode menu */
ACTION_OPEN_MOVEMENT,
/**@}*/
5 changes: 4 additions & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
@@ -1587,10 +1587,12 @@ std::unique_ptr<activity_actor> consume_activity_actor::deserialize( JsonIn &jsi
return actor.clone();
}

void try_sleep_activity_actor::start( player_activity &act, Character &/*who*/ )
void try_sleep_activity_actor::start( player_activity &act, Character &who )
{
act.moves_total = to_moves<int>( duration );
act.moves_left = act.moves_total;
who.set_movement_mode( move_mode_id( "prone" ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

When the player wake up, do they need to manually switch back to walking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Laying down to sleep is a conscious effort. Waking up is not. As such i think switching back to walking should be manual

Copy link
Contributor

@Qrox Qrox Jan 26, 2021

Choose a reason for hiding this comment

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

There are other actions that require conscious effort but is done automatically anyway, for example assignment of containers to inventory items. Not automatically switching back to walking might confuse players (especially those updating from an earlier version and are used to waking up in walking mode).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not hung up on it so I can add that, no problem.

who.add_msg_if_player( _( "You lie down preparing to fall asleep." ) );
}

void try_sleep_activity_actor::do_turn( player_activity &act, Character &who )
@@ -1621,6 +1623,7 @@ void try_sleep_activity_actor::finish( player_activity &act, Character &who )
if( !who.has_effect( effect_sleep ) ) {
who.add_msg_if_player( _( "You try to sleep, but can't." ) );
}
who.set_movement_mode( move_mode_id( "walk" ) );
}

void try_sleep_activity_actor::query_keep_trying( player_activity &act, Character &who )
9 changes: 9 additions & 0 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
@@ -1396,6 +1396,15 @@ void avatar::toggle_crouch_mode()
}
}

void avatar::toggle_prone_mode()
{
if( is_prone() ) {
set_movement_mode( move_mode_id( "walk" ) );
} else {
set_movement_mode( move_mode_id( "prone" ) );
}
}

ZhilkinSerg marked this conversation as resolved.
Show resolved Hide resolved
void avatar::activate_crouch_mode()
{
if( !is_crouching() ) {
2 changes: 2 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
@@ -226,6 +226,8 @@ class avatar : public player
void toggle_run_mode();
// Toggles crouching on/off.
void toggle_crouch_mode();
// Toggles lying down on/off.
void toggle_prone_mode();
// Activate crouch mode if not in crouch mode.
void activate_crouch_mode();

9 changes: 9 additions & 0 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
@@ -90,6 +90,15 @@ bool avatar_action::move( avatar &you, map &m, const tripoint &d )
}
return false;
}

// If any leg broken without crutches and not already on the ground topple over
if( ( you.get_working_leg_count() < 2 && !you.weapon.has_flag( flag_CRUTCHES ) ) &&
!you.is_prone() ) {
you.set_movement_mode( move_mode_id( "prone" ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

A warning message would be nice here.

you.add_msg_if_player( m_bad,
_( "Your broken legs can't hold your weight and you fall down in pain." ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

If there's pain mentioned in message, maybe then actually add some pain on this event?

}

const bool is_riding = you.is_mounted();
tripoint dest_loc;
if( d.z == 0 && you.has_effect( effect_stunned ) ) {
10 changes: 8 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
@@ -1031,7 +1031,8 @@ int Character::swim_speed() const

bool Character::is_on_ground() const
{
return get_working_leg_count() < 2 || has_effect( effect_downed );
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a lot other places where effect_downed is used. Should these places be updated as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed earlier. There is a huge variety of reasons effect_downed is used. I don't think this is in this PR scope to identify and change them

return ( ( get_working_leg_count() < 2 && !weapon.has_flag( flag_CRUTCHES ) ) ) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the player fall over when trying to attack with their crutches?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not really thought of that. Should he fall over but still deal damage or just fall over and that's it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can make it depend on melee skill, or maybe we can just display a message that says you can't attack with crutches when your legs are broken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added check when performing melee if legs are broken. Currently you just cannot melee attack while you have broken legs. I don't think melee skill should affect that. But that's just a balance issue

has_effect( effect_downed ) || is_prone();
}

bool Character::can_stash( const item &it )
@@ -1898,6 +1899,11 @@ bool Character::is_crouching() const
return move_mode->type() == move_mode_type::CROUCHING;
}

bool Character::is_prone() const
{
return move_mode->type() == move_mode_type::PRONE;
}

steed_type Character::get_steed_type() const
{
steed_type steed;
@@ -9966,7 +9972,7 @@ void Character::on_hit( Creature *source, bodypart_id bp_hit,
source->add_effect( effect_blind, 2_turns );
}
}
if( worn_with_flag( flag_REQUIRES_BALANCE ) && !has_effect( effect_downed ) ) {
if( worn_with_flag( flag_REQUIRES_BALANCE ) && !is_on_ground() ) {
int rolls = 4;
if( worn_with_flag( flag_ROLLER_ONE ) ) {
rolls += 2;
4 changes: 3 additions & 1 deletion src/character.h
Original file line number Diff line number Diff line change
@@ -583,7 +583,7 @@ class Character : public Creature, public visitable
bool has_watch() const;
/** Called after every action, invalidates player caches */
void action_taken();
/** Returns true if the player is knocked over or has broken legs */
/** Returns true if the player is knocked over, has broken legs or is lying down */
bool is_on_ground() const override;
/** Returns the player's speed for swimming across water tiles */
int swim_speed() const;
@@ -711,6 +711,8 @@ class Character : public Creature, public visitable
bool is_running() const;
bool is_walking() const;
bool is_crouching() const;
bool is_prone() const;


bool can_switch_to( const move_mode_id &mode ) const;
steed_type get_steed_type() const;
12 changes: 10 additions & 2 deletions src/creature.cpp
Original file line number Diff line number Diff line change
@@ -281,7 +281,7 @@ bool Creature::sees( const Creature &critter ) const
return false;
}
if( ch != nullptr ) {
if( ch->is_crouching() ) {
if( ch->is_crouching() || ch->is_prone() ) {
const int coverage = here.obstacle_coverage( pos(), critter.pos() );
if( coverage < 30 ) {
return sees( critter.pos(), critter.is_avatar() ) && visible( ch );
@@ -306,7 +306,15 @@ bool Creature::sees( const Creature &critter ) const
debugmsg( "ERROR: Creature has invalid size class." );
break;
}
const int vision_modifier = 30 - 0.5 * coverage * size_modifier;

int vision_modifier {0};

if( ch->is_crouching() ) {
vision_modifier = 30 - 0.5 * coverage * size_modifier;
} else if( ch->is_prone() ) {
vision_modifier = 30 - 0.9 * coverage * size_modifier;
}

if( vision_modifier > 1 ) {
return sees( critter.pos(), critter.is_avatar(), vision_modifier ) && visible( ch );
}
1 change: 1 addition & 0 deletions src/flag.cpp
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ const flag_id flag_CONDUCTIVE( "CONDUCTIVE" );
const flag_id flag_CONSUMABLE( "CONSUMABLE" );
const flag_id flag_COOKED( "COOKED" );
const flag_id flag_CORPSE( "CORPSE" );
const flag_id flag_CRUTCHES( "CRUTCHES" );
const flag_id flag_CUSTOM_EXPLOSION( "CUSTOM_EXPLOSION" );
const flag_id flag_CUT_IMMUNE( "CUT_IMMUNE" );
const flag_id flag_DANGEROUS( "DANGEROUS" );
1 change: 1 addition & 0 deletions src/flag.h
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ extern const flag_id flag_CONDUCTIVE;
extern const flag_id flag_CONSUMABLE;
extern const flag_id flag_COOKED;
extern const flag_id flag_CORPSE;
extern const flag_id flag_CRUTCHES;
extern const flag_id flag_CUSTOM_EXPLOSION;
extern const flag_id flag_CUT_IMMUNE;
extern const flag_id flag_DANGEROUS;
6 changes: 5 additions & 1 deletion src/handle_action.cpp
Original file line number Diff line number Diff line change
@@ -1783,7 +1783,11 @@ bool game::do_regular_action( action_id &act, avatar &player_character,
player_character.toggle_crouch_mode();
break;

case ACTION_OPEN_MOVEMENT:
case ACTION_TOGGLE_PRONE:
player_character.toggle_prone_mode();
break;

case ACTION_OPEN_MOVEMENT:
ZhilkinSerg marked this conversation as resolved.
Show resolved Hide resolved
open_movement_mode_menu();
break;

10 changes: 10 additions & 0 deletions src/melee.cpp
Original file line number Diff line number Diff line change
@@ -487,6 +487,16 @@ bool Character::melee_attack_abstract( Creature &t, bool allow_special,
const matec_id &force_technique,
bool allow_unarmed )
{
if( get_working_leg_count() < 2 ) {
if( !movement_mode_is( move_mode_id( "prone" ) ) ) {
add_msg_if_player( m_bad, _( "Your broken legs cannot hold you and you fall down." ) );
set_movement_mode( move_mode_id( "prone" ) );
} else if( is_on_ground() ) {
add_msg_if_player( m_warning, _( "You cannot fight while on the ground." ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe in the future we should allow fighting (defending only?) while lying down, if your arms ain't broken.

}
return false;
}

melee::melee_stats.attack_count += 1;
int hit_spread = t.deal_melee_attack( this, hit_roll() );
if( !t.is_player() ) {
1 change: 1 addition & 0 deletions src/move_mode.cpp
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ bool move_mode_id::is_valid() const
}

static const std::map<std::string, move_mode_type> move_types {
{ "prone", move_mode_type::PRONE },
{ "crouching", move_mode_type::CROUCHING },
{ "walking", move_mode_type::WALKING },
{ "running", move_mode_type::RUNNING }
1 change: 1 addition & 0 deletions src/move_mode.h
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ enum class steed_type : int {
};

enum class move_mode_type : int {
PRONE,
CROUCHING,
WALKING,
RUNNING
2 changes: 1 addition & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
@@ -622,7 +622,7 @@ void player::pause()
if( has_effect( effect_onfire ) ) {
time_duration total_removed = 0_turns;
time_duration total_left = 0_turns;
bool on_ground = has_effect( effect_downed );
bool on_ground = is_prone();
for( const bodypart_id &bp : get_all_body_parts() ) {
effect &eff = get_effect( effect_onfire, bp );
if( eff.is_null() ) {