MoLAoS Posted September 5, 2021 Report Share Posted September 5, 2021 (edited) So I'm trying to figure out the template files and the coding style is quite difficult for me. Both how stuff works in individual files and how groups of files interact. Part of it is probably that I am used to C++ but the organization is also just really foreign to the way I think of code. My current modification effort is to add a Requirements section to I think the entity component. How do I check whether a player has a unit created. Additionally is there an existing function to check if a specific building had a unit garrisoned. Also can you assign unit/structure ownership to other units and structures or only the player? My overall project is Majesty style and I need to be able to assign structures and units to the control of a "Guild". Like the Defenders(melee boys) Guildhall would own the main guild plus chapter houses plus all guild members plus for some of the more complex guilds various support buildings. Part of that is to make stuff easier for the AI. I'll also have to implement local resources. I think that part will probably be a bit easier than "ownership". class Requirements { private: vector<Unit*> structures; vector<Unit*> units; vector<Item*> items; vector<Upgrade*> upgrades; public: //get functions //add functions }; class Unit { private: Unit *owner; Requirements *requirements; public: //init //set/get Owner //Guild stuff private: //basically a clone of player resource code to enable limitations based on local building/guild wide resources }; That is how I would do it in C++ pseudocode. As you can see I've never met a problem that vector<*> can't be abused to solve. I'll have to dig up a way to do that in JS. Edited September 5, 2021 by MoLAoS Quote Link to comment Share on other sites More sharing options...
bb_ Posted September 5, 2021 Report Share Posted September 5, 2021 1 hour ago, MoLAoS said: Also can you assign unit/structure ownership to other units and structures or only the player? In the vanilla game, the ownership is handled by the ownership component, which assigns it to a player. Changing this to other entities requires cpp changes (as ownership is a cpp component (*cmpOwnership.*)). Not entirely sure what you want to do though. Any entity can call any entities components already. So if you e.g. wish to let one building issue a research in another building, you can simply do so by directly adding it in the queue: Query the ProductionQueue and call the "add to queue" function (don't know its name by heard, but should be easily found in ProductionQueue.js). If you want such a "Guild" building: make a Guild component which you add to the relevant building and let that handle whatever you want to let it do. (As advice make it a JS component, that makes querying other components much simpler) 1 hour ago, MoLAoS said: How do I check whether a player has a unit created. You can use the RangeManager for querying all units of a player. From javaScript code this can be done by Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetEntitiesByPlayer(playerID) From cpp code it works the same: query the component and call `GetEntitiesByPlayer` with the relevant playerID. From the return data (its an array) you then can check whatever condition on the entity. 1 hour ago, MoLAoS said: Additionally is there an existing function to check if a specific building had a unit garrisoned. Query the GarrissonHolder and call `GetEntities`. It will return you all units inside. Quote Link to comment Share on other sites More sharing options...
MoLAoS Posted September 5, 2021 Author Report Share Posted September 5, 2021 (edited) @bb_ Okay so make a Guild component with that stuff and add a getGuild function to Entity? I think Entity is the base template that Unit/Structure adds to. Can I replicate the player/faction resource storage for buildings in the JS files? Like you build a Guild from the builder or faction menu and it costs 12000res 5000res 4000res and then stores 10000/4000/3200 in local storage and uses that rather than my resource storage to build buildings and units it "owns"? ____________________ Separately, do you know whether the map check for building is defined in C++ or JS? Like if I want to have buildings that can only be built on specific tiles or one that is built on a tree or rock or on some other map object, where is that code stored? In my Glest overhaul for instance I set up the "foundation check" code so some buildings can only build on tiles containing a specially tagged rock. So say a 4 by 4 set of tiles all with a rock entity of the appropriate kind. I also did an adjacency check. So the Pyromancers Guild if built next to a volcano gets a tag that opens up bonus options. I think I already heard that can be done in JS. Edited September 5, 2021 by MoLAoS Quote Link to comment Share on other sites More sharing options...
Stan` Posted September 6, 2021 Report Share Posted September 6, 2021 10 hours ago, MoLAoS said: In my Glest overhaul for instance I set up the "foundation check" code so some buildings can only build on tiles containing a specially tagged rock. So say a 4 by 4 set of tiles all with a rock entity of the appropriate kind. You might be interested by https://code.wildfiregames.com/D2382 For the ability to produce other non moving entities see https://code.wildfiregames.com/D2657 https://code.wildfiregames.com/D2658 might also be of interest 10 hours ago, MoLAoS said: Separately, do you know whether the map check for building is defined in C++ or JS? Like if I want to have buildings that can only be built on specific tiles or one that is built on a tree or rock or on some other map object, where is that code stored? That's js. 10 hours ago, MoLAoS said: Can I replicate the player/faction resource storage for buildings in the JS files? Like you build a Guild from the builder or faction menu and it costs 12000res 5000res 4000res and then stores 10000/4000/3200 in local storage and uses that rather than my resource storage to build buildings and units it "owns"? You need to change commands.js to create such a command but I suppose it should work yes. Quote Link to comment Share on other sites More sharing options...
bb_ Posted September 6, 2021 Report Share Posted September 6, 2021 18 minutes ago, Stan` said: 10 hours ago, MoLAoS said: Separately, do you know whether the map check for building is defined in C++ or JS? Like if I want to have buildings that can only be built on specific tiles or one that is built on a tree or rock or on some other map object, where is that code stored? That's js. Not entirely accurate: you can pick up the code flow in buildRestriction.js (CheckPlacement), but the actual checks you are in the Obstruction cpp component (which is called from buildRestrictions, see the CheckFoundations calls). 10 hours ago, MoLAoS said: Okay so make a Guild component with that stuff and add a getGuild function to Entity? What would you need the "getGuild" function for? You can query the guild component just like any other component: Engine.QueryInterface(entityID, IID), where the IID is the IID of the component so for the guild you will probably use IID_Guild, you define this by ending your new component with Engine.RegisterComponentType(IID_Guild, "Guild", Guild); Assuming you name the component Guild and use "Guild" for the templates. 1 Quote Link to comment Share on other sites More sharing options...
Freagarach Posted September 6, 2021 Report Share Posted September 6, 2021 There is no local storage space for entities yet, but if this is all for easing the AIs mind, you might want to look at PetraAI code, she does similar things by delegating stuff to managers and workers https://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/ai/petra. 7 hours ago, Stan` said: You need to change commands.js to create such a command but I suppose it should work yes. It sounds more like it just costing that amount of resources but having a "default" amount in stock when created, although for maximum user control (e.g. how many resources should be in stock it indeed should be a user command). Quote Link to comment Share on other sites More sharing options...
MoLAoS Posted September 6, 2021 Author Report Share Posted September 6, 2021 1 hour ago, Freagarach said: There is no local storage space for entities yet, but if this is all for easing the AIs mind, you might want to look at PetraAI code, she does similar things by delegating stuff to managers and workers https://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/ai/petra. It sounds more like it just costing that amount of resources but having a "default" amount in stock when created, although for maximum user control (e.g. how many resources should be in stock it indeed should be a user command). There is a default stock when created but Guilds would be buying resources and producing and selling items or or spending gold or other resources on research and building guild buildings and recruiting heroes. In this particular case the player still makes some Guild decisions like whether to recruit heroes. That is how it works in GlestAE/Mandate. The Heroes have Majesty style AI. In my GAE fork I just exempted the units in the Majesty tech tree, essentially their version of mods, from the normal AI, and wrote a new Majesty style AI for them. I didn't test it a whole lot but you could mix regular AI controlled factions with both player and "enemy" Majesty factions. I did a game like that for funsies against the standard "Magitech" Glest tech tree factions. 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.