Skip to content

Commit

Permalink
jsonize chainsaw. last one
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Jan 13, 2024
1 parent 21d6f8a commit c5008fd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 71 deletions.
10 changes: 0 additions & 10 deletions data/json/item_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,6 @@
"id": "CAPTURE_MONSTER_VEH",
"name": { "str": "Capture/place" }
},
{
"type": "item_action",
"id": "CHAINSAW_OFF",
"name": { "str": "Turn on" }
},
{
"type": "item_action",
"id": "CHEW",
Expand Down Expand Up @@ -345,11 +340,6 @@
"id": "COKE",
"name": { "str": "Snort coke" }
},
{
"type": "item_action",
"id": "TOOLWEAPON_DEACTIVATE",
"name": { "str": "Turn off" }
},
{
"type": "item_action",
"id": "CONTACTS",
Expand Down
61 changes: 58 additions & 3 deletions data/json/items/tool/woodworking.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,32 @@
"pocket_data": [ { "pocket_type": "MAGAZINE", "ammo_restriction": { "gasoline": 450 }, "watertight": true, "rigid": true } ],
"charges_per_use": 5,
"techniques": [ "SWEEP" ],
"use_action": [ "CHAINSAW_OFF" ],
"use_action": {
"type": "effect_on_conditions",
"menu_text": "Turn on",
"effect_on_conditions": [
{
"id": "EOC_toolweapon_activate__chainsaw",
"condition": { "and": [{ "math": [ "rng(0, 10) - n_damage_level()", ">", "5" ] }, { "not": "u_is_underwater" }, "has_ammo"] },
"effect": [
{ "turn_cost": "0.8" },
{
"u_make_sound": "With a roar, the chainsaw screams to life!",
"type": "combat",
"volume": 20
},
{ "u_message": "With a roar, the chainsaw screams to life!" },
{ "transform_item": "chainsaw_on", "active": true },
{ "sound_effect": "chainsaw_on", "id": "chainsaw_cord" },
{ "sound_effect": "chainsaw_on", "id": "chainsaw_start" }
],
"false_effect": [
{ "sound_effect": "chainsaw_on", "id": "chainsaw_cord" },
{ "u_message": "You yank the cord, but nothing happens." }
]
}
]
},
"flags": [ "NONCONDUCTIVE", "FRAGILE_MELEE" ],
"melee_damage": { "bash": 10 }
},
Expand All @@ -71,7 +96,19 @@
"revert_to": "chainsaw_off",
"techniques": [ "SWEEP" ],
"qualities": [ [ "AXE", 4 ], [ "BUTCHER", -100 ] ],
"use_action": [ "TOOLWEAPON_DEACTIVATE" ],
"use_action": {
"type": "effect_on_conditions",
"menu_text": "Turn off",
"effect_on_conditions": [
{
"id": "EOC_toolweapon_deactivate__chainsaw",
"effect": [
{ "run_eoc_with": "EOC_toolweapon_deactivate", "variables": { "transform_target": "chainsaw_off" } },
{ "sound_effect": "chainsaw_on", "id": "chainsaw_stop" }
]
}
]
},
"tick_action": {
"type": "effect_on_conditions",
"effect_on_conditions": [
Expand Down Expand Up @@ -106,7 +143,25 @@
"pocket_data": [ { "pocket_type": "MAGAZINE", "ammo_restriction": { "gasoline": 450 }, "watertight": true, "rigid": true } ],
"charges_per_use": 5,
"techniques": [ "SWEEP" ],
"use_action": [ "CHAINSAW_OFF" ],
"use_action": {
"type": "effect_on_conditions",
"menu_text": "Turn on",
"effect_on_conditions": [
{
"id": "EOC_toolweapon_activate__polesaw",
"effect": {
"run_eoc_with": "EOC_toolweapon_activate",
"variables": {
"turn_cost": "0.8",
"transform_target": "polesaw_on",
"success_message": "With a roar, the polesaw screams to life!",
"volume": "15",
"failure_message": "You yank the cord, but nothing happens."
}
}
}
]
},
"flags": [ "POLEARM", "NONCONDUCTIVE", "FRAGILE_MELEE", "REACH_ATTACK" ],
"melee_damage": { "bash": 6 }
},
Expand Down
2 changes: 0 additions & 2 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,6 @@ void Item_factory::init()
add_iuse( "DIRECTIONAL_HOLOGRAM", &iuse::directional_hologram );
add_iuse( "CAPTURE_MONSTER_ACT", &iuse::capture_monster_act );
add_iuse( "CAPTURE_MONSTER_VEH", &iuse::capture_monster_veh );
add_iuse( "CHAINSAW_OFF", &iuse::chainsaw_off );
add_iuse( "CHEW", &iuse::chew );
add_iuse( "RPGDIE", &iuse::rpgdie );
add_iuse( "CHANGE_EYES", &iuse::change_eyes );
Expand All @@ -1684,7 +1683,6 @@ void Item_factory::init()
add_iuse( "CHOP_LOGS", &iuse::chop_logs );
add_iuse( "CLEAR_RUBBLE", &iuse::clear_rubble );
add_iuse( "COKE", &iuse::coke );
add_iuse( "TOOLWEAPON_DEACTIVATE", &iuse::toolweapon_deactivate );
add_iuse( "CONTACTS", &iuse::contacts );
add_iuse( "CROWBAR", &iuse::crowbar );
add_iuse( "CROWBAR_WEAK", &iuse::crowbar_weak );
Expand Down
52 changes: 0 additions & 52 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ static const itype_id itype_barometer( "barometer" );
static const itype_id itype_battery( "battery" );
static const itype_id itype_c4armed( "c4armed" );
static const itype_id itype_canister_empty( "canister_empty" );
static const itype_id itype_chainsaw_off( "chainsaw_off" );
static const itype_id itype_chainsaw_on( "chainsaw_on" );
static const itype_id itype_cig( "cig" );
static const itype_id itype_cigar( "cigar" );
static const itype_id itype_cow_bell( "cow_bell" );
Expand Down Expand Up @@ -3031,56 +3029,6 @@ std::optional<int> iuse::siphon( Character *p, item *, const tripoint & )
return 1;
}

