H3 HoMM Map / Heroes Castles storing units

FannyShaver

Well-Known Member
Reaction score
31
Hi there.

I am in the process of making a Heroes of Might and Magic 3 map. I know there's hardly any community left in Warcraft 3 and it will be lot more likely it will go down rather than up, but just in case if Warcraft 4 comes out in the next 60 years when I am still alive I might be able to move it overthere.

I am trying to use the same principal Heroes 3 had to offer, but in a real time strategy. By this I mean, there will be still Heroes and Castles with armies on board, however, battlefield will be a real time, so will need to prepare strategies quick, regroup, cast spells etc.

I have all the units ready and their abilities in vast majority completed, just few ones waiting. The problem that I've got is storing the actual units within Heroes (up to three per player) and Castles (there's shitloads). And of course, there are different races, so I am wondering if there is anyone who could suggest me a good and fairly straightforward way of coding it. I have done my fair share of more complicated things and I can easily work on even expert level, as long as I have a good base to work on.

Any help much appreciated.
 

jonas

You can change this now in User CP.
Reaction score
66
Just use multiple arrays. How many types of units and castles do you have?

int variable "containers": counts number of containers (heroes/castles) currently on the map
Array one: container unit
Then if #units * (#containers) < 8000, I suggest
Array two: two dimensional array where you count for each index in array one and each type of unit, how many units of that type are in the container with that index.
If you have more, I suggest one array per unit type.


Then you just remove/create the units on demand, and update the numbers accordingly. E.g., if you want to move units from one container to another, loop through the first array to find the indices of the two containers, then subtract numbers from one index and add them to the other.

Note that this only works if you have less than a thousand or so containers :p
 

FannyShaver

Well-Known Member
Reaction score
31
Can you provide an example as I have to admit I am lost. Maximum number of containers is number of cities possible (47 I think) +3x12 for heroes. Random creeps on the field will be randomized and adjusted with regards to the game duration.
 
Last edited:

Accname

2D-Graphics enthusiast
Reaction score
1,462
Could you explain what a "Heroes of Might and Magic 3 map" is? I am not familiar with that game and as such I dont understand your question.
 

FannyShaver

Well-Known Member
Reaction score
31
Heroes of Might and Magic 3 is a turn based game where you control heroes and castles. Units you have are stored either as a garnison in your town or an army your hero is commanding. Upon attack, either a castle or another hero, whatever armies are stored within target are used during turn based battle.

So in Warcraft 3 sence, Beastmaster has 2 pigs and a Death Knight has 2 skeletons. Pigs and skeletons are not visible until either of these two heroes attack each other. Then heroes just watch their minions sort it out between themselves.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Do you want to store the units in between fights or do you want to re-create them?
If you want to store them you need some place to put them. For example some portion of the map that is cut off from the rest. Alternatively you may try to abuse some jass to move them outside of the map bounds. This is possible but can occasionally become a problem.

Either way:
1) You need to identify the hero / town where units are stored. For this you could give them a unique ID. You can use the custom value of a unit to store the unique ID.
2) You can use the ID of a hero / town to adress a unit group (if you keep the units on the map) or an array of unit types (if you want to create them when a battle starts)

Its really straight forward and simple.
 

jonas

You can change this now in User CP.
Reaction score
66
Do you want to store the units in between fights or do you want to re-create them?
I definetly advise recreating them.

1) You need to identify the hero / town where units are stored. For this you could give them a unique ID. You can use the custom value of a unit to store the unique ID.
For 80 units creating a unique indexing system is overkill, and using straight forward indexing sets you up for problems if you later want to use an indexing system. Just use linear search in an array.

2) an array of unit types (if you want to create them when a battle starts)
Well, in the original game units of the same type can stack up to hundreds, so you would also need an array of unit counts (larger stacks deal more damage, and units die from the stack when the stack is dealt damage). Not sure how to implement that either, maybe with buffs.
 

FannyShaver

Well-Known Member
Reaction score
31
In here if you have 100 angels, you will have 100 individual angels. Units will be lot more expensive, so there will not be a masses really. Can someone give an example of the system that I can use?

Basically, during a fight I will need to gather, in a rather simple way a data of the attacker (heroID and armies stored somehow, which is something like that:

1=20
2=10
3=4
4=3
5=2
6=2
7=1

First number standing for a creature type, second for a number. Of course it could be shortened into [20,10,4,3,2,2,1])

