Random hero theory

ChrisH36

Guy with Most Posts on Quiet Board.
Joined
May 20, 2003
Messages
15,042
Reaction score
4
Location
Temple Prime, Sarajevo
You know how in Footmen Frenzy by Hato, you can get a random hero from the tavern then it will randomly pick you one. I wonder how that is done.

In my theory, I can declare an array that holds unit type, up to the number of heroes + the secrets. Then whenever a random hero is done, that person gets a random number from 0-max and that number will reference an element in the array. Like if you get 0, you can get Paladin or if you get 35: you get Bill.

But there must be another way in theory. Well declaring an array takes up memory on your PC. Its the size of a Unit Object (like footman or something's info) x the max number of elements. You can easily blow a high amount of space, but its more efficient.

Why I want to know this? Well, maybe there is a way that you don't really need an array, have to blow memory then destroy it (all wanted memory such as variables are destroyed when the game ends). I can figure it out, but some input would help!
 

Octopor

your whole family is made of meat
Joined
Nov 28, 2003
Messages
2,043
Reaction score
2
Unit Aquires Item

Item equal to "Random Hero"

If Then Else:

If Random Integer between 1 and (ammount of heroes) is equal to 1 (or whatever).
Then create hero for owner of triggering unit at region.
Else do nothing.
 

Dream_Walker

BattleForums Senior Member
Joined
Feb 20, 2005
Messages
1,924
Reaction score
0
Location
Arcanum
I think you are right Chris. Maybe we should put that in our map Marc :O
 

ChrisH36

Guy with Most Posts on Quiet Board.
Joined
May 20, 2003
Messages
15,042
Reaction score
4
Location
Temple Prime, Sarajevo
I know how the trigger works Marc, its my theory and its the only one that I know works. Besides, indexes start at 0.
 

Octopor

your whole family is made of meat
Joined
Nov 28, 2003
Messages
2,043
Reaction score
2
Hellwolf_36 said:
I know how the trigger works Marc, its my theory and its the only one that I know works. Besides, indexes start at 0.
I'm not talking about indexes.
 

ChrisH36

Guy with Most Posts on Quiet Board.
Joined
May 20, 2003
Messages
15,042
Reaction score
4
Location
Temple Prime, Sarajevo
If you don't use indexes. You would need 1-whatever maximum heroes you can have in one huge ass if statement chain. Variables are good for these reasons :).
 

x42bn6

Retired Staff
Joined
Nov 11, 2002
Messages
15,150
Reaction score
2
Location
London, United Kingdom
You could generate all 36 heroes in a region, make them Neutral Hostile and make them invisible to all and get a trigger to pick a random unit inside that region, then change its user and make it visible, but that blows even more memory.

No, I think the above way is the only sensible way.

Besides, a 36-member array is nothing compared to the visual effects in games like D-Day.*
 

ChrisH36

Guy with Most Posts on Quiet Board.
Joined
May 20, 2003
Messages
15,042
Reaction score
4
Location
Temple Prime, Sarajevo
Well, the problem is when you allocate memory, you need to destroy it. Sometimes, memory isn't destroyed or destroyed completely, so you start getting small "data leaks". Also, you would need to display these heroes in a section of the map where nobody can see them.

But the memory of a hero depends on what makes up a "unit". If it's small, then its no problem. But if it's big... then there is a problem.
 

x42bn6

Retired Staff
Joined
Nov 11, 2002
Messages
15,150
Reaction score
2
Location
London, United Kingdom
Hellwolf_36 said:
Well, the problem is when you allocate memory, you need to destroy it. Sometimes, memory isn't destroyed or destroyed completely, so you start getting small "data leaks". Also, you would need to display these heroes in a section of the map where nobody can see them.

But the memory of a hero depends on what makes up a "unit". If it's small, then its no problem. But if it's big... then there is a problem.
I think Warcraft is secure enough for those memory leaks. Besides, the memory leaked from loading 36 models shouldn't be detrimental.*
 

ChrisH36

Guy with Most Posts on Quiet Board.
Joined
May 20, 2003
Messages
15,042
Reaction score
4
Location
Temple Prime, Sarajevo
Well, the array of units is probably a pointer to unit objects. So it will only take up the memory of what its pointing too. Like in C++, a class can have something like

char * y;

This is a char pointer that is currently Null. You can use Dynamic Memory Allocation to populate it with whatever you wanted. Like to put the word LOL in it, you would need to allocate 4 elements (1 byte/element up to 3, including the terminating byte).

Units might be classes in that case, so there would be a pointer of unit classes inside the program when you do this. So, I guess it would be fine, I will try it out and see if there is any changes.

Man this talk about arrays has really gone technical.
 

x42bn6

Retired Staff
Joined
Nov 11, 2002
Messages
15,150
Reaction score
2
Location
London, United Kingdom
You don't have to go that far. D-Day, one of the most complicated maps out there, has tons of variables and plenty of arrays. Yet the game seldom crashes on high-end computers (if ever). Memory leak? Nah.*
 

ChrisH36

Guy with Most Posts on Quiet Board.
Joined
May 20, 2003
Messages
15,042
Reaction score
4
Location
Temple Prime, Sarajevo
I guess the guy must be doing something dumb in that map like referencing outside the bounds of an array. The Fatal Error is a fail safe to avoid crashing the game too bad.
 

Forged

Premium Member
Joined
Nov 28, 2002
Messages
5,433
Reaction score
0
Location
Texas
Website
www.securegamers.com
Your idea for an array is the best way I can think of. Assign every Hero to a number in an array and then create a random number generator to pick one.
 

ChrisH36

Guy with Most Posts on Quiet Board.
Joined
May 20, 2003
Messages
15,042
Reaction score
4
Location
Temple Prime, Sarajevo
Heh, I guess I will implement it into my footmen frenzy then.
 

NewPosts

New threads

Top