wowgetoffyourcellphone Posted June 14, 2016 Report Share Posted June 14, 2016 (edited) Hi. So in my mod I remove the "wooden defense tower" and just have one defense tower like in earlier alpha. But, it starts out as wood, and in Town Phase (City Phase for Celts) player can upgrade the wooden defense tower to stone defense tower. This use actor replace code in tech. Everything works great except two things -- 1 (most impoertant problem), in the fog of war the stone towers revert back to original wooden tower actor, and 2, when building a new stone tower what rises from the ground is the old wooden actor. Here is the tech: { "genericName": "Stone Towers", "description": ".", "cost": {"food": 0, "wood": 0, "stone": 500, "metal": 0}, "requirements": {"tech": "phase_town"}, "requirementsTooltip": "Unlocked in Town Phase.", "icon": "stone_towers.png", "researchTime": 40, "tooltip": "Upgrade wooden defense towers to stone defense towers. +100% health, +100 stone cost. Unlocks Oxybeles Towers.", "modifications": [ {"value": "Cost/Resources/stone", "add": 100}, {"value": "Health/Max", "multiply": 2}, {"value": "VisualActor/Actor", "replace": "structures/hellenes/scout_tower.xml"} ], "affects": ["DefenseTower"], "soundComplete": "interface/alarm/alarm_upgradearmory.xml" } If you guys are going to show Civic Centers upgrading visual actor with phases, then this is something that should be fix, since that feature will probably use the same or similar kind of tech modification (unless you go really weird and do some kind of entity promotion). Edited June 14, 2016 by wowgetoffyourcellphone Quote Link to comment Share on other sites More sharing options...
sanderd17 Posted June 14, 2016 Report Share Posted June 14, 2016 Oh, yeah. Actor upgrades were probably a code design mistake from my side. It's not versatile enough and causes some problems. I'd like to design something new that should work better and be more versatile. 1 Quote Link to comment Share on other sites More sharing options...
sanderd17 Posted June 14, 2016 Report Share Posted June 14, 2016 Got something here that you may want to give a try. Instead of switching complete actors, it selects different variants of actors. This way you can f.e. just change some prop for another (and props can be very big, you could f.e. define almost nothing on the base actor, and define completely different meshes on the props to get a full replacement). Here's some code you can put in your mod (it will eventually arrive in the main game too, but it's still experimental, so the exact schema can still change a bit): simulation/components/interfaces/TechnologyVariants.js: Engine.RegisterInterface("TechnologyVariants"); simulation/components/TechnologyVariants.js: function TechnologyVariants() {} TechnologyVariants.prototype.Schema = "<a:example>" + "<Phase datatype='tokens'>" + "phase_village:villageVariant" + "phase_town:townVariant" + "phase_city:cityVariant" + "</Phase>" + "</a:example>" + "<oneOrMore>" + "<element a:help='Set of variants chosen per tech'>" + "<anyName/>" + "<attribute name='datatype'>" + "<value>tokens</value>" + "</attribute>" + "<text/>" + "</element>" + "</oneOrMore>"; TechnologyVariants.prototype.Init = function() {}; TechnologyVariants.prototype.Serialize = null; /** * Clean the technology variants * @param checkTech Used when there's only one tech to check */ TechnologyVariants.prototype.Clean = function(checkTech = null) { let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); let cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); if (!cmpVisual || !cmpTechnologyManager) return; for (let setName in this.template) { let chosenActor = ""; let techFound = false; for (let token of this.template[setName]._string.split(/\s+/g)) { let [techName, actorName] = token.split(":"); if (techName == checkTech) techFound = true; if (cmpTechnologyManager.IsTechnologyResearched(techName)) chosenActor = actorName; } // update the variant if the researched tech was used, // or if there was a total clean requested if (techFound || !checkTech) cmpVisual.SetVariant("technology_" + setName, chosenActor); } }; TechnologyVariants.prototype.OnGlobalResearchFinished = function(msg) { if (IsOwnedByPlayer(msg.player, this.entity)) this.Clean(msg.tech); }; TechnologyVariants.prototype.OnOwnershipChanged = function(msg) { if (msg.to != -1) this.Clean(); }; Engine.RegisterComponentType(IID_TechnologyVariants, "TechnologyVariants", TechnologyVariants); Then the XML part in the entity template can look like this. <TechnologyVariants> <Phase datatype="tokens"> phase_village:villageVariant phase_town:townVariant phase_city:cityVariant </Phase> <Armour datatype="tokens"> tech_armour:extraShieldsVariant </Armour> </TechnologyVariants> The template above has two groups (here "Phase" and "Armour"), you can put in as many groups of selections you want, and the name doesn't matter. Then for every group, the code will look at the list of possible selections, and will chose the last one that has the tech researched. F.e. when you're in town phase, both "phase_village" and "phase_town" are researched, but the code will pick the variant that goes with "phase_town" (in this case, the variant names "townVariant"). If no techs of the set are researched, it should just show the default actor (depending on the frequencies), so as long as "tech_armour" isn't researched, it will show the default, but from the moment that tech is researched, it will show the "extraShieldsVariant". It works quite similar to damage variants (which is why this change was so easy to implement now). F.e. in the iberian fire ship actor, there's a group of variants depending on health (with variants like lightdamage, mediumdamage, ...). And when you use this piece of code, you will need to make groups of variants that match the groups in the template. So the code can pick one variant from the group and not unselect other choices.. Quote Link to comment Share on other sites More sharing options...
sanderd17 Posted June 14, 2016 Report Share Posted June 14, 2016 Second thought, that won't work with foundations or mirages yet either. But it would just need #2951 to fix it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.