Units then will be created based on figures above and adjusted by race, then created. After battle, numbers will be counted for viciorious side and adjusted again.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
I definetly advise recreating them.
I definitely dont.
The way variables in the editor work makes it hard to do multi dimensional dynamic data structures (which are needed here). However, it is very much possible to have an array of unit groups which is naturally multi dimensional (and perfect for the job!).

For 80 units creating a unique indexing system is overkill, and using straight forward indexing sets you up for problems if you later want to use an indexing system. Just use linear search in an array.
No its not. Just give each hero and/or town a continuous ID.

Well, in the original game units of the same type can stack up to hundreds, so you would also need an array of unit counts (larger stacks deal more damage, and units die from the stack when the stack is dealt damage). Not sure how to implement that either, maybe with buffs.
This many units are not going to work in WC3 anyways. The game engine bugs with more then a few hundred units on the field. If this is supposed to be a multiplayer game OP will have to cut down the unit numbers for sure.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
I just made an example map which will show you how you >can< do it.
Depending on the actual number of units you want to use this might not be the best solution. I would say this will work great up to a total of maybe 200 units (counting ALL players). If you want to have several dozen, or up to hundreds of units per player you may want to go with the alternative approach of storing the unit types and numbers instead of actual units.
 

Attachments

  • Homm.w3x
    15.2 KB · Views: 340

FannyShaver

Well-Known Member
Reaction score
31
Specific units are only playable during battles. Other than that there are only very few creeps available on the map and who do nothing apart from travelling and exploring.
 

jonas

You can change this now in User CP.
Reaction score
66
I definitely dont.
The way variables in the editor work makes it hard to do multi dimensional dynamic data structures (which are needed here). However, it is very much possible to have an array of unit groups which is naturally multi dimensional (and perfect for the job!).
No, because with 40+ containers you could at most keep four or so units per container for exactly the reasons you mention somewhere else, plus keeping the units around causes lots of other problems (you need to put them somewhere, remove buffs from the last combat, etc.).

No its not. Just give each hero and/or town a continuous ID.
jonas said:
and using straight forward indexing sets you up for problems if you later want to use an indexing system


This many units are not going to work in WC3 anyways. The game engine bugs with more then a few hundred units on the field. If this is supposed to be a multiplayer game OP will have to cut down the unit numbers for sure.
jonas said:
units of the same type can stack up
You don't have 50 individual entities, you have one controllable entity with 50 unit stacks. I think usually about 5 or so per hero and about 15 or so per castle. If you model one stack with one unit, you won't have more than 20 or so units on the field unless you plan to keep them all around (as you suggest above).
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
No, because with 40+ containers you could at most keep four or so units per container for exactly the reasons you mention somewhere else, plus keeping the units around causes lots of other problems (you need to put them somewhere, remove buffs from the last combat, etc.).
Have a look at the demo map. Keeping them around is pretty simple and straight forward in the WC3 editor. Creating a two dimensional data structure (with GUI) is much more complicated in comparison. I dont know exactly what the OP needs so I cant tell whether it would be more comfortable to create new units or reusing the old ones. Does he want units to stay damaged in between fights? Or should be they be healed? Does he want buffs to stay? Items to stay? I dont know. Whether one system is better then the other is really hard to decide without the specifics. For this reason I recommend going with the most simple solution first.

You don't have 50 individual entities, you have one controllable entity with 50 unit stacks. I think usually about 5 or so per hero and about 15 or so per castle. If you model one stack with one unit, you won't have more than 20 or so units on the field unless you plan to keep them all around (as you suggest above).
A few hundred units are not that big a problem if you put them away. Check out the test map, its pretty simple. You move the units outside of the map bounds. You also pause them and deactivate their collision. With this setup the overhead for unused units is very small. They dont need to be rendered on screen, no collision detection, no auto-attack or auto-cast update cycles, etc.
 

jonas

You can change this now in User CP.
Reaction score
66
Whether one system is better than the other is really hard to decide without the specifics.

I agree. By the way, did you know that there is HoMM 3 for the GBA? I played some of it on an emulator on my phone a while back, you should try it out.
 

FannyShaver

