Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 |
/* * USARUtils.uc * author: Chris Scrapper * brief: Utility class for USARSim. * * This class contains multiple utility functions: * gaussRand - Gaussian random number generator given a mean and standard deviation * tokenizer - returns a dynamic array of string tokens. Takes a string of args * and a string that specifies the delimiter. */ class USARUtils extends Object config(USARBot); // persistent variables needed for gaussRand function var float y2; var bool use_last; /* * Generates Gaussian distribution of random numbers given a mean * and a standard deviation(sigma). Uses Box-Muller method */ function float gaussRand(float mean, float sigma) { local float x1, x2, w, y1; w =1.0; x1=0.0; x2=0.0; y1=0.0; if( sigma == 0 ) return 0; if( use_last ) { y1 = y2; use_last=false; } else { while (w >= 1.0) { x1 = 2.0 * FRand() - 1.0; x2 = 2.0 * FRand() - 1.0; w = x1 * x1 + x2 * x2; } w = sqrt( (-2.0 * Loge(w))/w); y1 = x1 * w; y2 = x2 * w; use_last=true; } return (mean + y1 * sigma); } /* * Parses a string of arguments into tokens. The tokens are split * by the delimiter specified by delim. * Returns a dynamic array of string. */ function array<string> tokenizer(string argStr, string delim) { local int i; local int count; local bool rVal; local array<string> opt; rVal=false; count = 0; if( argStr != "" ) { rVal=true; do { opt.Length=count+1; i=InStr(argStr,","); if( i == -1 ) opt[count]=argStr; else { opt[count]=Left(argStr,i); argStr = mid(argStr,i+1); } count++; } until ( i == -1 ); } return opt; } // Sets default values of persistent variables. defaultproperties { use_last = true; y2 = 0.0; } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |