# ai_base.cpp

Go to the documentation of this file.

    00001 /* $Id: ai_base.cpp 17248 2009-08-21 20:21:05Z rubidium $ */
    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 "ai_base.hpp"
    00013 #include "../../network/network.h"
    00014 #include "../../core/random_func.hpp"
    00015
    00016 /* static */ uint32 AIBase::Rand()
    00017 {
    00018   /* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
    00019    *   but we pick InteractiveRandomRange if we are a network_server or network-client. */
    00020   if (_networking) return ::InteractiveRandom();
    00021   return ::Random();
    00022 }
    00023
    00024 /* static */ uint32 AIBase::RandItem(int unused_param)
    00025 {
    00026   return AIBase::Rand();
    00027 }
    00028
    00029 /* static */ uint AIBase::RandRange(uint max)
    00030 {
    00031   /* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
    00032    *   but we pick InteractiveRandomRange if we are a network_server or network-client. */
    00033   if (_networking) return ::InteractiveRandomRange(max);
    00034   return ::RandomRange(max);
    00035 }
    00036
    00037 /* static */ uint32 AIBase::RandRangeItem(int unused_param, uint max)
    00038 {
    00039   return AIBase::RandRange(max);
    00040 }
    00041
    00042 /* static */ bool AIBase::Chance(uint out, uint max)
    00043 {
    00044   return (uint16)Rand() <= (uint16)((65536 * out) / max);
    00045 }
    00046
    00047 /* static */ bool AIBase::ChanceItem(int unused_param, uint out, uint max)
    00048 {
    00049   return AIBase::Chance(out, max);
    00050 }