Jump to content

Extending {civ} function in <Builder>


Recommended Posts

Hi. I was attempting to greatly simplify all of the builder units in the game, namely infantry, by removing their builder components in each individual file, something like 50 files. I then just made one master list in the generic infantry template using the {civ} tag for all, thinking the individual soldiers would just be able to build the buildings they have in their civ.

For example.

Instead of 50 individual soldiers having this in their templates:


  <Builder>
    <Entities datatype="tokens">
      structures/{civ}_catapult
	  structures/sele_military_colony
      structures/sele_library
      structures/sele_wonder
    </Entities>
  </Builder>

I created one glorious, beautiful master list in the template_unit_infantry:

 

  <Builder>
    <Rate>1.0</Rate>
    <Entities datatype="tokens">
      structures/{civ}_civil_centre
      structures/{civ}_military_colony
      structures/{civ}_house
      structures/{civ}_storehouse
      structures/{civ}_farmstead
      structures/{civ}_field
      structures/{civ}_rotarymill
      structures/{civ}_corral
      structures/{civ}_dock
      structures/{civ}_shipyard
      structures/{civ}_market
      structures/{civ}_pillar_ashoka
      structures/{civ}_outpost
      structures/{civ}_defense_tower
      other/wallset_palisade
      structures/{civ}_wallset_short
      structures/{civ}_wallset_stone
      structures/{civ}_wallset_siege
      structures/{civ}_barracks
      structures/{civ}_stables
      structures/{civ}_barracks_aux
      structures/{civ}_elephant_stables
      structures/{civ}_embassy_celtic
      structures/{civ}_embassy_iberian
      structures/{civ}_embassy_italiote
      structures/{civ}_syssiton
      structures/{civ}_gymnasion
      structures/{civ}_blacksmith
      structures/{civ}_kennel
      structures/{civ}_government_center
      structures/{civ}_statue
      structures/{civ}_temple
      structures/{civ}_temple_vesta
      structures/{civ}_arch
      structures/{civ}_theatron
      structures/{civ}_library
      structures/{civ}_lighthouse
      structures/{civ}_apadana
      structures/{civ}_prytaneion
      structures/{civ}_army_camp
      structures/{civ}_fortress
      structures/{civ}_catapult
      structures/{civ}_wonder
    </Entities>
  </Builder>

 

I did this thinking it would work, since something almost exactly the same works for the ProductionQueue element for training units:

  <ProductionQueue>
    <BatchTimeModifier>0.8</BatchTimeModifier>
	<Entities datatype="tokens">
	  units/{civ}_infantry_spearman_b
	  units/{civ}_infantry_pikeman_b
	  units/{civ}_infantry_swordsman_b
	  units/{civ}_infantry_javelinist_b
	  units/{civ}_infantry_slinger_b
	  units/{civ}_infantry_archer_b
	  units/{civ}_infantry_crossbowman_b
	  units/{civ}_cavalry_swordsman_b
	  units/{civ}_cavalry_spearman_b
	  units/{civ}_cavalry_javelinist_b
	  units/{civ}_cavalry_archer_b
	  units/{civ}_cavalry_crossbowman_b
	</Entities>
    <Technologies datatype="tokens">
	  training_levy_infantry
	  training_mobilization
	  training_total_war
    </Technologies>
  </ProductionQueue>

 

See, when training units it just picks the right units based on what is available for the civ. Can this be extended to the <Builder> component too? Otherwise I get this nastiness:

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_barracks_aux.xml"

ERROR: Failed to load entity template 'structures/chin_barracks_aux'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_elephant_stables.xml"

ERROR: Failed to load entity template 'structures/chin_elephant_stables'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_embassy_celtic.xml"

ERROR: Failed to load entity template 'structures/chin_embassy_celtic'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_embassy_iberian.xml"

ERROR: Failed to load entity template 'structures/chin_embassy_iberian'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_military_colony.xml"

ERROR: Failed to load entity template 'structures/chin_military_colony'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_rotarymill.xml"

