ZDaemon Forum Index ZDaemon
Client/Server DOOM
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Frenchies' Chaotic Tuesdays #17 - Meet the V.I.P. -
Goto page Previous  1, 2
 
Post new topic   Reply to topic    ZDaemon Forum Index -> Frenchies' Chaotic Tuesdays
View previous topic :: View next topic  
Author Message
Sr69Mm-jC
Spamming!


Joined: 21 Jul 2011

PostPosted: Tue Jun 04, 2013 4:24 pm    Post subject: Reply with quote

Yes rhino, you got everything correct.

rhinoduck wrote:
The m_w and m_z variables are the RNG seeds and you must initialise them to a non-zero value before you start using the function. You should be able to use values calculated from one or more player coordinates/angle and/or gameticks passed to seed the RNG at each map (re)start if the decision about who the VIP will be is made some time into the game and the players are allowed to move a bit first.

Exactly. As a reminder, we now have:
Code:
 1. Implementation of 2 new CVARs; "cv_localtime" and "cv_gmtime".
     They're read-only and return the number of seconds since midnight
     in local time and GMT time respectively.

This might as well be already sufficient enough. If not, I'd use the angle of one of the players (wait for at least 1 player to spawn, delay a second or two, then read the first player's angle).
Back to top
View user's profile Send private message
rhinoduck
Potatoes


Joined: 22 Oct 2012

PostPosted: Tue Jun 04, 2013 5:15 pm    Post subject: Reply with quote

Sr69Mm-jC wrote:
As a reminder, we now have:

Code:
 1. Implementation of 2 new CVARs; "cv_localtime" and "cv_gmtime".
     They're read-only and return the number of seconds since midnight
     in local time and GMT time respectively.


Sweet mother of God! How do I keep missing that these things exist?

This would, of course, be the preferred way as it is the simplest, and it is completely sufficient in this case.
Back to top
View user's profile Send private message
Ch0wW
Unstoppable!


Joined: 05 Feb 2013
Location: France

PostPosted: Wed Jun 05, 2013 12:22 am    Post subject: Reply with quote

So, if I've got it right, in order to make it work nicely, you can make this :

Code:

/*
=============
Abs
Gives an Absolute value
=============
*/
function int Abs (int x)
{
    if (x < 0)
        return -x;

    return x;
}

/*
=============
Random2
Alternative to Random's function (from Worst, helped by rhinoduck + Sr69Mm-jC)
=============
*/
function int Random2 (int min, int max) {
   
   int m_z = GetCVAR("cv_gmtime");
   int m_w = GetCVAR("cv_localtime");

   m_z = 36969 * (m_z & 65535) + (m_z >> 16);
   m_w = 18000 * (m_w & 65535) + (m_w >> 16);
   return Abs((m_z << 16) + m_w)%(max-min+1) + min;
}


am I right?


Last edited by Ch0wW on Wed Jun 05, 2013 12:53 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
rhinoduck
Potatoes


Joined: 22 Oct 2012

PostPosted: Wed Jun 05, 2013 12:49 am    Post subject: Reply with quote

Although what you posted would probably work for you as well, this is how it was intended. (Replace XXX with an actual script number.)

Code:
/*
=============
RNG variables
=============
*/
int m_w;
int m_z;

/*
=============
RNG seed populating script
=============
*/
script XXX OPEN
{
   m_z = GetCVAR("cv_gmtime");
   m_w = GetCVAR("cv_localtime");
}

/*
=============
Random2
Alternative to Random's function (from Worst, helped by rhinoduck + Sr69Mm-jC)
=============
*/
function int Random2 (int min, int max)
{
   m_z = 36969 * (m_z & 65535) + (m_z >> 16);
   m_w = 18000 * (m_w & 65535) + (m_w >> 16);
   return Abs((m_z << 16) + m_w)%(max-min+1) + min;
}


The OPEN script will take care of populating the RNG seed (only needed once for one sequence of random numbers) at map start and you can then just use the function. Those two map variables hold the inner state of the RNG, you can assign to them again to change the seed and get a new sequence of random numbers (only needed at each map start in your case - happens in the OPEN script). The Abs function was alright.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ZDaemon Forum Index -> Frenchies' Chaotic Tuesdays All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group