Skip to content

Commit

Permalink
Merged PR 555: 617_added_guild_rank_prereqs_to_buildings
Browse files Browse the repository at this point in the history
Added guild rank prerequisites

Related Work Items: #617

Related work items: #617
  • Loading branch information
Allen B. Cummings committed Aug 14, 2019
1 parent d93c205 commit 16a8251
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 23 deletions.
41 changes: 37 additions & 4 deletions core/prerequisites.c
Expand Up @@ -42,6 +42,11 @@ protected mapping prerequisites = ([
// "type": "guild", // "type": "guild",
// "value": ({ "fighter" }) // "value": ({ "fighter" })
// ]), // ]),
// "guild rank": ([
// "type": "guild rank",
// "guild": "mage",
// "value": ({ "acolyte", "archmage" })
// ]),
// "best kill": ([ // "best kill": ([
// "type": "combat statistic", // "type": "combat statistic",
// "value": 45 // "value": 45
Expand Down Expand Up @@ -69,7 +74,7 @@ private nomask int isValidPrerequisiteType(string type)
{ {
return (member(({ "research", "attribute", "skill", "quest", "guild", return (member(({ "research", "attribute", "skill", "quest", "guild",
"race", "faction", "trait", "background", "combat statistic", "level", "race", "faction", "trait", "background", "combat statistic", "level",
"opinion", "state", "presence", "not present" }), type) > -1); "opinion", "state", "presence", "not present", "guild rank" }), type) > -1);
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
Expand Down Expand Up @@ -305,6 +310,14 @@ private nomask int checkGuilds(object researcher, string *guilds)
return ret; return ret;
} }


/////////////////////////////////////////////////////////////////////////////
private nomask int checkGuildRanks(object researcher, string guild,
string *ranks)
{
return checkGuilds(researcher, ({ guild })) && pointerp(ranks) &&
(member(ranks, researcher->guildRank(guild)) > -1);
}

//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Method: checkRaces // Method: checkRaces
// Description: This method will check whether or not the passed researcher // Description: This method will check whether or not the passed researcher
Expand Down Expand Up @@ -530,6 +543,12 @@ public nomask varargs int checkPrerequisites(object researcher, string grouping,
ret &&= checkGuilds(researcher, prerequisiteData["value"]); ret &&= checkGuilds(researcher, prerequisiteData["value"]);
break; break;
} }
case "guild rank":
{
ret &&= checkGuildRanks(researcher,
prerequisiteData["guild"], prerequisiteData["value"]);
break;
}
case "race": case "race":
{ {
ret &&= checkRaces(researcher, prerequisiteData["value"]); ret &&= checkRaces(researcher, prerequisiteData["value"]);
Expand Down Expand Up @@ -702,6 +721,12 @@ public nomask string displayPrerequisites(string colorConfiguration,
prerequisites[key]["value"]); prerequisites[key]["value"]);
break; break;
} }
case "guild rank":
{
prereq = sprintf("Rank in the %s guild of ",
prerequisites[key]["guild"]);
// Yes, fall through!
}
case "guild": case "guild":
case "race": case "race":
case "presence": case "presence":
Expand All @@ -711,11 +736,19 @@ public nomask string displayPrerequisites(string colorConfiguration,
if (pointerp(prerequisites[key]["value"]) && if (pointerp(prerequisites[key]["value"]) &&
sizeof(prerequisites[key]["value"])) sizeof(prerequisites[key]["value"]))
{ {
foreach(string value in prerequisites[key]["value"]) string *words = explode(implode(
prerequisites[key]["value"], " or "), " ");

int size = sizeof(words);
for (int i = 0; i < size; i++)
{ {
prereq += capitalize(value) + " or "; if (words[i] != "or")
{
words[i] = capitalize(words[i]);
}
} }
prereq = prereq[..(sizeof(prereq) - 5)];
prereq += implode(words, " ");
} }
break; break;
} }
Expand Down
4 changes: 3 additions & 1 deletion dictionaries/domains/building-components.h
Expand Up @@ -5,12 +5,14 @@
#ifndef buildingComponents_h #ifndef buildingComponents_h
#define buildingComponents_h #define buildingComponents_h


#include "buildings.h"
#include "stone-keep-components.h" #include "stone-keep-components.h"
#include "tower-components.h" #include "tower-components.h"
#include "wall-components.h" #include "wall-components.h"
#include "wooden-keep-components.h" #include "wooden-keep-components.h"


