本文整理汇总了C#中Randomizer.Int32方法的典型用法代码示例。如果您正苦于以下问题:C# Randomizer.Int32方法的具体用法?C# Randomizer.Int32怎么用?C# Randomizer.Int32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Randomizer
的用法示例。
在下文中一共展示了Randomizer.Int32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateWorkplaceCount
/// <summary>
///
/// </summary>
/// <param name="r"></param>
/// <param name="width"></param>
/// <param name="length"></param>
/// <param name="level0"></param>
/// <param name="level1"></param>
/// <param name="level2"></param>
/// <param name="level3"></param>
public override void CalculateWorkplaceCount(Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
{
ItemClass @class = this.m_info.m_class;
int num;
if (@class.m_level == ItemClass.Level.Level1)
{
num = DataStore.office[0][DataStore.PEOPLE];
level0 = 0;
level1 = 40;
level2 = 50;
level3 = 10;
}
else if (@class.m_level == ItemClass.Level.Level2)
{
num = DataStore.office[1][DataStore.PEOPLE];
level0 = 0;
level1 = 20;
level2 = 50;
level3 = 30;
}
else
{
num = DataStore.office[2][DataStore.PEOPLE];
level0 = 0;
level1 = 0;
level2 = 40;
level3 = 60;
}
if (num != 0)
{
num = Mathf.Max(200, width * length * num + r.Int32(100u)) / 100;
int num2 = level0 + level1 + level2 + level3;
if (num2 != 0)
{
level0 = (num * level0 + r.Int32((uint)num2)) / num2;
num -= level0;
}
num2 = level1 + level2 + level3;
if (num2 != 0)
{
level1 = (num * level1 + r.Int32((uint)num2)) / num2;
num -= level1;
}
num2 = level2 + level3;
if (num2 != 0)
{
level2 = (num * level2 + r.Int32((uint)num2)) / num2;
num -= level2;
}
level3 = num;
}
}
示例2: OnBuildingCreated
public static void OnBuildingCreated(ushort buildingID)
{
#if DEBUG
UnityEngine.Debug.Log($"UnlimitedOutsideConnections - OnBuildingCreated. buildingID={buildingID}");
#endif
var instance = BuildingManager.instance;
var connectionAi = instance.m_buildings.m_buffer[buildingID].Info?.m_buildingAI as OutsideConnectionAI;
if (connectionAi == null)
{
return;
}
var serviceBuildings = BuildingUtil.FindServiceBuildings(buildingID);
foreach (var id in serviceBuildings)
{
var ai = instance.m_buildings.m_buffer[id].Info.GetAI() as TransportStationAI;
if (ai?.m_transportLineInfo == null)
{
continue;
}
var gateIndex = 0;
if (ai.m_spawnPoints != null && ai.m_spawnPoints.Length != 0)
{
var randomizer = new Randomizer(id);
gateIndex = randomizer.Int32((uint)ai.m_spawnPoints.Length);
}
instance.m_buildings.m_buffer[buildingID].m_flags |= Building.Flags.IncomingOutgoing;
TransportStationAIDetour.CreateConnectionLines(ai, id, ref instance.m_buildings.m_buffer[id], buildingID, ref instance.m_buildings.m_buffer[buildingID], gateIndex);
BuildingUtil.ReleaseOwnVehicles(id);
}
}
示例3: CalculateHomeCount
/// <summary>
///
/// </summary>
/// <param name="r"></param>
/// <param name="width"></param>
/// <param name="length"></param>
/// <returns></returns>
public override int CalculateHomeCount(Randomizer r, int width, int length)
{
ItemClass item = this.m_info.m_class;
int level = (int)(item.m_level >= 0 ? item.m_level : 0); // Force it to 0 if the level was set to None
int[] array;
// int approxFloorCount = 1;
// bool aprint = false;
if(item.m_subService == ItemClass.SubService.ResidentialLow)
{
array = DataStore.residentialLow[level];
}
else
{
array = DataStore.residentialHigh[level];
// approxFloorCount = ((int)this.m_info.m_size.y) / 3;
// aprint = true;
}
int num = array[DataStore.PEOPLE];
int householdCount = Mathf.Max(100, width * length * num + r.Int32(100u)) / 100;
/*
if (aprint)
{
Vector3 v = this.m_info.m_size;
Debugging.writeDebugToFile("x/y/z: " + v.x + " * " + v.y + " * " + v.z + ", household: " + householdCount);
}
*/
return householdCount;
}
示例4: checkIfShouldMoveIn
public static bool checkIfShouldMoveIn(uint[] familyWithSeniors, ref Building buildingData, ref Randomizer randomizer, float operationRadius, int quality, ref NumWorkers numWorkers)
{
float chanceValue = BASE_CHANCE_VALUE;
Logger.logInfo(LOG_CHANCES, "---------------------------------");
// Age
chanceValue += getAgeChanceValue(familyWithSeniors);
// Distance
chanceValue += getDistanceChanceValue(familyWithSeniors, ref buildingData, operationRadius);
// Family Status
chanceValue += getFamilyStatusChanceValue(familyWithSeniors);
// Wealth
chanceValue += getWealthChanceValue(familyWithSeniors, quality);
// Workers
chanceValue += getWorkersChanceValue(ref numWorkers);
// Check for no chance
if (chanceValue <= 0) {
Logger.logInfo(LOG_CHANCES, "MoveInProbabilityHelper.checkIfShouldMoveIn -- No Chance: {0}", chanceValue);
return false;
}
// Check against random value
uint maxChance = (uint) MAX_CHANCE_VALUE;
int randomValue = randomizer.Int32(maxChance);
Logger.logInfo(LOG_CHANCES, "MoveInProbabilityHelper.checkIfShouldMoveIn -- Total Chance Value: {0} -- Random Number: {1} -- result: {2}", chanceValue, randomValue, randomValue <= chanceValue);
return randomValue <= chanceValue;
}
示例5: GetBufferStatus
public override void GetBufferStatus(ushort vehicleID, ref Vehicle data, out string localeKey, out int current, out int max)
{
localeKey = "Default";
current = (int)data.m_transferSize;
max = this.m_passengerCapacity;
if (data.m_leadingVehicle == 0) {
VehicleManager instance = Singleton<VehicleManager>.instance;
ushort trailingVehicle = data.m_trailingVehicle;
int num = 0;
while (trailingVehicle != 0) {
VehicleInfo info = instance.m_vehicles.m_buffer [(int)trailingVehicle].Info;
if (instance.m_vehicles.m_buffer [(int)trailingVehicle].m_leadingVehicle != 0) {
int num2;
int num3;
info.m_vehicleAI.GetBufferStatus (trailingVehicle, ref instance.m_vehicles.m_buffer [(int)trailingVehicle], out localeKey, out num2, out num3);
current += num2;
max += num3;
}
trailingVehicle = instance.m_vehicles.m_buffer [(int)trailingVehicle].m_trailingVehicle;
if (++num > 65536) {
CODebugBase<LogChannel>.Error (LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);
break;
}
}
}
if ((data.m_flags & Vehicle.Flags.DummyTraffic) != Vehicle.Flags.None) {
Randomizer randomizer = new Randomizer ((int)vehicleID);
current = randomizer.Int32 (max >> 1, max);
}
}
示例6: GetVehicleInfo
protected override VehicleInfo GetVehicleInfo(ushort instanceID, ref CitizenInstance citizenData, bool forceProbability)
{
if (citizenData.m_citizen == 0u)
{
return null;
}
int num;
int num2;
int num3;
if (forceProbability || (citizenData.m_flags & CitizenInstance.Flags.BorrowCar) != CitizenInstance.Flags.None)
{
num = 100;
num2 = 0;
num3 = 0;
}
else
{
num = this.GetCarProbability ();
num2 = this.GetBikeProbability ();
num3 = this.GetTaxiProbability ();
}
Randomizer randomizer = new Randomizer (citizenData.m_citizen);
bool flag = randomizer.Int32 (100u) < num;
bool flag2 = randomizer.Int32 (100u) < num2;
bool flag3 = randomizer.Int32 (100u) < num3;
ItemClass.Service service = ItemClass.Service.Residential;
ItemClass.SubService subService = ItemClass.SubService.ResidentialLow;
if (!flag && flag3)
{
service = ItemClass.Service.PublicTransport;
subService = ItemClass.SubService.PublicTransportTaxi;
}
VehicleInfo randomVehicleInfo = Singleton<VehicleManager>.instance.GetRandomVehicleInfo (ref randomizer, service, subService, ItemClass.Level.Level1);
VehicleInfo randomVehicleInfo2 = Singleton<VehicleManager>.instance.GetRandomVehicleInfo (ref randomizer, ItemClass.Service.Residential, ItemClass.SubService.ResidentialHigh, ItemClass.Level.Level2);
if (flag2 && randomVehicleInfo2 != null)
{
return randomVehicleInfo2;
}
if ((flag || flag3) && randomVehicleInfo != null)
{
return randomVehicleInfo;
}
return null;
}
示例7: CalculateHomeCount
/// <summary>
/// Calculated to the similar way the original code would have done it
/// </summary>
/// <param name="r"></param>
/// <param name="width"></param>
/// <param name="length"></param>
/// <param name="subService"></param>
/// <param name="level"></param>
/// <returns></returns>
public static int CalculateHomeCount(Randomizer r, int width, int length, ItemClass.SubService subService, ItemClass.Level level)
{
int[][] residentialArray = { new int [] { 20, 25, 30, 35, 40 },
new int [] { 60, 100, 130, 150, 160 } };
int iLevel = (int)(level >= 0 ? level : 0);
int density = (subService == ItemClass.SubService.ResidentialLow) ? 0 : 1;
int num = residentialArray[density][iLevel];
return Mathf.Max(100, width * length * num + r.Int32(100u)) / 100;
}
示例8: GenerateName
public override string GenerateName(ushort buildingID, InstanceID caller)
{
if (this.m_info.m_prefabDataIndex == -1) {
return null;
}
Randomizer randomizer = new Randomizer ((int)buildingID);
string key = PrefabCollection<BuildingInfo>.PrefabName ((uint)this.m_info.m_prefabDataIndex);
uint num = Locale.CountUnchecked ("BUILDING_NAME", key);
if (num != 0u) {
return Locale.Get ("BUILDING_NAME", key, randomizer.Int32 (num));
}
return BuildingNameGenerator.GenerateName (this.m_info.m_class.m_service, randomizer);
}
示例9: AutoSetHomes
public static void AutoSetHomes(ushort buildingID, ref Building data, CoreAI core)
{
short[] config;
ItemClass @class = core.m_info.m_class;
int subservice = (int)@class.m_subService;
if (VanillaData.LevelAutogenResidents.TryGetValue(subservice, out config))
{
int level = (int)@class.m_level;
if (config.GetLength(0) >= level)
{
Randomizer r = new Randomizer((int)buildingID);
core.occupants.maxHomeCount = (short)(Mathf.Max(100, data.Width * data.Length * config[level] + r.Int32(100u)) / 100);
core.occupantsUpdated = true;
}
}
}
示例10: GetConsumptionRates
/// <summary>
///
/// </summary>
/// <param name="r"></param>
/// <param name="productionRate"></param>
/// <param name="electricityConsumption"></param>
/// <param name="waterConsumption"></param>
/// <param name="sewageAccumulation"></param>
/// <param name="garbageAccumulation"></param>
/// <param name="incomeAccumulation"></param>
public override void GetConsumptionRates(Randomizer r, int productionRate, out int electricityConsumption, out int waterConsumption, out int sewageAccumulation, out int garbageAccumulation, out int incomeAccumulation)
{
ItemClass @class = this.m_info.m_class;
electricityConsumption = 0;
waterConsumption = 0;
sewageAccumulation = 0;
garbageAccumulation = 0;
incomeAccumulation = 0;
int[] array;
int level = (int) (@class.m_level >= 0 ? @class.m_level : 0); // Force it to 0 if the level was set to None
array = (@class.m_subService == ItemClass.SubService.ResidentialLow) ? DataStore.residentialLow[level] : DataStore.residentialHigh[level];
electricityConsumption = array[DataStore.POWER];
waterConsumption = array[DataStore.WATER];
sewageAccumulation = array[DataStore.SEWAGE];
garbageAccumulation = array[DataStore.GARBAGE];
incomeAccumulation = array[DataStore.INCOME];
if (electricityConsumption != 0)
{
electricityConsumption = Mathf.Max(100, productionRate * electricityConsumption + r.Int32(100u)) / 100;
}
if (waterConsumption != 0)
{
int num = r.Int32(100u);
waterConsumption = Mathf.Max(100, productionRate * waterConsumption + num) / 100;
if (sewageAccumulation != 0)
{
sewageAccumulation = Mathf.Max(100, productionRate * sewageAccumulation + num) / 100;
}
}
else if (sewageAccumulation != 0)
{
sewageAccumulation = Mathf.Max(100, productionRate * sewageAccumulation + r.Int32(100u)) / 100;
}
if (garbageAccumulation != 0)
{
garbageAccumulation = Mathf.Max(100, productionRate * garbageAccumulation + r.Int32(100u)) / 100;
}
if (incomeAccumulation != 0)
{
incomeAccumulation = productionRate * incomeAccumulation;
}
}
示例11: AutoSetWorkers
//Used to initialize a building's worker count. Vanilla function converted to be universal and compact.
public static void AutoSetWorkers(ushort buildingID, ref Building data, Occupants occupants, short[] workersConfig)
{
short[][] config;
if (VanillaData.LevelAutogenWorkers.TryGetValue(subservice, out config))
{
int level = (int)@class.m_level;
if (config.GetLength(0) >= level)
{
int num = config[level][0];
int level0 = config[level][1];
int level1 = config[level][2];
int level2 = config[level][3];
int level3 = config[level][4];
if (num != 0)
{
var r = new Randomizer((int)buildingID);
num = Mathf.Max(200, data.Width * data.Length * num + r.Int32(100u)) / 100;
int num2 = level0 + level1 + level2 + level3;
if (num2 != 0)
{
level0 = (num * level0 + r.Int32((uint)num2)) / num2;
num -= level0;
}
num2 = level1 + level2 + level3;
if (num2 != 0)
{
level1 = (num * level1 + r.Int32((uint)num2)) / num2;
num -= level1;
}
num2 = level2 + level3;
if (num2 != 0)
{
level2 = (num * level2 + r.Int32((uint)num2)) / num2;
num -= level2;
}
level3 = num;
core.occupants.ModifyWorkers((short)level0, (short)level1, (short)level2, (short)level3);
core.occupantsUpdated = true;
}
}
}
}
示例12: GetBufferStatus
public override void GetBufferStatus(ushort vehicleID, ref Vehicle data, out string localeKey, out int current, out int max)
{
localeKey = "Default";
current = 0;
max = this.m_cargoCapacity;
VehicleManager instance = Singleton<VehicleManager>.instance;
ushort num = data.m_firstCargo;
int num2 = 0;
while (num != 0) {
current++;
num = instance.m_vehicles.m_buffer [(int)num].m_nextCargo;
if (++num2 > 65536) {
CODebugBase<LogChannel>.Error (LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);
break;
}
}
if ((data.m_flags & Vehicle.Flags.DummyTraffic) != Vehicle.Flags.None) {
Randomizer randomizer = new Randomizer ((int)vehicleID);
current = randomizer.Int32 (max >> 1, max);
}
}
示例13: GetRandomBuildingInfo_Spawn
// called before a new building spawns on empty land (ZoneBlock.SimulationStep)
public static BuildingInfo GetRandomBuildingInfo_Spawn(Vector3 position, ref Randomizer r, ItemClass.Service service, ItemClass.SubService subService, ItemClass.Level level, int width, int length, BuildingInfo.ZoningMode zoningMode, int style)
{
if (Debugger.Enabled)
{
Debugger.Log("GetRandomBuildingInfo_Spawn called!");
}
var areaIndex = BuildingThemesManager.GetAreaIndex(service, subService, level, width, length, zoningMode);
var districtId = Singleton<DistrictManager>.instance.GetDistrict(position);
FastList<ushort> fastList = Singleton<BuildingThemesManager>.instance.GetAreaBuildings(districtId, areaIndex);
if (fastList == null || fastList.m_size == 0)
{
return (BuildingInfo)null;
}
// select a random prefab from the list
int index = r.Int32((uint)fastList.m_size);
return PrefabCollection<BuildingInfo>.GetPrefab((uint)fastList.m_buffer[index]);
}
示例14: CalculateWorkplaceCount
/// <summary>
///
/// </summary>
/// <param name="r"></param>
/// <param name="width"></param>
/// <param name="length"></param>
/// <param name="level0"></param>
/// <param name="level1"></param>
/// <param name="level2"></param>
/// <param name="level3"></param>
public override void CalculateWorkplaceCount(Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
{
ItemClass @class = this.m_info.m_class;
int num = 0;
level0 = 0;
level1 = 0;
level2 = 0;
level3 = 0;
if (@class.m_subService == ItemClass.SubService.IndustrialGeneric)
{
if (@class.m_level == ItemClass.Level.Level1)
{
num = DataStore.industry[0][DataStore.PEOPLE];
level0 = 100;
level1 = 0;
level2 = 0;
level3 = 0;
}
else if (@class.m_level == ItemClass.Level.Level2)
{
num = DataStore.industry[1][DataStore.PEOPLE];
level0 = 20;
level1 = 60;
level2 = 20;
level3 = 0;
}
else
{
num = DataStore.industry[2][DataStore.PEOPLE];
level0 = 5;
level1 = 15;
level2 = 30;
level3 = 50;
}
}
else if (@class.m_subService == ItemClass.SubService.IndustrialFarming)
{
num = DataStore.industry_farm[0][DataStore.PEOPLE];
level0 = 100;
level1 = 0;
level2 = 0;
level3 = 0;
}
else if (@class.m_subService == ItemClass.SubService.IndustrialForestry)
{
num = DataStore.industry_forest[0][DataStore.PEOPLE];
level0 = 100;
level1 = 0;
level2 = 0;
level3 = 0;
}
else if (@class.m_subService == ItemClass.SubService.IndustrialOre)
{
num = DataStore.industry_ore[0][DataStore.PEOPLE];
level0 = 20;
level1 = 60;
level2 = 20;
level3 = 0;
}
else if (@class.m_subService == ItemClass.SubService.IndustrialOil)
{
num = DataStore.industry_oil[0][DataStore.PEOPLE];
level0 = 20;
level1 = 60;
level2 = 20;
level3 = 0;
}
if (num != 0)
{
num = Mathf.Max(200, width * length * num + r.Int32(100u)) / 100;
int num2 = level0 + level1 + level2 + level3;
if (num2 != 0)
{
level0 = (num * level0 + r.Int32((uint)num2)) / num2;
num -= level0;
}
num2 = level1 + level2 + level3;
if (num2 != 0)
{
level1 = (num * level1 + r.Int32((uint)num2)) / num2;
num -= level1;
}
num2 = level2 + level3;
if (num2 != 0)
{
level2 = (num * level2 + r.Int32((uint)num2)) / num2;
num -= level2;
}
level3 = num;
}
//.........这里部分代码省略.........
示例15: RenderInstance
//.........这里部分代码省略.........
}
}
}
// mod end
var num2 = 2;
if (repeatDistance > 1f)
{
num2 *= Mathf.Max(1, Mathf.RoundToInt(_this.m_length / repeatDistance));
}
var num3 = propIndex;
if (propIndex != -1)
{
propIndex = num3 + (num2 + 1 >> 1);
}
if (prop.CheckFlags((NetLane.Flags)_this.m_flags, startFlags, endFlags))
{
var num4 = prop.m_segmentOffset * 0.5f;
if (_this.m_length != 0f)
{
num4 = Mathf.Clamp(num4 + prop.m_position.z / _this.m_length, -0.5f, 0.5f);
}
if (flag2)
{
num4 = -num4;
}
if (finalProp != null && (layerMask & 1 << finalProp.m_prefabDataLayer) != 0)
{
var color = (prop.m_colorMode != NetLaneProps.ColorMode.EndState) ? startColor : endColor;
var randomizer = new Randomizer((int)(laneID + (uint)i));
for (var j = 1; j <= num2; j += 2)
{
if (randomizer.Int32(100u) < prop.m_probability)
{
var num5 = num4 + (float)j / (float)num2;
var variation = finalProp.GetVariation(ref randomizer);
var scale = variation.m_minScale + (float)randomizer.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f;
if (prop.m_colorMode == NetLaneProps.ColorMode.Default)
{
color = variation.GetColor(ref randomizer);
}
var vector = _this.m_bezier.Position(num5);
if (propIndex != -1)
{
vector.y = (float)data.m_extraData.GetUShort(num3++) * 0.015625f;
}
vector.y += prop.m_position.y;
if (cameraInfo.CheckRenderDistance(vector, variation.m_maxRenderDistance))
{
var vector2 = _this.m_bezier.Tangent(num5);
if (vector2 != Vector3.zero)
{
if (flag2)
{
vector2 = -vector2;
}
vector2.y = 0f;
if (prop.m_position.x != 0f)
{
vector2 = Vector3.Normalize(vector2);
vector.x += vector2.z * prop.m_position.x;
vector.z -= vector2.x * prop.m_position.x;
}
var num6 = Mathf.Atan2(vector2.x, -vector2.z);
if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f)