Skip to content

Commit

Permalink
fix(VNpc): implement loading of news
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Jan 21, 2024
1 parent 8029ca4 commit 8cba2cf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
31 changes: 31 additions & 0 deletions include/zenkit/vobs/Misc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,36 @@ namespace zenkit {

using slot ZKREM("renamed to Slot") = Slot;

enum class NewsId {
MURDER = 200,
ATTACK = 195,
THEFT = 190,
DEFEAT = 185,
NERVE = 180,
INTERFERE = 175,
HAS_DEFEATED = 170,
};

enum class NewsSpread {
DONT_SPREAD = 0,
FRIENDLY_TOWARDS_VICTIM = 1,
FRIENDLY_TOWARDS_WITNESS = 2,
FRIENDLY_TOWARDS_OFFENDER = 3,
SAME_GUILD_VICTIM = 4,
};

struct News {
bool told;
float spread_time;
NewsSpread spread_type;
NewsId news_id;
bool gossip;
bool guild_victim;
std::string witness_name;
std::string offender_name;
std::string victim_name;
};

std::string npc_instance;
glm::vec3 model_scale;
float model_fatness;
Expand Down Expand Up @@ -512,6 +542,7 @@ namespace zenkit {
bool move_lock;

std::string packed[packed_count];
std::vector<std::unique_ptr<News>> news;
std::vector<std::shared_ptr<VItem>> items;
std::vector<std::unique_ptr<Slot>> slots;

Expand Down
32 changes: 24 additions & 8 deletions src/vobs/Misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,19 @@ namespace zenkit {
// unknown.
[[maybe_unused]] auto spells = r.read_raw(4); // spells

// TODO: News (I don't have a sample.).
auto news_count = r.read_int(); // NumOfEntries
if (news_count != 0) {
ZKLOGE("VOb.Npc",
"!!! IMPORTANT !!! This save-game contains news entries and cannot be loaded currently. Please "
"open an issue at https://github.com/GothicKit/ZenKit providing your save-game as a ZIP file.");
throw ParserError {"VNpc"};
for (auto i = 0; i < news_count; ++i) {
auto n = std::make_unique<News>();
n->told = r.read_bool(); // told
n->spread_time = r.read_float(); // spread_time
n->spread_type = static_cast<NewsSpread>(r.read_int()); // spreadType
n->news_id = static_cast<NewsId>(r.read_int()); // news_id
n->gossip = r.read_bool(); // gossip
n->guild_victim = r.read_bool(); // guildvictim
n->witness_name = r.read_string(); // witnessName
n->offender_name = r.read_string(); // offenderName
n->victim_name = r.read_string(); // victimName
news.push_back(std::move(n));
}

carry_vob = std::dynamic_pointer_cast<VirtualObject>(r.read_object(version)); // [carryVob % 0 0]
Expand Down Expand Up @@ -492,8 +498,18 @@ namespace zenkit {
spells.push_back({});
w.write_raw("spells", spells);

// TODO: News (I don't have a sample.).
w.write_int("NumOfEntries", 0);
w.write_int("NumOfEntries", this->news.size());
for (auto& n : this->news) {
w.write_bool("told", n->told);
w.write_float("spread_time", n->spread_time);
w.write_int("spreadType", static_cast<std::int32_t>(n->spread_type));
w.write_int("news_id", static_cast<std::int32_t>(n->news_id));
w.write_bool("gossip", n->gossip);
w.write_bool("guildvictim", n->guild_victim);
w.write_string("witnessName", n->witness_name);
w.write_string("offenderName", n->offender_name);
w.write_string("victimName", n->victim_name);
}

w.write_object("carryVob", this->carry_vob, version);
w.write_object("enemy", this->enemy, version);
Expand Down

0 comments on commit 8cba2cf

Please sign in to comment.