____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

util.h File Reference

General utilities. More...

#include <string.h>
#include <string>

Go to the source code of this file.

Defines

#define MyRand()   rand()
 < rand only used on this computer.
#define _TRUNCATE   ((size_t)-1)

Functions

void InitSyncRand (void)
 Initialize the syncron rand.
int SyncRand (void)
 Syncron rand.
int SyncRand (int max)
 Syncron rand.
long isqrt (long num)
unsigned int strcpy_s (char *dst, size_t dstsize, const char *src)
unsigned int strncpy_s (char *dst, size_t dstsize, const char *src, size_t count)
unsigned int strcat_s (char *dst, size_t dstsize, const char *src)
int sprintf_s (char *dest, size_t destSize, const char *format,...)
char * new_strdup (const char *str)
 strdup + strcat
char * strdcat (const char *l, const char *r)
 strdup + strcat + strcat
char * strdcat3 (const char *l, const char *m, const char *r)
 case insensitive strstr
char * strcasestr (const char *str, const char *substr)
size_t strnlen (const char *str, size_t strsize)
 < determine length of a fixed-length string
int GetClipboard (std::string &str)
int UTF8GetNext (const std::string &text, int curpos)
int UTF8GetPrev (const std::string &text, int curpos)

Variables

unsigned SyncRandSeed
 Sync random seed value.


Detailed Description

General utilities.

Definition in file util.h.


Define Documentation

#define _TRUNCATE   ((size_t)-1)

Definition at line 62 of file util.h.

Referenced by strncpy_s().

 
#define MyRand (  )     rand()

< rand only used on this computer.

Compute a square root using ints

Definition at line 48 of file util.h.

Referenced by ActionStillGeneric(), CChunkParticle::CChunkParticle(), HandleActionBuilt(), CUnit::Init(), NetworkServerStartGame(), and CChunkParticle::update().


Function Documentation

int GetClipboard ( std::string &  str  ) 

Standard implementation of getopt(3).

One extension: If the first character of the optionsstring is a ':' the error return for 'argument required' is a ':' not a '?'. This makes it easier to differentiate between an 'illegal option' and an 'argument required' error.

Paste text from the clipboard

Definition at line 414 of file util.cpp.

Referenced by gcn::TextField::keyPress(), gcn::TextBox::keyPress(), gcn::TextField::mousePress(), and gcn::TextBox::mousePress().

void InitSyncRand ( void   ) 

Initialize the syncron rand.

Inititalize sync rand seed.

Definition at line 57 of file util.cpp.

References SyncRandSeed.

Referenced by CreateGame(), InitModules(), and main().

long isqrt ( long  num  ) 

Compute a square root using ints

Uses John Halleck's method, see http://www.cc.utah.edu/~nahaj/factoring/isqrt.legalize.c.html

Parameters:
num Calculate the square root of this number
Returns:
The integer square root.

Definition at line 104 of file util.cpp.

Referenced by AStarFindSimplePath(), HitUnit(), InitVisionTable(), MapDistance(), MapDistanceBetweenTypes(), and MapDistanceToType().

char* new_strdup ( const char *  str  )  [inline]

int sprintf_s ( char *  dest,
size_t  destSize,
const char *  format,
  ... 
)

char* strcasestr ( const char *  a,
const char *  b 
)

Case insensitive version of strstr

Parameters:
a String to search in
b Substring to search for
Returns:
Pointer to first occurence of b or NULL if not found.

Definition at line 298 of file util.cpp.

Referenced by CreateFileWriter(), and CreateGame().

unsigned int strcat_s ( char *  dst,
size_t  dstsize,
const char *  src 
)

Definition at line 202 of file util.cpp.

Referenced by InputKey(), LoadStratagusMap(), ReadDataDirectory(), strdcat(), and strdcat3().

unsigned int strcpy_s ( char *  dst,
size_t  dstsize,
const char *  src 
)

char* strdcat ( const char *  l,
const char *  r 
)

strdup + strcat + strcat

String duplicate/concatenate (two arguments)

Parameters:
l Left string
r Right string
Returns:
Allocated combined string (must be freed).

Definition at line 255 of file util.cpp.

References strcat_s(), and strcpy_s().

char* strdcat3 ( const char *  l,
const char *  m,
const char *  r 
)

case insensitive strstr

String duplicate/concatenate (three arguments)

Parameters:
l Left string
m Middle string
r Right string
Returns:
Allocated combined string (must be freeded).

Definition at line 276 of file util.cpp.

References strcat_s(), and strcpy_s().

Referenced by SaveGlobal().

unsigned int strncpy_s ( char *  dst,
size_t  dstsize,
const char *  src,
size_t  count 
)

Definition at line 175 of file util.cpp.

References _TRUNCATE, and strnlen().

Referenced by IsSafeMapName(), and ServerParseWaiting().

size_t strnlen ( const char *  str,
size_t  strsize 
)

< determine length of a fixed-length string

Definition at line 161 of file util.cpp.

Referenced by strncpy_s().

int SyncRand ( int  max  ) 

Syncron rand.

Synchronized random number.

Parameters:
max Max value of random number to return

Definition at line 84 of file util.cpp.

References SyncRand().

int SyncRand ( void   ) 

Syncron rand.

Synchronized random number.

Note:
This random value must be same on all machines in network game. Very simple random generations, enough for us.

Definition at line 68 of file util.cpp.

References SyncRandSeed.

Referenced by AiBuildBuilding(), AiCollectResources(), AiMoveUnitInTheWay(), AiSendExplorers(), CalculateDamage(), AreaBombardment::Cast(), CclCreateUnit(), CclMoveUnit(), EvaluateMissileLocation(), HitUnit(), SelectTargetUnitsOfAutoCast(), SyncRand(), tolua_stratagus_SyncRand00(), tolua_stratagus_SyncRand01(), and UnitShowAnimationScaled().

int UTF8GetNext ( const std::string &  text,
int  curpos 
)

Definition at line 528 of file util.cpp.

Referenced by gcn::TextField::keyPress(), and gcn::TextBox::keyPress().

int UTF8GetPrev ( const std::string &  text,
int  curpos 
)

Definition at line 510 of file util.cpp.

Referenced by InputKey(), gcn::TextField::keyPress(), and gcn::TextBox::keyPress().


Variable Documentation

unsigned SyncRandSeed

Sync random seed value.

Definition at line 52 of file util.cpp.

Referenced by CclSavedGameInfo(), CommandLog(), DoNextReplay(), InitSyncRand(), LoadGame(), NetworkSendCommands(), SaveGame(), SyncRand(), and UnitActions().


Generated on Sat Feb 21 00:28:22 2009 for Bos Wars by  doxygen 1.5.6