Skip to content

Commit

Permalink
Faction ownership and thievery (CleverRaven#29834)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpwbrown authored and ZhilkinSerg committed May 24, 2019
1 parent 8403903 commit 4985bb0
Show file tree
Hide file tree
Showing 27 changed files with 540 additions and 35 deletions.
64 changes: 64 additions & 0 deletions data/json/mapgen/faction_buildings.json

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions data/json/mapgen/refugee_center.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"om_terrain": [ [ "evac_center_1", "evac_center_2", "evac_center_3", "evac_center_4", "evac_center_5" ] ],
"weight": 100,
"object": {
"faction_owner": [
{ "id": "free_merchants", "x": [ 0, 23 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 24, 47 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 48, 71 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 72, 95 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 96, 119 ], "y": [ 0, 23 ] }
],
"fill_ter": "t_floor",
"rows": [
"........................................................................................................................",
Expand Down Expand Up @@ -51,6 +58,13 @@
"om_terrain": [ [ "evac_center_6", "evac_center_7", "evac_center_8", "evac_center_9", "evac_center_10" ] ],
"weight": 100,
"object": {
"faction_owner": [
{ "id": "free_merchants", "x": [ 0, 23 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 24, 47 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 48, 71 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 72, 95 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 96, 119 ], "y": [ 0, 23 ] }
],
"fill_ter": "t_floor",
"rows": [
"......_______,,_______ssss.......................sss________________sss.......................ssss_______,,_______......",
Expand Down Expand Up @@ -143,6 +157,13 @@
"om_terrain": [ [ "evac_center_11", "evac_center_12", "evac_center_13", "evac_center_14", "evac_center_15" ] ],
"weight": 100,
"object": {
"faction_owner": [
{ "id": "free_merchants", "x": [ 0, 23 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 24, 47 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 48, 71 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 72, 95 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 96, 119 ], "y": [ 0, 23 ] }
],
"fill_ter": "t_floor",
"rows": [
"......_______,,________sss.........##### c# ###########+#+###########LL#c #####..........sss________,,_______......",
Expand Down Expand Up @@ -215,6 +236,13 @@
"om_terrain": [ [ "evac_center_16", "evac_center_17", "evac_center_18", "evac_center_19", "evac_center_20" ] ],
"weight": 100,
"object": {
"faction_owner": [
{ "id": "free_merchants", "x": [ 0, 23 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 24, 47 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 48, 71 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 72, 95 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 96, 119 ], "y": [ 0, 23 ] }
],
"fill_ter": "t_floor",
"rows": [
"......_______,,_______sss....#########t+ c# #2hcV bbbb bbbb Vch2# #c +t#########....sss________,,_______......",
Expand Down Expand Up @@ -303,6 +331,13 @@
"om_terrain": [ [ "evac_center_21", "evac_center_22", "evac_center_23", "evac_center_24", "evac_center_25" ] ],
"weight": 100,
"object": {
"faction_owner": [
{ "id": "free_merchants", "x": [ 0, 23 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 24, 47 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 48, 71 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 72, 95 ], "y": [ 0, 23 ] },
{ "id": "free_merchants", "x": [ 96, 119 ], "y": [ 0, 23 ] }
],
"fill_ter": "t_floor",
"rows": [
"......_______,,_______ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss_______,,_______......",
Expand Down
58 changes: 58 additions & 0 deletions data/json/npcs/TALK_COMMON_OTHER.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,64 @@
{ "text": "Thanks, see you later!", "topic": "TALK_DONE" }
]
},
{
"id": "TALK_STOLE_ITEM",
"type": "talk_topic",
"dynamic_line": "You picked up something that does not belong to you...",
"responses": [
{
"text": "Okay, okay, this is all a misunderstanding. Sorry, I'll drop it now.",
"topic": "TALK_DONE",
"effect": "drop_stolen_item",
"condition": "u_has_stolen_item"
},
{
"text": "No, I'm keeping it. Try and take it off me, I dare you.",
"condition": "u_has_stolen_item",
"trial": { "type": "INTIMIDATE", "difficulty": 30, "mod": [ [ "FEAR", 8 ], [ "VALUE", 2 ], [ "TRUST", 2 ], [ "BRAVERY", -2 ] ] },
"success": { "topic": "TALK_KEEPING_ITEM", "effect": { "u_faction_rep": -2 } },
"failure": { "topic": "TALK_DONE", "effect": [ "hostile", { "u_faction_rep": -75 } ] }
},
{
"text": "Look, I really need this. Please let me have it.",
"condition": "u_has_stolen_item",
"trial": { "type": "PERSUADE", "difficulty": 20, "mod": [ [ "TRUST", 3 ], [ "VALUE", 3 ], [ "ANGER", -3 ] ] },
"success": { "topic": "TALK_ALLOW_KEEP_ITEM", "effect": { "u_faction_rep": -1 } },
"failure": { "topic": "TALK_DISALLOW_KEEP_ITEM", "opinion": { "trust": -3, "anger": 2 }, "effect": { "u_faction_rep": -15 } }
},
{
"text": "What, this? It's not the same one, you are mistaken.",
"condition": "u_has_stolen_item",
"trial": { "type": "LIE", "difficulty": 25, "mod": [ [ "TRUST", 3 ] ] },
"success": { "topic": "TALK_DONE", "effect": "remove_stolen_status" },
"failure": { "topic": "TALK_DISALLOW_KEEP_ITEM", "opinion": { "trust": -3, "value": -1, "anger": 2 } }
},
{
"text": "I'm sorry. Look, I already dropped it, okay?",
"topic": "TALK_DONE",
"effect": [ "remove_stolen_status", { "u_faction_rep": -5 } ],
"condition": { "not": "u_has_stolen_item" }
}
]
},
{
"id": "TALK_DISALLOW_KEEP_ITEM",
"type": "talk_topic",
"dynamic_line": "Don't try and talk yourself out of this, drop it now.",
"responses": [ { "text": "Okay, I'm dropping it...", "effect": "drop_stolen_item", "topic": "TALK_DONE" } ]
},
{
"id": "TALK_ALLOW_KEEP_ITEM",
"type": "talk_topic",
"dynamic_line": "Just this once, you can keep it. Don't tell anyone else.",
"responses": [ { "text": "Thanks.", "topic": "TALK_DONE", "effect": "remove_stolen_status" } ]
},
{
"id": "TALK_KEEPING_ITEM",
"type": "talk_topic",
"dynamic_line": "Right... I don't want any trouble.",
"responses": [ { "text": "Smart choice.", "topic": "TALK_DONE", "effect": "remove_stolen_status" } ]
},
{
"id": "TALK_DENY_EQUIPMENT",
"type": "talk_topic",
Expand Down
15 changes: 15 additions & 0 deletions data/json/npcs/talk_tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,21 @@
"Thanks, <name_g>!"
]
},
{
"type": "snippet",
"category": "<witnessed_thievery>",
"text": [
"Hey! I <swear> saw you take that <name_b>! Drop it. Now.",
"You best be dropping what you just picked up right now <name_b>.",
"I've got eyes, you <swear> <name_b> thief!",
"Hey! That belongs to us! Drop it.",
"<swear>, I've seen a <swear> thief!",
"I saw that! Drop what you just stole!",
"Thieves will not last long around me <name_g>, please drop that.",
"Consider this a warning <name_b>, thieves will not be tolerated, drop it.",
"You think I'm <swear> blind <name_b>? Don't touch our stuff."
]
},
{
"type": "snippet",
"category": "<happy>",
Expand Down
22 changes: 18 additions & 4 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static void put_into_vehicle( Character &c, item_drop_reason reason, const std::
g->m.add_item_or_charges( where, it );
fallen_count += it.count();
}
it.handle_pickup_ownership( c );
}

const std::string part_name = veh.part_info( part ).name();
Expand Down Expand Up @@ -188,7 +189,17 @@ static void put_into_vehicle( Character &c, item_drop_reason reason, const std::
}
}

static void stash_on_pet( const std::list<item> &items, monster &pet )
static void pass_to_ownership_handling( item obj, Character &c )
{
obj.handle_pickup_ownership( c );
}

static void pass_to_ownership_handling( item obj, player *p )
{
obj.handle_pickup_ownership( *p );
}

static void stash_on_pet( const std::list<item> &items, monster &pet, player *p )
{
units::volume remaining_volume = pet.inv.empty() ? 0_ml : pet.inv.front().get_storage();
units::mass remaining_weight = pet.weight_capacity();
Expand All @@ -213,10 +224,12 @@ static void stash_on_pet( const std::list<item> &items, monster &pet )
remaining_volume -= it.volume();
remaining_weight -= it.weight();
}
// TODO: if NPCs can have pets or move items onto pets
pass_to_ownership_handling( it, p );
}
}

static void drop_on_map( const Character &c, item_drop_reason reason, const std::list<item> &items,
static void drop_on_map( Character &c, item_drop_reason reason, const std::list<item> &items,
const tripoint &where )
{
if( items.empty() ) {
Expand Down Expand Up @@ -297,8 +310,9 @@ static void drop_on_map( const Character &c, item_drop_reason reason, const std:
break;
}
}
for( const auto &it : items ) {
for( auto &it : items ) {
g->m.add_item_or_charges( where, it );
pass_to_ownership_handling( it, c );
}
}

Expand Down Expand Up @@ -663,7 +677,7 @@ void activity_handlers::stash_do_turn( player_activity *act, player *p )

monster *pet = g->critter_at<monster>( pos );
if( pet != nullptr && pet->has_effect( effect_pet ) ) {
stash_on_pet( obtain_activity_items( *act, *p ), *pet );
stash_on_pet( obtain_activity_items( *act, *p ), *pet, p );
} else {
p->add_msg_if_player( _( "The pet has moved somewhere else." ) );
p->cancel_activity();
Expand Down
22 changes: 20 additions & 2 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,34 @@ void advanced_inventory::print_items( advanced_inventory_pane &pane, bool active
}

std::string item_name;
std::string stolen_string;
bool stolen = false;
if( it.has_owner() ) {
const faction *item_fac = it.get_owner();
if( item_fac != g->faction_manager_ptr->get( faction_id( "your_followers" ) ) ) {
stolen_string = string_format( "<color_light_red>!</color>" );
stolen = true;
}
}
if( it.ammo_type() == "money" ) {
//Count charges
// TODO: transition to the item_location system used for the normal inventory
unsigned long charges_total = 0;
for( const auto item : sitem.items ) {
charges_total += item->charges;
}
item_name = it.display_money( sitem.items.size(), charges_total );
if( stolen ) {
item_name = string_format( "%s %s", stolen_string, it.display_money( sitem.items.size(),
charges_total ) );
} else {
item_name = it.display_money( sitem.items.size(), charges_total );
}
} else {
item_name = it.display_name();
if( stolen ) {
item_name = string_format( "%s %s", stolen_string, it.display_name() );
} else {
item_name = it.display_name();
}
}
if( get_option<bool>( "ITEM_SYMBOLS" ) ) {
item_name = string_format( "%s %s", it.symbol(), item_name );
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ long int Character::i_add_to_container( const item &it, const bool unloading )
visit_items( [ & ]( item * item ) {
if( charges > 0 && item->is_ammo_container() && item_type == item->contents.front().typeId() ) {
charges = add_to_container( *item );
item->handle_pickup_ownership( *this );
}
return VisitResponse::NEXT;
} );
Expand Down Expand Up @@ -805,7 +806,6 @@ item &Character::i_add( item it, bool should_stack )
break;
}
}

auto &item_in_inv = inv.add_item( it, keep_invlet, true, should_stack );
item_in_inv.on_pickup( *this );
return item_in_inv;
Expand Down
1 change: 1 addition & 0 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ void debug()
temp->mission = NPC_MISSION_NULL;
temp->add_new_mission( mission::reserve_random( ORIGIN_ANY_NPC, temp->global_omt_location(),
temp->getID() ) );
temp->set_fac( faction_id( "wasteland_scavengers" ) );
g->load_npcs();
}
break;
Expand Down
1 change: 1 addition & 0 deletions src/dialogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ struct conditional_t {
void set_has_weapon( bool is_npc = false );
void set_is_driving( bool is_npc = false );
void set_is_day();
void set_has_stolen_item( bool is_npc = false );
void set_is_outside();
void set_is_by_radio();
void set_u_has_camp();
Expand Down
16 changes: 16 additions & 0 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ int om_harvest_ter_break( npc &comp, const tripoint &omt_tgt, const ter_id &t, i
/// @ref take, whether you take the item or count it
mass_volume om_harvest_itm( npc_ptr comp, const tripoint &omt_tgt, int chance = 100,
bool take = true );
void apply_camp_ownership( const tripoint camp_pos, int radius );
/*
* Counts or cuts trees into trunks and trunks into logs
* @param omt_tgt the targeted OM tile
Expand Down Expand Up @@ -3520,6 +3521,7 @@ void basecamp::place_results( item result, bool by_radio )
target_bay.load( omt_pos.x * 2, omt_pos.y * 2, omt_pos.z, false );
const tripoint &new_spot = target_bay.getlocal( get_dumping_spot() );
target_bay.add_item_or_charges( new_spot, result, true );
apply_camp_ownership( new_spot, 10 );
target_bay.save();
} else {
auto &mgr = zone_manager::get_manager();
Expand All @@ -3534,11 +3536,25 @@ void basecamp::place_results( item result, bool by_radio )
for( auto &src : src_sorted ) {
const auto &src_loc = g->m.getlocal( src );
g->m.add_item_or_charges( src_loc, result, true );
apply_camp_ownership( src_loc, 10 );
break;
}
//or dump them at players feet
} else {
g->m.add_item_or_charges( g->u.pos(), result, true );
apply_camp_ownership( g->u.pos(), 0 );
}
}
}

void apply_camp_ownership( const tripoint camp_pos, int radius )
{
for( const tripoint &p : g->m.points_in_rectangle( tripoint( camp_pos.x - radius,
camp_pos.y - radius, camp_pos.z ), tripoint( camp_pos.x + radius, camp_pos.y + radius,
camp_pos.z ) ) ) {
auto items = g->m.i_at( p.x, p.y );
for( item &elem : items ) {
elem.set_owner( g->faction_manager_ptr->get( faction_id( "your_followers" ) ) );
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,9 @@ bool game::start_game()
}
}
}

for( auto &e : u.inv_dump() ) {
e->set_owner( g->faction_manager_ptr->get( faction_id( "your_followers" ) ) );
}
// Now that we're done handling coordinates, ensure the player's submap is in the center of the map
update_map( u );
// Profession pets
Expand Down Expand Up @@ -2604,7 +2606,9 @@ void game::load( const save_t &name )
validate_npc_followers();
validate_camps();
update_map( u );

for( auto &e : u.inv_dump() ) {
e->set_owner( g->faction_manager_ptr->get( faction_id( "your_followers" ) ) );
}
// legacy, needs to be here as we access the map.
if( u.getID() == 0 || u.getID() == -1 ) {
// player does not have a real id, so assign a new one,
Expand Down
Loading

0 comments on commit 4985bb0

Please sign in to comment.