void UpdateCell(int _targetCell, float _tempChange) { FlameCell _FC = flameCells[_targetCell]; _FC.temperature = Mathf.Clamp(_FC.temperature + _tempChange, -1f, 1f); _FC.IgnitionTest(); }
private void SetFlame(Player player, int cx, int cy) { FieldCellSlot slot = GetSlot(cx, cy); FlameCell flame = slot.GetFlame(); if (flame != null && flame.player == player) { flame.RemoveFromField(); } AddCell(new FlameCell(player, cx, cy)); }
// Kick off the command - choose targets, set required vars etc private void BeginCommand(BotCommand _command) { currentCommand = _command; switch (currentCommand.action) { case BotAction.DROP_BUCKET: DropBucket(); CompleteCommand(); break; case BotAction.FILL_BUCKET: isFillingBucket = true; break; case BotAction.THROW_BUCKET: ThrowBucket(); CompleteCommand(); break; case BotAction.GET_BUCKET: if (botType == BotType.SCOOP || botType == BotType.OMNIBOT) { targetBucket = FindNearestBucket(false); } else { if (bucketProvider != null && bucketProvider.carrying != null) { targetBucket = bucketProvider.carrying; } } break; case BotAction.GOTO_WATER: targetWater = FindNearestWater(); break; case BotAction.GOTO_FIRE: targetFlameCell = FindNearestFlame(); break; } }
private void WriteFieldState(NetBuffer buffer, Field field) { int bitsForPlayerIndex = NetUtility.BitsToHoldUInt((uint)(field.GetPlayers().GetCount() - 1)); FieldCellSlot[] slots = field.GetCells().slots; for (int i = 0; i < slots.Length; ++i) { FieldCell staticCell = slots[i].staticCell; bool shouldWrite = staticCell != null && !staticCell.IsSolid(); buffer.Write(shouldWrite); if (shouldWrite) { switch (staticCell.type) { case FieldCellType.Brick: { BrickCell brick = staticCell.AsBrick(); buffer.Write(CELL_BRICK, BITS_FOR_STATIC_CELL); break; } case FieldCellType.Powerup: { PowerupCell powerup = staticCell.AsPowerup(); buffer.Write(CELL_POWERUP, BITS_FOR_STATIC_CELL); buffer.Write(powerup.powerup, BITS_FOR_POWERUP); break; } case FieldCellType.Flame: { FlameCell flame = staticCell.AsFlame(); buffer.Write(CELL_FLAME, BITS_FOR_STATIC_CELL); buffer.Write(flame.player.GetIndex(), bitsForPlayerIndex); break; } } } } }
////////////////////////////////////////////////////////////////////////////// #region Bombs public void SetBomb(Bomb bomb) { AddCell(bomb); FieldCellSlot slot = GetSlot(bomb); PowerupCell powerup = slot.GetPowerup(); if (powerup != null) { powerup.RemoveFromField(); } else { FlameCell flame = slot.GetFlame(); if (flame != null) { bomb.Blow(); } } }
public FlameCell FindNearestFlame() { FlameCell nearestFlame = null; Vector3 targetLocation = (botType == BotType.OMNIBOT) ? t.position : location_PICKUP; float distance = 999f; for (int i = 0; i < fireSim.totalCells; i++) { FlameCell _FC = fireSim.flameCells[i]; if (_FC.onFire) { float testDistance = Vector3.Distance(targetLocation, _FC.transform.position); if (testDistance < distance) { nearestFlame = _FC; distance = testDistance; } } } return(nearestFlame); }
void UpdateFire() { timeUntilFireUpdate -= Time.deltaTime; if (timeUntilFireUpdate <= 0) { timeUntilFireUpdate = fireSimUpdateRate; for (int cellIndex = 0; cellIndex < totalCells; cellIndex++) { float tempChange = 0f; FlameCell currentCell = flameCells[cellIndex]; currentCell.neighbourOnFire = false; int cellRowIndex = Mathf.FloorToInt(cellIndex / columns); int cellColumnIndex = cellIndex % columns; for (int rowIndex = -heatRadius; rowIndex <= heatRadius; rowIndex++) { int currentRow = cellRowIndex - rowIndex; if (currentRow >= 0 && currentRow < rows) { for (int columnIndex = -heatRadius; columnIndex <= heatRadius; columnIndex++) { int currentColumn = cellColumnIndex + columnIndex; if (currentColumn >= 0 && currentColumn < columns) { FlameCell _neighbour = flameCells[(currentRow * columns) + currentColumn]; if (_neighbour.onFire) { currentCell.neighbourOnFire = true; tempChange += _neighbour.temperature * heatTransferRate; } } } } } UpdateCell(cellIndex, tempChange); } } }
public void UpdateBot() { decisionTimer -= Time.deltaTime; if (decisionTimer < 0) { decisionTimer = decisionRate; RestartCommand(); } switch (currentCommand.action) { case BotAction.PASS_BUCKET: if (MoveTowards(location_DROPOFF)) { DropBucket(); CompleteCommand(); } break; case BotAction.FILL_BUCKET: carrying.volume = Mathf.Clamp(carrying.volume + fireSim.bucketFillRate, 0f, fireSim.bucketCapacity); targetWater.Subtract(fireSim.bucketFillRate); carrying.bucketFull = (carrying.volume >= fireSim.bucketCapacity); // Update bucket Scale (reparenting trick to preserve scale) carrying.transform.SetParent(fireSim.transform, true); carrying.UpdateBucket(); carrying.transform.SetParent(t, true); if (carrying.bucketFull) { CompleteCommand(); } break; case BotAction.GET_BUCKET: if (targetBucket != null) { if (!targetBucket.bucketActive) { if (MoveTowards(targetBucket.transform.position)) { PickupBucket(targetBucket); CompleteCommand(); } } } else { if (botType == BotType.PASS_EMPTY || botType == BotType.PASS_FULL || botType == BotType.THROW) { MoveTowards(location_PICKUP); } RestartCommand(); } break; case BotAction.GOTO_PICKUP_LOCATION: if (MoveTowards(location_PICKUP)) { CompleteCommand(); } break; case BotAction.GOTO_DROPOFF_LOCATION: if (MoveTowards(location_DROPOFF)) { CompleteCommand(); } break; case BotAction.GOTO_WATER: if (targetWater != null) { if (targetWater.volume <= 0) { RestartCommand(); } if (MoveTowards(targetWater.transform.position)) { CompleteCommand(); } } break; case BotAction.GOTO_FIRE: if (fireSim.cellsOnFire > 0) { if (targetFlameCell != null) { if (!targetFlameCell.onFire) { RestartCommand(); } if (MoveTowards(targetFlameCell.transform.position)) { CompleteCommand(); } } else { RestartCommand(); } } else { Debug.Log("NO FIRES LEFT"); targetFlameCell = null; } break; } }
private bool HandleCollision(FlameCell cell) { GetField().KillPlayer(this); return(true); }
public void SetFrom(FlameCell f) { cx = f.cx; cy = f.cy; }