ERROR: Failed to load entity template 'structures/chin_rotarymill'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_pillar_ashoka.xml"

ERROR: Failed to load entity template 'structures/chin_pillar_ashoka'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_wallset_short.xml"

ERROR: Failed to load entity template 'structures/chin_wallset_short'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_wallset_siege.xml"

ERROR: Failed to load entity template 'structures/chin_wallset_siege'

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_stables.xml"

 

This can be done to the public mod templates too, if we can get this to work. One benefit, besides template cleanliness and consistency, is that you can now put the RotaryMill, for example, in the GUI next to the Farmstead where it belongs, whereas currently it's put at the end of the GUI list with the Fortress because the tokens are always added to the end.

Edited by wowgetoffyourcellphone
Link to comment
Share on other sites

You mean that in Builder there is an error and that it's not just skipped? If so, it should be easy to fix/change.

For the gui you can also remove and readd tokens to have it in the right place (which is awfull :p). For example if you have A B D and you want to insert C, you need to do -D C D or something like that.

(In general, I am - it's only personal and not really related to that post- more for adding things where there must be instead of removing things or having easter egg popping up. I think more of ProductionQueue list talking of that.)

Link to comment
Share on other sites

8 minutes ago, fatherbushido said:

You mean that in Builder there is an error and that it's not just skipped? If so, it should be easy to fix/change.

 

Yes. Could be an error or oversight.

 

8 minutes ago, fatherbushido said:

(In general, I am - it's only personal and not really related to that post- more for adding things where there must be instead of removing things or having easter egg popping up. I think more of ProductionQueue list talking of that.)

Well, with a master list and code that properly does the {civ} thing you don't have to add or remove anything! :) Only in very specific cases.

Edited by wowgetoffyourcellphone
Link to comment
Share on other sites

Index: binaries/data/mods/public/simulation/components/Builder.js
===================================================================
--- binaries/data/mods/public/simulation/components/Builder.js    (révision 19732)
+++ binaries/data/mods/public/simulation/components/Builder.js    (copie de travail)
@@ -42,7 +42,10 @@
         return entities;
 
     let disabledTemplates = cmpPlayer.GetDisabledTemplates();
-    return entities.filter(ent => !disabledTemplates[ent]);
+
+    var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
+
+    return entities.filter(ent => !disabledTemplates[ent] && cmpTemplateManager.TemplateExists(ent));
 };
 
Builder.prototype.GetRange = function()

That should work.

 

Link to comment
Share on other sites

Your fix actually does work in-game. I select the dude and get no error and the correct buildings are there in the GUI as expected. I couldn't get the diff to work, was rejected, but I found and replaced the right lines of code. No more error, EXCEPT.....

 

When I open structree.

 

ERROR: CCacheLoader failed to find archived or source file for: "simulation/templates/structures/chin_military_colony.xml"

ERROR: Failed to load entity template 'structures/chin_military_colony'

ERROR: Invalid template found for 'structures/chin_military_colony'

ERROR: JavaScript error: gui/structree/helper.js line 19 TypeError: data is undefined loadTemplate@gui/structree/helper.js:19:1 loadStructure@gui/structree/load.js:51:17 selectCiv@gui/structree/structree.js:90:1 __eventhandler238 (selectionchange)@civSelection selectionchange:0:1 init@gui/structree/structree.js:36:27 openStrucTree@gui/session/menu.js:1027:1 __eventhandler214 (press)@civIconOverlay press:0:1

ERROR: GUI page 'page_structree.xml': Failed to call init() function

Edited by wowgetoffyourcellphone
Link to comment
Share on other sites

Index: binaries/data/mods/public/gui/structree/load.js
Thx for testing @wowgetoffyourcellphone

Index: binaries/data/mods/public/gui/structree/load.js
===================================================================
--- binaries/data/mods/public/gui/structree/load.js	(révision 19732)
+++ binaries/data/mods/public/gui/structree/load.js	(copie de travail)
@@ -48,6 +48,8 @@
 
 function loadStructure(templateName)
 {
+	if (!Engine.TemplateExists(templateName))
+		return null;
 	let template = loadTemplate(templateName);
 	let structure = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_CurrentModifiers);
 
Index: binaries/data/mods/public/simulation/components/Builder.js
===================================================================
--- binaries/data/mods/public/simulation/components/Builder.js	(révision 19732)
+++ binaries/data/mods/public/simulation/components/Builder.js	(copie de travail)
@@ -42,7 +42,10 @@
 		return entities;
 
 	let disabledTemplates = cmpPlayer.GetDisabledTemplates();
-	return entities.filter(ent => !disabledTemplates[ent]);
+
+	var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
+
+	return entities.filter(ent => !disabledTemplates[ent] && cmpTemplateManager.TemplateExists(ent));
 };
 
 Builder.prototype.GetRange = function()

 