static int toolweapon_off( Character &p, item &it, const bool fast_startup,
const bool condition, const int volume,
const std::string &msg_success, const std::string &msg_failure )
{
p.moves -= fast_startup ? 60 : 80;
if( condition && it.ammo_sufficient( &p ) ) {
if( it.typeId() == itype_chainsaw_off ) {
sfx::play_variant_sound( "chainsaw_cord", "chainsaw_on", sfx::get_heard_volume( p.pos() ) );
sfx::play_variant_sound( "chainsaw_start", "chainsaw_on", sfx::get_heard_volume( p.pos() ) );
sfx::play_ambient_variant_sound( "chainsaw_idle", "chainsaw_on", sfx::get_heard_volume( p.pos() ),
sfx::channel::idle_chainsaw, 1000 );
sfx::play_ambient_variant_sound( "weapon_theme", "chainsaw", sfx::get_heard_volume( p.pos() ),
sfx::channel::chainsaw_theme,
3000 );
}
sounds::sound( p.pos(), volume, sounds::sound_t::combat, msg_success );
// 4 is the length of "_off".
it.convert( itype_id( it.typeId().str().substr( 0, it.typeId().str().size() - 4 ) + "_on" ), &p );
it.active = true;
return 1;
} else {
if( it.typeId() == itype_chainsaw_off ) {
sfx::play_variant_sound( "chainsaw_cord", "chainsaw_on", sfx::get_heard_volume( p.pos() ) );
}
p.add_msg_if_player( msg_failure );
return 0; // No charges consumed on failure.
}
}

std::optional<int> iuse::chainsaw_off( Character *p, item *it, const tripoint & )
{
return toolweapon_off( *p, *it,
false,
rng( 0, 10 ) - it->damage_level() > 5 && !p->is_underwater(),
20, _( "With a roar, the chainsaw screams to life!" ),
_( "You yank the cord, but nothing happens." ) );
}

std::optional<int> iuse::toolweapon_deactivate( Character *p, item *it, const tripoint &pos )
{
if( it->typeId() == itype_chainsaw_on ) {
sfx::play_variant_sound( "chainsaw_stop", "chainsaw_on", sfx::get_heard_volume( pos ) );
sfx::fade_audio_channel( sfx::channel::idle_chainsaw, 100 );
sfx::fade_audio_channel( sfx::channel::chainsaw_theme, 3000 );
}
p->add_msg_if_player( _( "Your %s goes quiet." ), it->tname() );
it->convert( *it->type->revert_to, p ).active = false;
return 0; // Don't consume charges when turning off.
}

std::optional<int> iuse::change_eyes( Character *p, item *, const tripoint & )
{
if( p->is_avatar() ) {
Expand Down
4 changes: 0 additions & 4 deletions src/iuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,12 @@ std::optional<int> camera( Character *, item *, const tripoint & );
std::optional<int> can_goo( Character *, item *, const tripoint & );
std::optional<int> capture_monster_act( Character *, item *, const tripoint & );
std::optional<int> capture_monster_veh( Character *, item *, const tripoint & );
std::optional<int> chainsaw_off( Character *, item *, const tripoint & );
std::optional<int> chainsaw_on( Character *, item *, const tripoint & );
std::optional<int> change_eyes( Character *, item *, const tripoint & );
std::optional<int> change_skin( Character *, item *, const tripoint & );
std::optional<int> chop_logs( Character *, item *, const tripoint & );
std::optional<int> chop_tree( Character *, item *, const tripoint & );
std::optional<int> e_circsaw_on( Character *, item *, const tripoint & );
std::optional<int> clear_rubble( Character *, item *, const tripoint & );
std::optional<int> coin_flip( Character *, item *, const tripoint & );
std::optional<int> toolweapon_deactivate( Character *, item *, const tripoint & );
std::optional<int> contacts( Character *, item *, const tripoint & );
std::optional<int> crowbar( Character *, item *, const tripoint & );
std::optional<int> crowbar_weak( Character *, item *, const tripoint & );
Expand Down

0 comments on commit c5008fd

Please sign in to comment.