Station Crew Spawning and Trade
Hey Folks! Hope everyone had a good weekend. There was an apple picking trip among ours. Plus an extended bout of Rimworld Saturday evening, where half my colony died in a caravan beset by man-eating alphabeavers. RIP the de facto leaders of the colony.
Back at the office, I resumed work on the trading system, focusing on getting stations to spawn NPCs with whom to trade. I ultimately decided to add another zone type for spawning, and to change the zone properties to use a PersonSpec instead of a ConditionTrigger. PersonSpecs can optionally include a trigger, plus a bunch of other rules for finding/making people, so it seemed like a natural improvement.
The spawn zone also seemed fairly intuitive, and what's more, already used existing systems in the game. I could just draw a zone on the ship where NPCs should appear, and select the PersonSpec defining who should spawn there. It wasn't quite that clear cut, though.
One problem I ran into was the concept of shallow vs. fully-loaded ships. The spawned NPCs needed to be stored in appropriate shallow/full mode based on whether the ship was loaded or not, and this required some code to bridge those gaps.
The good news is that it's mostly working! I was able to spawn a station directly, have the NPC spawned on it, and then have my player initiate trade with them. I saw my pocketed items on my side of the screen, and their pocketed items plus their shop's inventory on theirs. Also, when I started a fresh game and flew to said station, I arrived to find two NPCs there!
The first one was a law enforcement officer, probably related to a plot that was autogenerated. The second was my storekeeper (bartender) for testing. So far so good!
Unfortunately, there was a problem when I initiated trade. The shopkeep didn't have a shop, just their held items. Looking into it further, I think it's a bug in the way ships get rotated during docking. The tile indices of the zones aren't getting updated with the new rotated tile indices, so it checks the wrong tiles. This shouldn't be too hard to fix, fortunately.
Performance is still a bit of a pig in this case. Some 2000+ tiles/items live for each ship in this test, and only 3 crew walking around. It hit the framerate pretty hard. Down around 20ish fps. I haven't profiled it yet, so I'm just guessing this is rendering/lighting. But that'll be an issue down the line.
For now, though, we almost have rudimentary trade working!