realm-generator
realm-generator copied to clipboard
Make event generator parser of JSON files, add event functionality, add events
Rewrite of event generator to parse event definitions from JSON files. See "event-definitions.md" for detail regarding event definition markup and features, examples and explanations included. Event parser and definitions replicate all existing events, support additional complex events. Event parser features: weighted random selection of events; event description with variables; actor constraints based on attributes; actor constraints based on attributes matching / not matching other actors; use of faction, animal, adjective lists; definition and use of arbitrary random variables; two-pass processing allows random selection from defined actors JSON Schema updated to include event definition data. Updated home page to allow user to select event sets to use.
Additional event set "Signs & Omens", various low-weight ominous happenings. Unselected by default, to preserve original behavior.
Efficiency improvement to event generation: EventGenerator object caches all_nobles, all_families, all_courtiers after performing lookups one time at initialization; previously performed full recursive traversal of families for each event generated. This should cause no change in behavior as long as the realm's nobility does not change during event generation. If event generation is updated to allow events to update the nobility (other than appending events to people and families), then I would recommend a dirty flag be used to cause the EventGenerator to update its cache after any change. This does require that additional memory be allocated to the EventGenerator object, but provides an approximately 5x improvement in speed of event generation, even with a measured ~2.1x decrease in speed due to changing to an event parsing architecture. Tested timing with default realm settings, average of 10 runs, timeit default_timer used around event generation code: Before any changes (commit fb30c2c0d5bdcaacfad56fa59e3edab539c5e3f9): 1.08450559 seconds After changing to event parser: 2.31943892 seconds After update to cache data: 0.19145887 seconds
Time can be further reduced by reducing "MAX_ACTOR_ATTEMPTS" and "MAX_GROUP_ATTEMPTS" timeout values in event.py, but this may result in fewer events being generated.
Possible logical bug in 'req_actors_any_eq' check in match_reqs() function in event.py; suspect this may produce false positives in some cases (>2 actors with multiple attributes being checked), but have not tested thoroughly.
Event parser code is not the most readable. Please reject pull request and tell me to fix it if it's too bad for you to stand.
Oh, wow. Outstanding stuff. Thanks for tackling that! This has way more functionality that I thought of when I thought of a schema-driven event parser. I don't find the schema to be unreadable by any means.
I want to dive a bit deeper into this. I'll probably tackle it on the weekend.
The schema is ridiculous, but that can be addressed later. Commit this, it is way more efficient.