Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Counters in a UDT

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 28th Sep 2011 22:12
After watching DCForemans excellent timer tutorial i was inspired to use it to help me with a little test program i am trying to make at the moment, but i have become a little stuck finding the best solution for the problem.

I have a UDT representing a faction (i have spawned 5 factions).

In this faction they all start of with a similar amount of cash and peasants. Now in the end i want them to all make simple decisions based on their current tactic on what to do with the money and who to attack and what. All this is very complicated for me but ill get round to it. The simple bits though is i want to build a counter that adds 1 peasant every 5 seconds and every 45 seconds tax is gathered on how many peasants a faction has (5g per 45 seconds per peasant). A nice and simple equation with a reasonably simple counter.

Firstly i made a seconds counter based on Timer(). When the factions are spawned (all 5 are spawned in the beginning but more will come later when some are destroyed), they each have their own counter from the second they spawned. So all at first start on 0, pretty simple stuff, then it increments just like seconds. If one were spawned later that would also work. This is part of the UDT for that faction and it all works fine.

Now i have had to add a counter in the UDT for each faction saying that every 5 seconds of the factions life increase the peasant numbers by 1. So now i have a timer that says how long the game has been going as a global and how long the faction has been going in the UDT and a counter in the UDT that keeps getting reset every 5 seconds.

So now how do i do another counter for the money. Do i really need to make another counter for this in the UDT. Then after that what about when i want it to make a desicion. I want it thinking about what its doing next after so many seconds (a slightly random amount) so they dont all do stuff at once and it appears more humanlike. Another counter in the UDT? My UDT will be full of resettable counters. This cant be the only way. I think im missing something by a long shot but its just not obvious to me after thinking about it for a while.

Can anyone help?
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 29th Sep 2011 18:04
If by "Counter" you mean each variable as an integer that is set to the value of Timer(), then there's a much easier way of sorting this stuff out.



This is just a simple example I've thrown together - I don't think there's any easier way to do this, and it's worked well for me in the past. Hope it helps!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 30th Sep 2011 13:05
Thanks for your reply Rob. Its as i suspected and feared by the looks of it then

I thought thats how i might have to do it so basically i have a counter for every thing that happens for every faction i have.

At the moment (and i cant show code as im at work so ill have to do it when i get home) i have a UDT that is getting larger by the minute. You see i didnt want a universal game counter because although at first 5 factions will all spawn at the same time, eventually new ones will replace old ones and i dont want a statement that makes it increase peasant numbers by 1 (or whatever) every 5 seconds, instead its every 5 seconds for that faction so each one would have numbers growing at different times etc. Same with the tax collection.
For example.
Faction 1 is spawned at game start. 5 seconds in he gets a peasant, 10 seconds later tax is collected or something like that.
22 Seconds later a new faction is spawned, now that would mean that only 3 seconds (if my math is right) after it spawns the game will say, add another peasant.

The way both you and i have done it ensures that each faction is treated on a seperate counter and not a general rule even though they will all follow the same rule to a degree. Its just i then need a counter for a few other things for each faction too like when it decides to make a descision based on an event and so on.

I am going to post up everything i have soonish so people can see what i am trying to do and see if there is a better way of doing it but for now i will carry on the way i have been.

Thanks for taking a look.

Login to post a reply

Server time is: 2024-11-22 12:29:48
Your offset time is: 2024-11-22 12:29:48