00001 /* $Id$ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. 00006 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00007 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 00008 */ 00009 00012 #include "../../stdafx.h" 00013 #include "ai_base.hpp" 00014 #include "../../network/network.h" 00015 #include "../../core/random_func.hpp" 00016 00017 /* static */ uint32 AIBase::Rand() 00018 { 00019 /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) 00020 * but we pick InteractiveRandomRange if we are a network_server or network-client. */ 00021 if (_networking) return ::InteractiveRandom(); 00022 return ::Random(); 00023 } 00024 00025 /* static */ uint32 AIBase::RandItem(int unused_param) 00026 { 00027 return AIBase::Rand(); 00028 } 00029 00030 /* static */ uint AIBase::RandRange(uint max) 00031 { 00032 /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) 00033 * but we pick InteractiveRandomRange if we are a network_server or network-client. */ 00034 if (_networking) return ::InteractiveRandomRange(max); 00035 return ::RandomRange(max); 00036 } 00037 00038 /* static */ uint32 AIBase::RandRangeItem(int unused_param, uint max) 00039 { 00040 return AIBase::RandRange(max); 00041 } 00042 00043 /* static */ bool AIBase::Chance(uint out, uint max) 00044 { 00045 return (uint16)Rand() <= (uint16)((65536 * out) / max); 00046 } 00047 00048 /* static */ bool AIBase::ChanceItem(int unused_param, uint out, uint max) 00049 { 00050 return AIBase::Chance(out, max); 00051 }