Well-Known Member
Reaction score
31
Trigger:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Unit-type of (Triggering unit)) Equal to Castle HQ
        • ((Trained unit) is A Hero) Equal to True
      • Then - Actions
        • Set HeroCount = (HeroCount + 1)
        • Set Hero[HeroCount] = (Trained unit)
        • Set Stack1[HeroCount] = Squire
        • Set Stack2[HeroCount] = Spearman
        • Set Stack3[HeroCount] = Griffin
        • Set Stack4[HeroCount] = Crusader
        • Set Stack5[HeroCount] = Zealot
        • Set Stack6[HeroCount] = Champion
        • Set Stack7[HeroCount] = Archangel
        • Set StackSize1[HeroCount] = 25
        • Set StackSize2[HeroCount] = 10
        • Set StackSize3[HeroCount] = 0
        • Set StackSize4[HeroCount] = 0
        • Set StackSize5[HeroCount] = 0
        • Set StackSize6[HeroCount] = 0
        • Set StackSize7[HeroCount] = 0
        • Game - Display to (All players) the text: (String((Custom value of Hero[HeroCount])))
        • Unit - Move Hero[HeroCount] instantly to (Center of WorldMap &lt;gen&gt;)
      • Else - Actions


Now, the problem that I've got is, when I have multiple heroes or castles all marked as a Hero[HeroCount] the spawned units are just based off the last knowing [HeroCount]. I was told I need to loop it somehow in order to have this working:

Trigger:
  • Then - Actions
    • Set AttackerCount = (AttackerCount + 1)
    • Set Attacker[AttackerCount] = (Attacking unit)
    • Set Stack1a[AttackerCount] = Stack1[HeroCount]
    • Set Stack2a[AttackerCount] = Stack2[HeroCount]
    • Set Stack3a[AttackerCount] = Stack3[HeroCount]
    • Set Stack4a[AttackerCount] = Stack4[HeroCount]
    • Set Stack5a[AttackerCount] = Stack5[HeroCount]
    • Set Stack6a[AttackerCount] = Stack6[HeroCount]
    • Set Stack7a[AttackerCount] = Stack7[HeroCount]
    • Set StackSize1a[AttackerCount] = StackSize1[HeroCount]
    • Set StackSize2a[AttackerCount] = StackSize2[HeroCount]
    • Set StackSize3a[AttackerCount] = StackSize3[HeroCount]
    • Set StackSize4a[AttackerCount] = StackSize4[HeroCount]
    • Set StackSize5a[AttackerCount] = StackSize5[HeroCount]
    • Set StackSize6a[AttackerCount] = StackSize6[HeroCount]
    • Set StackSize7a[AttackerCount] = StackSize7[HeroCount]
    • Set DefenderCount = (DefenderCount + 1)
    • Set Defender[DefenderCount] = (Attacked unit)
    • Set Stack1d[DefenderCount] = Stack1[HeroCount]
    • Set StackSize1d[DefenderCount] = StackSize1[HeroCount]
    • Unit - Create StackSize1a[AttackerCount] Stack1a[AttackerCount] for (Owner of Attacker[AttackerCount]) at (Center of Attacker &lt;gen&gt;) facing Default building facing degrees
    • Unit - Create StackSize2a[AttackerCount] Stack2a[AttackerCount] for (Owner of Attacker[AttackerCount]) at (Center of Attacker &lt;gen&gt;) facing Default building facing degrees
    • Unit - Create StackSize1d[DefenderCount] Stack1d[DefenderCount] for (Owner of Defender[DefenderCount]) at (Center of Defender &lt;gen&gt;) facing Default building facing degrees
    • Trigger - Turn off (This trigger)


Any ideas?
 

jonas

You can change this now in User CP.
Reaction score
66
You already have set Hero[HeroCount] = (Trained unit)

After that do

Code:
for loop integer A from 1 to HeroCount
    if Attacking unit == Hero[A]
        set AttackerId = A
// using AttackerId is unsafe here unless you know that all attacking units are stored as Hero
set Xa[...] = X[AttackerId]
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
I would really suggest using the custom value to store the heroID of each hero. Just like the demo map I made.
Unless you already use the custom value of course. In that case use a Hash Table.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Well then you are obviously doing something wrong. Perhaps you could show us the trigger where you set the ID and the trigger where you check it (to see that its 0)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top