truelight@9360: /* $Id$ */ truelight@9360: truebrain@9833: /** @file ai_base.cpp Implementation of AIBase. */ truelight@9360: rubidium@9430: #include "ai_base.hpp" rubidium@9723: #include "../../network/network.h" rubidium@9837: #include "../../core/random_func.hpp" truelight@9360: truelight@9660: /* static */ uint32 AIBase::Rand() truelight@9360: { truelight@9360: /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) truelight@9360: * but we pick InteractiveRandomRange if we are a network_server or network-client. */ truebrain@9736: if (_networking) return ::InteractiveRandom(); truelight@9361: return ::Random(); truelight@9360: } truelight@9360: truebrain@9814: /* static */ uint32 AIBase::RandItem(int unused_param) truebrain@9814: { truebrain@9814: return AIBase::Rand(); truebrain@9814: } truebrain@9814: truelight@9660: /* static */ uint AIBase::RandRange(uint max) truelight@9360: { truelight@9360: /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) truelight@9360: * but we pick InteractiveRandomRange if we are a network_server or network-client. */ truebrain@9736: if (_networking) return ::InteractiveRandomRange(max); truelight@9361: return ::RandomRange(max); truelight@9360: } truelight@9360: truebrain@9814: /* static */ uint32 AIBase::RandRangeItem(int unused_param, uint max) truebrain@9814: { truebrain@9814: return AIBase::RandRange(max); truebrain@9814: } truebrain@9814: truelight@9660: /* static */ bool AIBase::Chance(uint out, uint max) truelight@9360: { truebrain@9737: return (uint16)Rand() <= (uint16)((65536 * out) / max); truelight@9360: } truebrain@9814: truebrain@9814: /* static */ bool AIBase::ChanceItem(int unused_param, uint out, uint max) truebrain@9814: { truebrain@9814: return AIBase::Chance(out, max); truebrain@9814: }