ai_base.cpp

Go to the documentation of this file.
00001 /* $Id: ai_base.cpp 15060 2009-01-13 15:44:36Z smatz $ */
00002 
00005 #include "ai_base.hpp"
00006 #include "../../network/network.h"
00007 #include "../../core/random_func.hpp"
00008 
00009 /* static */ uint32 AIBase::Rand()
00010 {
00011   /* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
00012    *   but we pick InteractiveRandomRange if we are a network_server or network-client. */
00013   if (_networking) return ::InteractiveRandom();
00014   return ::Random();
00015 }
00016 
00017 /* static */ uint32 AIBase::RandItem(int unused_param)
00018 {
00019   return AIBase::Rand();
00020 }
00021 
00022 /* static */ uint AIBase::RandRange(uint max)
00023 {
00024   /* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
00025    *   but we pick InteractiveRandomRange if we are a network_server or network-client. */
00026   if (_networking) return ::InteractiveRandomRange(max);
00027   return ::RandomRange(max);
00028 }
00029 
00030 /* static */ uint32 AIBase::RandRangeItem(int unused_param, uint max)
00031 {
00032   return AIBase::RandRange(max);
00033 }
00034 
00035 /* static */ bool AIBase::Chance(uint out, uint max)
00036 {
00037   return (uint16)Rand() <= (uint16)((65536 * out) / max);
00038 }
00039 
00040 /* static */ bool AIBase::ChanceItem(int unused_param, uint out, uint max)
00041 {
00042   return AIBase::Chance(out, max);
00043 }

Generated on Tue Jul 21 18:48:21 2009 for OpenTTD by  doxygen 1.5.6