That one should apply properly. Highly experimental (not tested) for the structree part

  • Like 1
Link to comment
Share on other sites

@fatherbushido This is what I get with that patch when I select a builder:

 

ERROR: JavaScript error: simulation/components/Builder.js line 48 ReferenceError: disabledEntities is not defined Builder.prototype.GetEntitiesList/<@simulation/components/Builder.js:48:32 Builder.prototype.GetEntitiesList@simulation/components/Builder.js:48:9 GuiInterface.prototype.GetAllBuildableEntities@simulation/components/GuiInterface.js:857:24 GuiInterface.prototype.ScriptCall@simulation/components/GuiInterface.js:2016:10 getAllBuildableEntities@gui/session/unit_commands.js:210:9 getAllBuildableEntitiesFromSelection@gui/session/unit_commands.js:216:28 g_SelectionPanels.Construction.getItems@gui/session/selection_panels.js:241:10 setupUnitPanel@gui/session/unit_commands.js:59:14 updateUnitCommands@gui/session/unit_commands.js:147:4 updateSelectionDetails@gui/session/selection_details.js:493:2 updateGUIObjects@gui/session/session.js:868:2 onTick@gui/session/session.js:746:3 __eventhandler106 (tick)@sn tick:0:1

ERROR: Error calling component script function ScriptCall

ERROR: JavaScript error: simulation/components/Builder.js line 48 ReferenceError: disabledEntities is not defined Builder.prototype.GetEntitiesList/<@simulation/components/Builder.js:48:32 Builder.prototype.GetEntitiesList@simulation/components/Builder.js:48:9 GuiInterface.prototype.GetAllBuildableEntities@simulation/components/GuiInterface.js:857:24 GuiInterface.prototype.ScriptCall@simulation/components/GuiInterface.js:2016:10 getAllBuildableEntities@gui/session/unit_commands.js:210:9 getAllBuildableEntitiesFromSelection@gui/session/unit_commands.js:216:28 g_SelectionPanels.Construction.getItems@gui/session/selection_panels.js:241:10 setupUnitPanel@gui/session/unit_commands.js:59:14 updateUnitCommands@gui/session/unit_commands.js:147:4 updateSelectionDetails@gui/session/selection_details.js:493:2 updateGUIObjects@gui/session/session.js:868:2 onSimulationUpdate@gui/session/session.js:805:2 __eventhandler107 (simulationupdate)@sn simulationupdate:0:1

Edited by wowgetoffyourcellphone
Link to comment
Share on other sites

5 minutes ago, fatherbushido said:

Yes reapply, I edited it, I used a wrong var name :/

Okay, the unit selections/gui stuff is good, and the original structree error is gone. Now I get one final error with structree:

 

ERROR: JavaScript error: gui/structree/helper.js line 176 TypeError: template is null GetPhaseOfTemplate@gui/structree/helper.js:176:6 selectCiv@gui/structree/structree.js:181:22 __eventhandler221 (selectionchange)@civSelection selectionchange:0:1 init@gui/structree/structree.js:36:27 openStrucTree@gui/session/menu.js:1027:1 __eventhandler197 (press)@civIconOverlay press:0:1

ERROR: GUI page 'page_structree.xml': Failed to call init() function

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...