protected mapping BuildingComponents = StoneKeepComponents + protected mapping BuildingComponents = BuildingBlueprints +
StoneKeepComponents +
WoodenKeepComponents + WoodenKeepComponents +
WallComponents + WallComponents +
TowerComponents + ([]); TowerComponents + ([]);
Expand Down
68 changes: 54 additions & 14 deletions dictionaries/domains/buildings.h
Expand Up @@ -215,9 +215,33 @@ protected mapping BuildingBlueprints = ([
"aegis guard": 10, "aegis guard": 10,
]), ]),
"building prerequisites": ([ "building prerequisites": ([
"phaedra":(["type":"trait", "value": ({ "aegis":(["type":"guild", "value" : ({ "aegis" }) ]),
"/lib/instances/traits/personas/fighter/aegis.c", }) "stonemasonry": (["type":"skill", "value": 5]),
]), "carpentry": (["type":"skill", "value": 5]),
"wood crafting": (["type":"skill", "value": 5]),
"engineering": (["type":"skill", "value": 5]),
"sewing": (["type":"skill", "value": 2]),
]),
"building materials": ([
"stone": 100,
"wood": 150,
"metal": 15,
"textile": 5,
]),
"added duration": 300,
"structure": 300,
]),

"scion of dhuras outpost": ([
"class": "military floorplan",
"description": "",
"experience modifier": 1.1,
"default units": ([
"henchman": 1,
"scion of dhuras": 10,
]),
"building prerequisites": ([
"scion of dhuras": (["type":"guild", "value" : ({ "scion of dhuras" })]),
"stonemasonry": (["type":"skill", "value": 5]), "stonemasonry": (["type":"skill", "value": 5]),
"carpentry": (["type":"skill", "value": 5]), "carpentry": (["type":"skill", "value": 5]),
"wood crafting": (["type":"skill", "value": 5]), "wood crafting": (["type":"skill", "value": 5]),
Expand Down Expand Up @@ -379,22 +403,38 @@ protected mapping BuildingBlueprints = ([
"workshop":([ "workshop":([
"type": "craftsman's floorplan", "type": "craftsman's floorplan",
"description": "", "description": "",
"effects": ([ "default units": ([
]), "henchman": 3,
"upgrades": ([
]), ]),
"colors": ([ "effects": ([
"default":([ "craft seige equipment":([
"3-bit": "\x1b[0;31m", "action": "craft seige equipment",
"8-bit": "\x1b[0;38;5;9m", "duration bonus": 10,
"24-bit": "\x1b[0;38;2;200;0;0m" "quantity bonus": 10,
]), ]),
"workshop research": ([
"duration bonus": 10,
"apply": "1 every 12 hours",
"type" : ({ "domains", "crafting" })
])
]), ]),
"icon":([ "building prerequisites": ([
"ascii": "", "stonemasonry": (["type":"skill", "value": 5]),
"unicode": "", "carpentry": (["type":"skill", "value": 5]),
"wood crafting": (["type":"skill", "value": 5]),
"engineering": (["type":"skill", "value": 5]),
"sewing": (["type":"skill", "value": 2]),
]),
"building materials": ([
"stone": 100,
"wood": 150,
"metal": 15,
"textile": 5,
]), ]),
"added duration": 300,
"structure": 300,
]), ]),

"carpenter":([ "carpenter":([
"type": "craftsman's floorplan", "type": "craftsman's floorplan",
"description": "", "description": "",
Expand Down
42 changes: 39 additions & 3 deletions tests/core/prerequisitesTest.c
Expand Up @@ -116,6 +116,31 @@ void CheckPrerequsistesCorrectlyHandlesGuildChecks()
ExpectTrue(Prerequisite->checkPrerequisites(Researcher), "check succeeds when guild set"); ExpectTrue(Prerequisite->checkPrerequisites(Researcher), "check succeeds when guild set");
} }


/////////////////////////////////////////////////////////////////////////////
void CheckPrerequsistesCorrectlyHandlesGuildRankChecks()
{
Researcher->ToggleMockGuilds();
ExpectTrue(Prerequisite->AddTestPrerequisite("guild rank",
(["type": "guild rank", "guild": "mage", "value" : ({ "adept", "archmage" })])));

ExpectFalse(Prerequisite->checkPrerequisites(Researcher), "check initially fails");

Researcher->SetGuild("fighter");
ExpectFalse(Prerequisite->checkPrerequisites(Researcher), "check fails when wrong guild set");

Researcher->SetGuild("mage");
ExpectFalse(Prerequisite->checkPrerequisites(Researcher), "check fails when correct guild set");

Researcher->SetRank("acolyte");
ExpectFalse(Prerequisite->checkPrerequisites(Researcher), "check fails when wrong rank set");

Researcher->SetRank("adept");
ExpectTrue(Prerequisite->checkPrerequisites(Researcher), "check succeeds when valid rank set");

Researcher->SetRank("archmage");
ExpectTrue(Prerequisite->checkPrerequisites(Researcher));
}

///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
void CheckPrerequsistesCorrectlyHandlesRaceChecks() void CheckPrerequsistesCorrectlyHandlesRaceChecks()
{ {
Expand Down Expand Up @@ -394,7 +419,7 @@ void DisplayPrerequisitesCorrectlyDisplaysRacePrerequisites()
"type":"race", "value" : ({ "elf", "half-elf", "high elf" }) ]))); "type":"race", "value" : ({ "elf", "half-elf", "high elf" }) ])));


ExpectEq("\x1b[0;36mPrerequisites:\n\x1b[0m" ExpectEq("\x1b[0;36mPrerequisites:\n\x1b[0m"
"\x1b[0;33m Race: \x1b[0m\x1b[0;35mElf or Half-elf or High elf\n\x1b[0m", "\x1b[0;33m Race: \x1b[0m\x1b[0;35mElf or Half-elf or High Elf\n\x1b[0m",
Prerequisite->displayPrerequisites(colorConfiguration, Configuration)); Prerequisite->displayPrerequisites(colorConfiguration, Configuration));
} }


