Skip to content

Commit

Permalink
items can be put on walls with "POSTABLE" use_action
Browse files Browse the repository at this point in the history
-can be put on "WALL" ter/furn
-update docs on how to add an iuse function
-tile layering supports ter/furn flag
-deduplicate ter/furn layer drawing
  • Loading branch information
ShnitzelX2 committed Nov 16, 2024
1 parent d39cf9b commit f0f4549
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 157 deletions.
5 changes: 5 additions & 0 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,11 @@
"type": "json_flag",
"info": "You could probably <color_brown>plant</color> these."
},
{
"id": "POSTABLE",
"type": "json_flag",
"info": "This item can be put up on a wall."
},
{
"id": "MELTS",
"type": "json_flag",
Expand Down
5 changes: 5 additions & 0 deletions data/json/item_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,11 @@
"id": "PORTAL",
"name": { "str": "Place" }
},
{
"type": "item_action",
"id": "POSTABLE",
"name": { "str": "Put up" }
},
{
"type": "item_action",
"id": "PROZAC",
Expand Down
1 change: 1 addition & 0 deletions data/json/items/armor/cloaks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"material_thickness": 0.3,
"environmental_protection": 1,
"flags": [ "OVERSIZE", "BELTED", "ALLOWS_NATURAL_ATTACKS" ],
"use_action": [ "POSTABLE" ],
"armor": [
{
"encumbrance": 50,
Expand Down
5 changes: 3 additions & 2 deletions doc/DEVELOPER_FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ Specifically to ablative plates, some transform when damaged instead of damaging
## Adding an iuse function.

1. Add the new item use code to `iuse.cpp` and `iuse.h`.
2. Add the new json_flag to your item. And link it to the iuse function in `item_factory.cpp`.
3. Document the new flag in `JSON_FLAGS.md`.
2. Add a new json_flag to `flags.json`, and add the flag to your item(s) and to an `item_actions.json` entry.
3. Link the flag to the iuse function in `item_factory.cpp`.
4. Document the new flag in `JSON_FLAGS.md`.

## Acid resistance

Expand Down
1 change: 1 addition & 0 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ These flags can be applied via JSON item definition to most items. Not to be co
- ```PAPER_SHAPED``` This item is shaped in form of thin paper sheet, and can be stored in leather journal.
- ```PERFECT_LOCKPICK``` Item is a perfect lockpick. Takes only 5 seconds to pick a lock and never fails, but using it grants only a small amount of lock picking xp. The item should have `LOCKPICK` quality of at least 1.
- ```PLANTABLE_SEED``` This item is a seed, and you can plant it.
- ```POSTABLE``` This item can be placed on terrain/furniture with the WALL flag.
- ```PRESERVE_SPAWN_OMT``` This item will store the OMT that it spawns in, in the `spawn_location_omt` item var.
- ```PROVIDES_TECHNIQUES``` This item will provide martial arts techniques when worn/in the character's inventory, in addition to those provided by the weapon and martial art.
- ```PSEUDO``` Used internally to mark items that are referred to in the crafting inventory but are not actually items. They can be used as tools, but not as components. Implies `TRADER_AVOID`.
Expand Down
274 changes: 119 additions & 155 deletions src/cata_tiles.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class JsonObject;
class pixel_minimap;

extern void set_displaybuffer_rendertarget();
using ter_str_id = string_id<ter_t>;

/** Structures */
struct tile_type {
Expand Down
1 change: 1 addition & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,7 @@ void Item_factory::init()
add_iuse( "POISON", &iuse::poison );
add_iuse( "PORTABLE_GAME", &iuse::portable_game );
add_iuse( "PORTAL", &iuse::portal );
add_iuse( "POSTABLE", &iuse::postable );
add_iuse( "PROZAC", &iuse::prozac );
add_iuse( "PURIFY_SMART", &iuse::purify_smart );
add_iuse( "RADGLOVE", &iuse::radglove );
Expand Down
25 changes: 25 additions & 0 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8811,6 +8811,31 @@ std::optional<int> iuse::disassemble( Character *p, item *it, const tripoint & )
return 0;
}

std::optional<int> iuse::postable( Character *p, item *it, const tripoint & )
{
map &here = get_map();

//arbitrary limit of 10 postable items per wall
const std::function<bool( const tripoint_bub_ms & )> f = [&here]( const tripoint_bub_ms & pnt ) {
return here.has_flag_ter_or_furn( ter_furn_flag::TFLAG_WALL, pnt ) && here.i_at( pnt ).size() < 10;
};

const std::optional<tripoint_bub_ms> pnt_ = choose_adjacent_highlight(
_( "Post to which wall?" ), _( "There is no applicable wall nearby." ), f, false );
if( !pnt_ ) {
return std::nullopt;
}

//copy and place used item and remove the used item from inventory
item_location original_item( *p, it );
item copy_item( *original_item );
here.add_item( *pnt_, copy_item );
original_item.remove_item();
p->add_msg_if_player( m_good, _( "You put up the %s." ), copy_item.tname() );

return 0;
}

std::optional<int> iuse::melatonin_tablet( Character *p, item *it, const tripoint & )
{
p->add_msg_if_player( _( "You pop a %s." ), it->tname() );
Expand Down
2 changes: 2 additions & 0 deletions src/iuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ std::optional<int> craft( Character *, item *, const tripoint & );

std::optional<int> disassemble( Character *, item *, const tripoint & );

std::optional<int> postable( Character *, item *, const tripoint & );

// Helper functions for other iuse functions
void cut_log_into_planks( Character & );
void play_music( Character *p, const tripoint &source, int volume, int max_morale,
Expand Down

0 comments on commit f0f4549

Please sign in to comment.