Skip to content

Commit

Permalink
Output JSON reports - part 1 (#150)
Browse files Browse the repository at this point in the history
Because these changes are going to be somewhat far-reaching, I am going
to do these in smaller chunks.   This chunk will contain

- a new game config which defaults to not outputting json reports.
- the inclusion of the nlohmann/json.hpp single-file json
  parser/manipulation library.
- Output the basic faction info (meaning the fields on the faction
  itself, but NOT deeper structures like regions/objects/units)
- An example of some small nested structures (skill shows/faction stats)
  to give examples of how this stuff will work.
- A renaming of 2 rules helper functions from link/link_ref to url/achor
  in order to avoid a conflict with the link() function from unistd.h
  which gets pulled in via the nlohmann/json.hpp standard library
  includes, and which caused the rules to break.  This is JUST a
  renaming and no functionality change, so you can ignore all the
  changes in genrules.cpp as part of this.
- Removing some duplicated skill data which was being output if you were
  shown a skill description which allowed you create an object which in
  turn allowed you to use a skill (create staff of healing shows the
  staff of healing, which then adds a skill show for magic healing).
  This wouldn't affect a player since a faction tracks whether or not a
  skill has been shown permanently and never shows it again, but when
  generating the turn 1 report for the gamemaster, if those items were
  enabled, 4 skills would end up shown twice.   This also accounts for
  the change to the snapshot turn_0 report.1 file.  Those changes are
  expected.
  • Loading branch information
jt-traub authored Oct 26, 2023
1 parent 323872d commit 4a01073
Show file tree
Hide file tree
Showing 38 changed files with 26,005 additions and 716 deletions.
2 changes: 1 addition & 1 deletion GAMEMASTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ If you wanted to switch on quartermasters, and have their level affect
shipping costs, but not distance, you would set the variable in rules.cpp
like so:

Gamedefs::ALLOW_TRANSPORT | GameDefs::QM_AFFECT_COST, // TRANSPORT
GameDefs::ALLOW_TRANSPORT | GameDefs::QM_AFFECT_COST, // TRANSPORT

Note that the different values are set using a boolean OR |, not a
logical OR ||.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ENGINE_OBJECTS = alist.o aregion.o army.o astring.o battle.o economy.o \
events.o events-battle.o events-assassination.o mapgen.o simplex.o namegen.o \
indenter.o

UNITTEST_SRC = unittest/main.cpp $(wildcard unittest/*_test.cpp)
UNITTEST_SRC = unittest/main.cpp unittest/testhelper.cpp $(wildcard unittest/*_test.cpp)
UNITTEST_OBJECTS = $(patsubst unittest/%.cpp,unittest/obj/%.o,$(UNITTEST_SRC))

OBJECTS = $(patsubst %.o,obj/%.o,$(ENGINE_OBJECTS)) $(patsubst %.o,$(GAME)/obj/%.o,$(RULESET_OBJECTS))
Expand Down
8 changes: 8 additions & 0 deletions aregion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,14 @@ void ARegion::WriteExits(ostream& f, ARegionList *pRegs, int *exits_seen)
f << '\n';
}

void ARegion::write_json_report(json& j, Faction *fac, int month, ARegionList *pRegions) {
// for now, just set a name which would be the name of the region from a text report.
// ie "Alioth Plains (1, 2) in Alioth contains Alioth City [City]."
// This will get broken down and become more json-y when I flesh this code out.
j["name"] = Print(pRegions).const_str();
return;
}

void ARegion::WriteReport(ostream &f, Faction *fac, int month, ARegionList *pRegions)
{
Farsight *farsight = GetFarsight(&farsees, fac);
Expand Down
4 changes: 4 additions & 0 deletions aregion.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class ARegionArray;
#include "graphs.h"
#include "mapgen.h"

#include "external/nlohmann/json.hpp"
using json = nlohmann::json;

#include <map>
#include <vector>
#include <functional>
Expand Down Expand Up @@ -199,6 +202,7 @@ class ARegion : public AListElem
void WriteEconomy(ostream& f, Faction *, int);
void WriteExits(ostream& f, ARegionList *pRegs, int *exits_seen);
void WriteReport(ostream& f, Faction *fac, int month, ARegionList *pRegions);
void write_json_report(json& j, Faction *fac, int month, ARegionList *pRegions);
// DK
void WriteTemplate(ostream& f, Faction *, ARegionList *, int);
void WriteTemplateHeader(ostream& f, Faction *, ARegionList *, int);
Expand Down
1 change: 1 addition & 0 deletions basic/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ static GameDefs g = {
200, // MIN_DESTROY_POINTS,
33, // MAX_DESTROY_PERCENT
0, // HALF_RIDING_BONUS
GameDefs::REPORT_FORMAT_TEXT, // REPORT_FORMAT
};

GameDefs *Globals = &g;
Loading

0 comments on commit 4a01073

Please sign in to comment.