src/ai/api/ai_base.cpp
author truelight
Sun, 19 Aug 2007 13:16:06 +0000
branchnoai
changeset 9696 4384ed3de1f0
parent 9660 d0a430e8310b
child 9723 eee46cb39750
permissions -rw-r--r--
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
[NoAI] -Fix: AICompant::GetCompanyName returned \0 for invalid company instead of NULL
/* $Id$ */

/** @file ai_base.cpp handles the functions of the AIBase class */

#include "ai_base.hpp"

/* static */ uint32 AIBase::Rand()
{
	/* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
	 *   but we pick InteractiveRandomRange if we are a network_server or network-client. */
	if (_networking) return InteractiveRandom();
	return ::Random();
}

/* static */ uint AIBase::RandRange(uint max)
{
	/* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
	 *   but we pick InteractiveRandomRange if we are a network_server or network-client. */
	if (_networking) return InteractiveRandomRange(max);
	return ::RandomRange(max);
}

/* static */ bool AIBase::Chance(uint out, uint max)
{
	return (uint16)AIBase::Rand() <= (uint16)((65536 * out) / max);
}