Expand All @@ -408,13 +433,24 @@ void DisplayPrerequisitesCorrectlyDisplaysGuildPrerequisites()
Prerequisite->displayPrerequisites(colorConfiguration, Configuration)); Prerequisite->displayPrerequisites(colorConfiguration, Configuration));
} }


/////////////////////////////////////////////////////////////////////////////
void DisplayPrerequisitesCorrectlyDisplaysGuildRankPrerequisites()
{
ExpectTrue(Prerequisite->AddTestPrerequisite("guild rank",
(["type":"guild rank", "guild" : "mage", "value" : ({ "adept", "archmage" })])));

ExpectEq("\x1b[0;36mPrerequisites:\n\x1b[0m\x1b[0;33m Guild rank: "
"\x1b[0m\x1b[0;35mRank in the mage guild of Adept or Archmage\n\x1b[0m",
Prerequisite->displayPrerequisites(colorConfiguration, Configuration));
}

///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
void DisplayPrerequisitesCorrectlyDisplaysFactionPrerequisites() void DisplayPrerequisitesCorrectlyDisplaysFactionPrerequisites()
{ {
ExpectTrue(Prerequisite->AddTestPrerequisite("faction", ([ ExpectTrue(Prerequisite->AddTestPrerequisite("faction", ([
"type":"faction", "value": ({ "Llama lords" })]))); "type":"faction", "value": ({ "llama lords" })])));


ExpectEq("\x1b[0;36mPrerequisites:\n\x1b[0m\x1b[0;33m Faction: \x1b[0m\x1b[0;35mLlama lords\n\x1b[0m", ExpectEq("\x1b[0;36mPrerequisites:\n\x1b[0m\x1b[0;33m Faction: \x1b[0m\x1b[0;35mLlama Lords\n\x1b[0m",
Prerequisite->displayPrerequisites(colorConfiguration, Configuration)); Prerequisite->displayPrerequisites(colorConfiguration, Configuration));
} }


Expand Down
14 changes: 13 additions & 1 deletion tests/support/services/mockGuildsModule.c
Expand Up @@ -9,6 +9,7 @@ private string guild = "";
private int level = 0; private int level = 0;
private int experience = 0; private int experience = 0;
private object guildObj = 0; private object guildObj = 0;
private string rank = "";


///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
public void ToggleMockGuilds() public void ToggleMockGuilds()
Expand All @@ -35,6 +36,12 @@ public void SetLevel(int newLevel)
level = newLevel; level = newLevel;
} }


/////////////////////////////////////////////////////////////////////////////
public void SetRank(string newRank)
{
rank = newRank;
}

///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
public void SetExperience(int exp) public void SetExperience(int exp)
{ {
Expand Down Expand Up @@ -66,6 +73,12 @@ public nomask int guildLevel(string check)
return (guild == check) ? level : 0; return (guild == check) ? level : 0;
} }


/////////////////////////////////////////////////////////////////////////////
public nomask string guildRank(string check)
{
return (guild == check) ? rank : 0;
}

///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
public nomask int guildExperience(string check) public nomask int guildExperience(string check)
{ {
Expand Down Expand Up @@ -100,4 +113,3 @@ public nomask int costToAdvanceSkill(string skillType)
{ {
return guildObj ? guildObj->costToAdvanceSkillOfType(skillType) : 2; return guildObj ? guildObj->costToAdvanceSkillOfType(skillType) : 2;
} }

0 comments on commit 16a8251

Please sign in to comment.