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

Assign faction to (some) item and vehicle placement #56110

Merged
merged 7 commits into from
Mar 25, 2022

Conversation

haveric
Copy link
Contributor

@haveric haveric commented Mar 15, 2022

Summary

Infrastructure "Assign faction to (some) item and vehicle placement"

Purpose of change

I needed a way to place items and vehicles that are owned by a faction so that the player can't just take them without repercussions.

Also may fix a bug related to variants in the following code, since variant wasn't being included:

    // recurse to spawn (quantity - 1) items
    for( size_t i = 1; i < quantity; i++ ) {
        spawn_item( p, type_id, 1, charges, birthday, damlevel, flags, variant, faction );
    }

Also implemented:

  • Support jmapgen_vehicle
  • Support jmapgen_item_group

Potential Improvements: (I've tried a couple times, but can't implement these cleanly)

  • Support jmapgen_loot?
  • Replace faction_owner with global faction in mapgen

Describe the solution

Set a faction for spawning items and vehicles.

Describe alternatives you've considered

  • Wait for someone else to do it

Testing

I've tested with place_item, item, and place_vehicles on the Tacoma foreman missions and included those changes as examples. When spawned, the items and vehicles correctly show as being owned by the Tacoma commune. I also tested with place_items, but don't have an example included.

Additional context

In its current state, it solves my initial problem for the Tacoma missions. I've attempted to extend support to improve mapgen, but every attempt so far has been a giant mess that doesn't work. If anyone wants to assist or thinks they know a clean way to make those changes, please let me know.

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON NPC / Factions NPCs, AI, Speech, Factions, Ownership json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Mar 15, 2022
@PatrikLundell
Copy link
Contributor

As long as factions can be spawned multiple times it doesn't really work to define them globally (although I don't know if the current system handles that properly either).

@haveric
Copy link
Contributor Author

haveric commented Mar 16, 2022

As long as factions can be spawned multiple times it doesn't really work to define them globally (although I don't know if the current system handles that properly either).

What do you mean by that? I'm only talking globally within a mapgen, so that the default faction gets set before any of the placement instead of happening at the end.

Specifically replacing (for the refugee center):

    "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",

with

    "object": {
      "faction": "free_merchants",
      "fill_ter": "t_floor",

And then instead of having jmapgen_faction run at the end, the default faction would get passed through to all of the other mapgen, allowing them to override if needed.

@PatrikLundell
Copy link
Contributor

I was talking about the issue that there may be several instances of each faction because "unique" isn't.

However, as you clarified, this isn't "global" in the world sense, but "global" within the rather limited scope of the specific mapgen. Thus, you're "just" improving on the current logic to be used more efficiently, which is a good thing.

@haveric
Copy link
Contributor Author

haveric commented Mar 17, 2022

Took another stab at this. I haven't been able to get jmapgen_loot implemented cleanly and I'm struggling to get data passed around within mapgen's jmapgen_pieces, so I might just clean this up and put it up for review and hope somebody else can improve it later.

@github-actions github-actions bot added the <Documentation> Design documents, internal info, guides and help. label Mar 17, 2022
@haveric haveric marked this pull request as ready for review March 17, 2022 04:01
@haveric haveric changed the title WIP: Assign faction to (some) item placement WIP: Assign faction to (some) item and vehicle placement Mar 17, 2022
@haveric haveric changed the title WIP: Assign faction to (some) item and vehicle placement Assign faction to (some) item and vehicle placement Mar 17, 2022
@kevingranade kevingranade merged commit 9095c04 into CleverRaven:master Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` <Documentation> Design documents, internal info, guides and help. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants