Author Topic: How do I limit a unit?  (Read 2134 times)

helldiver

  • Guest
How do I limit a unit?
« on: 14 March 2013, 12:08:43 »
Hey all, I'm having a difficult time testing things since the AI is spawning more than 1 special unit. For example, I have a special unit that has a pet, it's supposed to only have 1 of that pet, yet not only can I keep summoning more of them, but the AI is also zerging that pet (it's a special pet that makes that unit good).

<skill>
  <type value="produce"/>
  <name value="summon_pet"/>
  <ep-cost value="0"/>
  <speed value="1000"/>
  <anim-speed value="10"/>
  <animation path="models/klion_standing.g3d"/>
  <sound enabled="false"/>
  <pet value="true" max="1"/>
</skill>

Note I have Max=1 but GAE is ignoring that (I guess that's an MG only feature).

As I'm progressing along, the unlimited number of units is getting in the way, not so bad right now since I'm in the art phase, but soon things will get really bad when I start to put correct numbers in.

So I thought of using Static (hidden) resources to limit the number of units. Thing is each unit in a faction has limits, that means I'd have to declare about 12-14 static hidden resources (they cannot share the hidden resource otherwise you'd get around the limitation.

For example I'd like to create the following Static resources:

Unit1
Unit2
Unit3
Unit4
Unit5
Unit6
Hero1
Hero2
Hero3
Hero4
Hero5
Hero6

These would be used to set limits on specific units.

Things get even more complicated: There is a unit that has a pet, he can only have 1 of that pet. But you can have up to 5 of that unit and each can have his own pet. How to limit it so that only 1 per unit but if you have more of the parent unit each can have their pet?

I thank you guys so much for the help.

I really wonder why Daniel Santos removed unit limitations. Any of you awesome guys out there that can recompile GAE with that glest feature turned on?

I just realized something, I could go the Dawn of War route and let the player limit the units based on what units he prefers. Dur... Only thing I need to know if it's still ok to declare many hidden resources.
« Last Edit: 14 March 2013, 12:23:54 by helldiver »

MoLAoS

  • Ornithopter
  • *****
  • Posts: 433
    • View Profile
Re: How do I limit a unit?
« Reply #1 on: 14 March 2013, 22:22:27 »
Mandate has a function where you can specify a unit to be limited and it keeps track of how many exist and won't let you make new ones. It uses the <units-owned> tag. It should be possible to port this and only this feature to GAE if you don't want to deal with all of Mandate's other stuff.

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: How do I limit a unit?
« Reply #2 on: 14 March 2013, 23:34:08 »
The max attribute is the maximum number of that pet each master can have. If you want to limit a number globally, use a hidden resource. Basically, the unit requires a new, unique resource, and that resource should have the element <display value="false" />. This will prevent the resource from being displayed in the HUD. Anyway, give the faction one (or however many we're limiting to) in the faction XML. You can also optionally choose whether or not the resource is recouperable in the resource XML. If it's not recouperable, you can only build one period. If it is recouperable, you can only have one at a time.

https://docs.megaglest.org/XML/Resource
https://docs.megaglest.org/XML/Faction
« Last Edit: 18 June 2016, 14:52:56 by filux »
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

helldiver

  • Guest
Re: How do I limit a unit?
« Reply #3 on: 15 March 2013, 03:08:14 »
You guys are awesome!

Ok, so I can declare as many hidden resources as I want? Like faction 1 could have 12 hidden resources, faction 2 could have 5 and so on?

"The max attribute is the maximum number of that pet each master can have."

Yeah I knew that, but I was still able to spam the pet on that master (only had 1 master, yet I could spam the pet and it ignored the 1 Max limitation). I think the current build of GAE is ignoring the limitation, hrm.

I double checked and yeah it seems this feature was turned off. It's ignoring the Max attribute. Here's what my code looks like on the Master (parent).


<skill>
  <type value="produce"/>
  <name value="summon_pet"/>
  <ep-cost value="0"/>
  <speed value="1000"/>
  <anim-speed value="20"/>
  <animation path="models/klion_summon.g3d"/>
  <sound enabled="false"/>
  <pet value="true" max="1"/>
</skill>

<command>
    <type value="produce"/>
    <name value="call_pet"/>
    <image path="../pet/images/pet.bmp" />
    <unit-requirements />
    <upgrade-requirements />
    <produce-skill value="summon_pet"/>
    <produced-unit name="pet"/>
</command>

According to what you said and what I read on the wiki, the above master should only be able to summon 1 pet, correct? If I have 5 of the same master, each can have 1 of that pet. Correct?

Right now, the above master can spam the produce command and make many of the same pet :(
« Last Edit: 15 March 2013, 03:46:17 by helldiver »

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: How do I limit a unit?
« Reply #4 on: 15 March 2013, 09:40:07 »
Strange that the max attribute is being ignored. At any rate, yes, you can have as many hidden resources as you want (there's probably some hard limit, but it would be very high). Note that resources are techtree specific, not faction. Doesn't really make a difference when they're hidden, though. Also, hidden resources are just regular resources that aren't shown in the GUI.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert