public SpawnEvent GenerateSpawnEvent(Faction spawnFaction, Faction targetFaction, int num, bool attack=true) { float padding = 2.0f; int side = PlayState.Random.Next(4); BoundingBox bounds = PlayState.ChunkManager.Bounds; Vector3 pos = Vector3.Zero; switch (side) { case 0: pos = new Vector3(bounds.Min.X + padding, bounds.Max.Y - padding, MathFunctions.Rand(bounds.Min.Z + padding, bounds.Max.Z - padding)); break; case 1: pos = new Vector3(bounds.Max.X - padding, bounds.Max.Y - padding, MathFunctions.Rand(bounds.Min.Z + padding, bounds.Max.Z - padding)); break; case 2: pos = new Vector3(MathFunctions.Rand(bounds.Min.X + padding, bounds.Max.X - padding), bounds.Max.Y - padding, bounds.Min.Z + padding); break; case 3: pos = new Vector3(MathFunctions.Rand(bounds.Min.X + padding, bounds.Max.X - padding), bounds.Max.Y - padding, bounds.Max.Z - padding); break; } return new SpawnEvent() { NumCreatures = num, SpawnFaction = spawnFaction, TargetFaction = targetFaction, WorldLocation = pos, Attack = attack }; }
public Economy(Faction faction, float currentMoney, PlayState state, string companyName, string companyMotto, NamedImageFrame companyLogo, Color companyColor) { PlayState = state; Company = Company.GenerateRandom(currentMoney, 1.0f, Company.Sector.Exploration); Company.Name = companyName; Company.SecondaryColor = Color.White; Company.Logo = companyLogo; Company.Motto = companyMotto; Company.Assets = currentMoney; Company.BaseColor = companyColor; CurrentMoney = currentMoney; Faction = faction; Market = new List<Company> { Company, Company.GenerateRandom(1000, 1.0f, Company.Sector.Exploration), Company.GenerateRandom(1200, 5.0f, Company.Sector.Exploration), Company.GenerateRandom(1500, 10.0f, Company.Sector.Exploration), Company.GenerateRandom(1300, 10.0f, Company.Sector.Manufacturing), Company.GenerateRandom(1200, 10.0f, Company.Sector.Manufacturing), Company.GenerateRandom(1500, 15.0f, Company.Sector.Military), Company.GenerateRandom(1300, 10.0f, Company.Sector.Military), Company.GenerateRandom(1200, 15.0f, Company.Sector.Military), Company.GenerateRandom(1500, 25.0f, Company.Sector.Magic), Company.GenerateRandom(1200, 30.0f, Company.Sector.Magic), Company.GenerateRandom(1300, 40.0f, Company.Sector.Magic), Company.GenerateRandom(1500, 50.0f, Company.Sector.Finance), Company.GenerateRandom(1800, 60.0f, Company.Sector.Finance) }; PlayState.Time.NewDay += Time_NewDay; }
public RoomBuilder(Faction faction) { DesignatedRooms = new List<Room>(); BuildDesignations = new List<BuildRoomOrder>(); CurrentRoomData = RoomLibrary.GetData("BedRoom"); Faction = faction; }
public Stockpile(Faction faction, IEnumerable<Voxel> voxels, RoomData data, ChunkManager chunks) : base(voxels, data, chunks) { Boxes = new List<Body>(); faction.Stockpiles.Add(this); Faction = faction; }
public Stockpile(Faction faction) : base(false, new List<Voxel>(), RoomLibrary.GetData(StockpileName), PlayState.ChunkManager) { Boxes = new List<Body>(); ReplacementType = VoxelLibrary.GetVoxelType("Stockpile"); faction.Stockpiles.Add(this); Faction = faction; }
public Dwarf(CreatureStats stats, string allies, PlanService planService, Faction faction, string name, ChunkManager chunks, GraphicsDevice graphics, ContentManager content, EmployeeClass workerClass, Vector3 position) : base(stats, allies, planService, faction, new Physics( "A Dwarf", PlayState.ComponentManager.RootComponent, Matrix.CreateTranslation(position), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.0f, -0.25f, 0.0f), 1.0f, 1.0f, 0.999f, 0.999f, new Vector3(0, -10, 0)), chunks, graphics, content, name) { Initialize(workerClass); }
public BuildRoomOrder(Room toBuild, Faction faction) { ToBuild = toBuild; PutResources = new Dictionary<ResourceLibrary.ResourceType, ResourceAmount>(); VoxelOrders = new List<BuildVoxelOrder>(); IsBuilt = false; Faction = faction; }
public GameMaster(Faction faction, DwarfGame game, ComponentManager components, ChunkManager chunks, Camera camera, GraphicsDevice graphics, DwarfGUI gui) { Faction = faction; Initialize(game, components, chunks, camera, graphics, gui); VoxSelector.Selected += OnSelected; BodySelector.Selected += OnBodiesSelected; PlayState.Time.NewDay += Time_NewDay; }
public ResourceInfoComponent(DwarfGUI gui, GUIComponent parent, Faction faction) : base(gui, parent) { Faction = faction; UpdateTimer = new Timer(0.5f, false); Layout = new GridLayout(gui, this, 1, 1); CurrentResources = new List<ResourceAmount>(); PanelWidth = 40; PanelHeight = 40; }
public DiplomacyState(DwarfGame game, GameStateManager stateManager, PlayState play, Faction faction) : base(game, "DiplomacyState", stateManager) { EdgePadding = 32; Input = new InputManager(); PlayState = play; EnableScreensaver = false; InputManager.KeyReleasedCallback += InputManager_KeyReleasedCallback; Faction = faction; }
public BalloonAI(Body body, Vector3 target, ShipmentOrder shipment, Faction faction) : base("BalloonAI", body) { Body = body; VelocityController = new PIDController(0.9f, 0.5f, 0.0f); MaxVelocity = 2.0f; MaxForce = 15.0f; TargetPosition = target; State = BalloonState.DeliveringGoods; Shipment = shipment; Faction = faction; CurrentResources = new List<ResourceAmount>(); }
public CapitalPanel(DwarfGUI gui, GUIComponent parent, Faction faction) : base(gui, parent) { Faction = faction; GridLayout layout = new GridLayout(gui, this, 4, 4); CurrentMoneyLabel = new Label(gui, layout, "Treasury: ", GUI.TitleFont); layout.SetComponentPosition(CurrentMoneyLabel, 0, 0, 2, 1); CurrentMoneyLabel.OnUpdate += CurrentMoneyLabel_OnUpdate; TotalPayLabel = new Label(gui, layout, "Employee pay: ", GUI.DefaultFont); layout.SetComponentPosition(TotalPayLabel, 2, 0, 2, 1); Stocks = new StockTicker(gui, layout, Faction.Economy); layout.SetComponentPosition(Stocks, 0, 1, 4, 3); }
public GoodsPanel(DwarfGUI gui, GUIComponent parent, Faction faction) : base(gui, parent) { LocalBounds = parent.GlobalBounds; Faction = faction; GridLayout layout = new GridLayout(GUI, this, 8, 4); Tabs = new TabSelector(GUI, layout, 4) { WidthSizeMode = SizeMode.Fit }; layout.SetComponentPosition(Tabs, 0, 0, 4, 8); TotalMoney = new Label(GUI, layout, "Total Money: " + Faction.Economy.CurrentMoney.ToString("C"), GUI.DefaultFont) { ToolTip = "Total amount of money in our treasury", WordWrap = true }; TotalMoney.OnUpdate += TotalMoney_OnUpdate; layout.SetComponentPosition(TotalMoney, 3, 0, 1, 1); SpaceLabel = new Label(GUI, layout, "Space: " + Faction.ComputeStockpileSpace() + "/" + Faction.ComputeStockpileCapacity(), GUI.DefaultFont) { ToolTip = "Space left in our stockpiles", WordWrap = true }; layout.SetComponentPosition(SpaceLabel, 2, 0, 1, 1); SpaceLabel.OnUpdate += SpaceLabel_OnUpdate; layout.UpdateSizes(); CreateBuyTab(); CreateSellTab(); Tabs.SetTab("Buy"); }
public Necromancer(CreatureStats stats, string allies, PlanService planService, Faction faction, ComponentManager manager, string name, Vector3 position) : base(manager, stats, allies, planService, faction, name) { Physics = new Physics(manager, "Necromancer", Matrix.CreateTranslation(position), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.0f, -0.25f, 0.0f), 1.0f, 1.0f, 0.999f, 0.999f, new Vector3(0, -10, 0)); Physics.AddChild(this); HasMeat = false; Initialize(); }
public void Initialize(PlayState state, string name, string motto, NamedImageFrame logo, Color color) { Races = new Dictionary<string, Race>(); /* Races["Dwarf"] = new Race() { Name = "Dwarf", CreatureTypes = new List<string> {"Dwarf", "AxeDwarf"}, IsIntelligent = true, IsNative = false, FactionNameFile = ContentPaths.Text.Templates.nations_dwarf, NameFile = ContentPaths.Text.Templates.names_dwarf, FactionNameTemplates = TextGenerator.GetAtoms(ContentPaths.Text.Templates.nations_dwarf) }; Races["Goblins"] = new Race() { Name = "Goblins", CreatureTypes = new List<string> { "Goblin"}, IsIntelligent = true, IsNative = true, FactionNameFile = ContentPaths.Text.Templates.nations_dwarf, NameFile = ContentPaths.Text.Templates.names_goblin, FactionNameTemplates = TextGenerator.GetAtoms(ContentPaths.Text.Templates.nations_goblin) }; Races["Molemen"] = new Race() { Name = "Molemen", CreatureTypes = new List<string> { "Moleman" }, IsIntelligent = true, IsNative = true, FactionNameFile = ContentPaths.Text.Templates.nations_dwarf, NameFile = ContentPaths.Text.Templates.names_dwarf, FactionNameTemplates = TextGenerator.GetAtoms(ContentPaths.Text.Templates.nations_goblin) }; Races["Elf"] = new Race() { Name = "Elf", CreatureTypes = new List<string> { "Elf" }, IsIntelligent = true, IsNative = true, FactionNameFile = ContentPaths.Text.Templates.nations_elf, NameFile = ContentPaths.Text.Templates.names_elf, FactionNameTemplates = TextGenerator.GetAtoms(ContentPaths.Text.Templates.nations_elf) }; Races["Undead"] = new Race() { Name = "Undead", CreatureTypes = new List<string> { "Necromancer", "Skeleton" }, IsIntelligent = true, IsNative = true, FactionNameFile = ContentPaths.Text.Templates.nations_undead, NameFile = ContentPaths.Text.Templates.names_undead, FactionNameTemplates = TextGenerator.GetAtoms(ContentPaths.Text.Templates.nations_undead) }; Races["Herbivore"] = new Race() { Name = "Herbivore", CreatureTypes = new List<string> { "Bird", "Deer" }, IsIntelligent = false, IsNative = true, FactionNameFile = ContentPaths.Text.Templates.nations_dwarf, NameFile = ContentPaths.Text.Templates.names_dwarf, }; */ Races = ContentPaths.LoadFromJson<Dictionary<string, Race>>(ContentPaths.World.races); Factions = new Dictionary<string, Faction>(); Factions["Player"] = new Faction { Name = "Player", Race = Races["Dwarf"] }; Factions["Player"].Economy = new Economy(Factions["Player"], 300.0f, state, name, motto, logo, color); Factions["Goblins"] = new Faction { Name = "Goblins", Race = Races["Goblins"] }; Factions["Elf"] = new Faction { Name = "Elf", Race = Races["Elf"] }; Factions["Undead"] = new Faction { Name = "Undead", Race = Races["Undead"] }; Factions["Herbivore"] = new Faction { Name = "Herbivore", Race = Races["Herbivore"] }; Factions["Molemen"] = new Faction { Name = "Molemen", Race = Races["Molemen"] }; }
public TradeEnvoy SendTradeEnvoy(Faction natives, WorldManager world) { if (!world.PlayerFaction.GetRooms().Any(room => room is BalloonPort && room.IsBuilt)) { world.MakeAnnouncement(String.Format("Trade envoy from {0} left. No balloon port!", natives.Name)); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.15f); return(null); } TradeEnvoy envoy = null; List <CreatureAI> creatures = world.MonsterSpawner.Spawn(world.MonsterSpawner.GenerateSpawnEvent(natives, world.PlayerFaction, MathFunctions.Random.Next(4) + 1, false)); if (natives.TradeMoney < 100m) { natives.TradeMoney += MathFunctions.Rand(250.0f, 5000.0f); } envoy = new TradeEnvoy(world.Time.CurrentDate) { Creatures = creatures, OtherFaction = world.PlayerFaction, ShouldRemove = false, OwnerFaction = natives, TradeGoods = natives.Race.GenerateResources(world), TradeMoney = natives.TradeMoney }; if (natives.Race.IsNative) { if (natives.Economy == null) { natives.Economy = new Economy(natives, 1000.0m, World, new CompanyInformation() { Name = natives.Name }); } foreach (CreatureAI creature in envoy.Creatures) { creature.Physics.AddChild(new ResourcePack(World.ComponentManager)); creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, natives.Economy.Company.Information)); } } else { Body balloon = world.PlayerFaction.DispatchBalloon(); if (balloon != null) { foreach (CreatureAI creature in creatures) { Matrix tf = creature.Physics.LocalTransform; tf.Translation = balloon.LocalTransform.Translation; creature.Physics.LocalTransform = tf; } } else { if (natives.Economy == null) { natives.Economy = new Economy(natives, 1000.0m, World, new CompanyInformation() { Name = natives.Name }); } foreach (CreatureAI creature in envoy.Creatures) { creature.Physics.AddChild(new ResourcePack(World.ComponentManager)); creature.Physics.AddChild(new Flag(World.ComponentManager, Vector3.Up * 0.5f + Vector3.Backward * 0.25f, natives.Economy.Company.Information)); } } } foreach (CreatureAI creature in envoy.Creatures) { creature.Physics.AddChild(new ResourcePack(World.ComponentManager)); } envoy.DistributeGoods(); natives.TradeEnvoys.Add(envoy); world.MakeAnnouncement(new DwarfCorp.Gui.Widgets.QueuedAnnouncement { Text = String.Format("Trade envoy from {0} has arrived!", natives.Name), ClickAction = (gui, sender) => { if (envoy.Creatures.Count > 0) { envoy.Creatures.First().ZoomToMe(); World.MakeWorldPopup(String.Format("Traders from {0} ({1}) have entered our territory.\nThey will try to get to our balloon port to trade with us.", natives.Name, natives.Race.Name), envoy.Creatures.First().Physics, -10); } }, ShouldKeep = () => { return(envoy.ExpiditionState == Expedition.State.Arriving); } }); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_positive_generic, 0.15f); world.Tutorial("trade"); if (!String.IsNullOrEmpty(natives.Race.TradeMusic)) { SoundManager.PlayMusic(natives.Race.TradeMusic); } return(envoy); }
public Elf(CreatureStats stats, string allies, PlanService planService, Faction faction, ComponentManager manager, string name, ChunkManager chunks, GraphicsDevice graphics, ContentManager content, Vector3 position) : base(stats, allies, planService, faction, new Physics("Elf", manager.RootComponent, Matrix.CreateTranslation(position), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.0f, -0.25f, 0.0f), 1.0f, 1.0f, 0.999f, 0.999f, new Vector3(0, -10, 0)), chunks, graphics, content, name) { Initialize(); }
public void AddFactions(List<Faction> factionsInSpawn) { if (Factions == null) { Factions = new Dictionary<string, Faction>(); if (Races == null) { InitializeRaces(); } Factions["Player"] = new Faction { Name = "Player", Race = Races["Dwarf"] }; } foreach (Faction faction in factionsInSpawn) { Factions[faction.Name] = faction; } }
public BalloonPort(Faction faction, bool designation, IEnumerable<Voxel> designations, ChunkManager chunks) : base(faction, designation, designations, BalloonPortData, chunks) { }
public EmployeeDisplay(DwarfGUI gui, GUIComponent parent, Faction faction) : base(gui, parent) { Faction = faction; Initialize(); }
public override void OnDequeued(Faction Faction) { Faction.Designations.RemoveEntityDesignation(Animal.Physics, DesignationType.Wrangle); }
override public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera) { base.Update(gameTime, chunks, camera); if (!Active) { return; } Creature.NoiseMaker.BasePitch = Stats.VoicePitch; // Non-dwarves are always at full energy. Stats.Energy.CurrentValue = 100.0f; BehaviorTimer.Update(gameTime); if (BehaviorTimer.HasTriggered) { if (Faction.Race.HasValue(out var race)) { if (!String.IsNullOrEmpty(race.BecomeWhenEvil) && MathFunctions.RandEvent(0.01f)) { Faction.Minions.Remove(this); Faction = World.Factions.Factions[race.BecomeWhenEvil]; Faction.AddMinion(this); } else if (!String.IsNullOrEmpty(race.BecomeWhenNotEvil) && MathFunctions.RandEvent(0.01f)) { Faction.Minions.Remove(this); Faction = World.Factions.Factions[race.BecomeWhenNotEvil]; Faction.AddMinion(this); } foreach (var body in World.EnumerateIntersectingObjects(Physics.BoundingBox.Expand(3.0f)).OfType <ResourceEntity>().Where(r => r.Active && r.AnimationQueue.Count == 0)) { if (Library.GetResourceType(body.Resource.TypeName).HasValue(out var resource) && resource.Tags.Contains("Edible")) { if ((race.EatsMeat && resource.Tags.Contains("AnimalProduct")) || (race.EatsPlants && !resource.Tags.Contains("AnimalProduct"))) { Creature.GatherImmediately(body); AssignTask(new ActWrapperTask(new EatFoodAct(this, false))); } } } } OrderEnemyAttack(); } DeleteBadTasks(); PreEmptTasks(); HandleReproduction(); // Try to find food if we are hungry. Wait - doesn't this rob the player? if (Stats.Hunger.IsDissatisfied() && World.CountResourcesWithTag("Edible") > 0) { var eatTask = new SatisfyHungerTask(); if (Stats.Hunger.IsCritical()) { eatTask.Priority = TaskPriority.Urgent; } if (!Tasks.Contains(eatTask) && CurrentTask.HasValue(out var task) && task != eatTask) // Really should just leave the current task in the task list. { AssignTask(eatTask); } } if (CurrentTask.HasValue(out var currentTask)) { if (!CurrentAct.HasValue()) // Should be impossible to have a current task and no current act. { // Try and recover the correct act. // <blecki> I always run with a breakpoint set here... just in case. ChangeAct(currentTask.CreateScript(Creature)); // This is a bad situation! if (!CurrentAct.HasValue()) { ChangeTask(null); } } if (CurrentAct.HasValue(out Act currentAct)) { var status = currentAct.Tick(); bool retried = false; if (CurrentAct.HasValue(out Act newCurrentAct) && currentTask != null) { if (status == Act.Status.Fail) { LastFailedAct = newCurrentAct.Name; if (!FailedTasks.Any(task => task.TaskFailure.Equals(currentTask))) { FailedTasks.Add(new FailedTask() { TaskFailure = currentTask, FailedTime = World.Time.CurrentDate }); } if (currentTask.ShouldRetry(Creature)) { if (!Tasks.Contains(currentTask)) { ReassignCurrentTask(); retried = true; } } } } if (currentTask != null && currentTask.IsComplete(World)) { ChangeTask(null); } else if (status != Act.Status.Running && !retried) { ChangeTask(null); } } } else { var goal = GetEasiestTask(Tasks); if (goal != null) { ChangeTask(goal); } else { var newTask = ActOnIdle(); if (newTask != null) { ChangeTask(newTask); } } } // With a small probability, the creature will drown if its under water. if (MathFunctions.RandEvent(GameSettings.Current.DrownChance)) { var above = VoxelHelpers.GetVoxelAbove(Physics.CurrentVoxel); var below = VoxelHelpers.GetVoxelBelow(Physics.CurrentVoxel); bool shouldDrown = (above.IsValid && (!above.IsEmpty || above.LiquidLevel > 0)); if ((Physics.IsInLiquid || (!Movement.CanSwim && (below.IsValid && (below.LiquidLevel > 5)))) && (!Movement.CanSwim || shouldDrown)) { Creature.Damage(Movement.CanSwim ? 1.0f : 30.0f, Health.DamageType.Normal); } } if (PositionConstraint.Contains(Physics.LocalPosition) == ContainmentType.Disjoint) { Physics.LocalPosition = MathFunctions.Clamp(Physics.Position, PositionConstraint); Physics.PropogateTransforms(); } }
public override bool IsComplete(Faction faction) { return(Animal == null || Animal.IsDead || (LastPen != null && LastPen.ZoneBodies.Contains(Animal.Physics))); }
public override void OnEnqueued(Faction Faction) { Faction.Designations.AddEntityDesignation(Animal.Physics, DesignationType.Wrangle, null, this); }
public override void OnVoxelsSelected(List <VoxelHandle> refs, InputManager.MouseButton button) { if (button == InputManager.MouseButton.Left) { int count = World.PersistentData.Designations.EnumerateDesignations(DesignationType.Dig).Count(); World.Tutorial("slice"); List <Task> assignments = new List <Task>(); foreach (var v in refs) { if (!v.IsValid || (v.IsEmpty && v.IsExplored) || v.Type.IsInvincible) { continue; } var boundingBox = v.GetBoundingBox().Expand(-0.1f); var entities = World.EnumerateIntersectingObjects(boundingBox, CollisionType.Static); if (entities.OfType <IVoxelListener>().Any()) { continue; } if (count >= GameSettings.Default.MaxVoxelDesignations) { World.UserInterface.ShowToolPopup("Too many dig designations!"); break; } // Todo: Should this be removed from the existing compound task and put in the new one? if (!World.PersistentData.Designations.IsVoxelDesignation(v, DesignationType.Dig) && !(World.IsInZone(v) || World.IsBuildDesignation(v))) { var task = new KillVoxelTask(v); task.Hidden = true; assignments.Add(task); count++; } } World.TaskManager.AddTasks(assignments); var compoundTask = new CompoundTask("DIG A HOLE", TaskCategory.Dig, TaskPriority.Medium); compoundTask.AddSubTasks(assignments); World.TaskManager.AddTask(compoundTask); var minions = Faction.FilterMinionsWithCapability(World.PersistentData.SelectedMinions, TaskCategory.Dig); OnConfirm(minions); } else { foreach (var r in refs) { if (r.IsValid) { if (World.PersistentData.Designations.GetVoxelDesignation(r, DesignationType.Dig).HasValue(out var designation) && designation.Task != null) // Todo: Is this necessary? { World.TaskManager.CancelTask(designation.Task); } } } } }
public void UpdateWarParties(Faction faction) { foreach (var party in faction.WarParties) { bool doneWaiting = party.UpdateTimer(World.Time.CurrentDate); party.Creatures.RemoveAll(creature => creature.IsDead); if (party.DeathTimer.Update(World.Time.CurrentDate)) { party.Creatures.ForEach((creature) => creature.Die()); } Diplomacy.Politics politics = faction.World.Diplomacy.GetPolitics(faction, party.OtherFaction); if (politics.GetCurrentRelationship() != Relationship.Hateful) { RecallWarParty(party); } if (party.Creatures.All(creature => creature.IsDead)) { party.ShouldRemove = true; // Killed entire war party. Wonderful! World.GoalManager.OnGameEvent(new Goals.Triggers.WarPartyDefeated { PlayerFaction = party.OtherFaction, OtherFaction = party.OwnerFaction }); } if (!doneWaiting) { continue; } else { foreach (var creature in party.OwnerFaction.Minions) { if (creature.Tasks.Count == 0) { CreatureAI enemyMinion = party.OtherFaction.GetNearestMinion(creature.Position); if (enemyMinion != null) { creature.AssignTask(new KillEntityTask(enemyMinion.Physics, KillEntityTask.KillType.Auto)); } } } if (party.ExpiditionState == Expedition.State.Arriving) { World.MakeAnnouncement(String.Format("The war party from {0} is attacking!", party.OwnerFaction.Name)); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.15f); party.ExpiditionState = Expedition.State.Fighting; } } foreach (var creature in party.Creatures) { if (MathFunctions.RandEvent(0.001f)) { creature.AssignTask(new ActWrapperTask(new GetMoneyAct(creature, (decimal)MathFunctions.Rand(0, 64.0f), party.OtherFaction)) { Priority = Task.PriorityType.Medium }); } } } faction.WarParties.RemoveAll(w => w.ShouldRemove); }
public void UpdateTradeEnvoys(Faction faction) { foreach (TradeEnvoy envoy in faction.TradeEnvoys) { if (envoy.ExpiditionState == Expedition.State.Trading) { if (envoy.UpdateWaitTimer(World.Time.CurrentDate)) { World.MakeAnnouncement(String.Format("The envoy from {0} is leaving.", envoy.OwnerFaction.Name)); RecallEnvoy(envoy); } } envoy.Creatures.RemoveAll(creature => creature.IsDead); if (envoy.DeathTimer.Update(faction.World.Time.CurrentDate)) { envoy.Creatures.ForEach((creature) => creature.GetRoot().Die()); } Diplomacy.Politics politics = faction.World.Diplomacy.GetPolitics(faction, envoy.OtherFaction); if (politics.GetCurrentRelationship() == Relationship.Hateful) { World.MakeAnnouncement(String.Format("The envoy from {0} is leaving.", envoy.OwnerFaction.Name)); RecallEnvoy(envoy); } else { if (envoy.Creatures.Any( // TODO (mklingen) why do I need this null check? creature => creature.Creature != null && envoy.OtherFaction.Designations.IsDesignation(creature.Physics, DesignationType.Attack))) { if (!politics.HasEvent("You attacked our trade delegates")) { politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = -1.0f, Description = "You attacked our trade delegates", Duration = new TimeSpan(1, 0, 0, 0), Time = faction.World.Time.CurrentDate }); } else { politics.RecentEvents.Add(new Diplomacy.PoliticalEvent() { Change = -2.0f, Description = "You attacked our trade delegates more than once", Duration = new TimeSpan(1, 0, 0, 0), Time = faction.World.Time.CurrentDate }); } } } if (!envoy.ShouldRemove && envoy.ExpiditionState == Expedition.State.Arriving) { foreach (CreatureAI creature in envoy.Creatures) { Room tradePort = envoy.OtherFaction.GetNearestRoomOfType("Balloon Port", creature.Position); if (tradePort == null) { World.MakeAnnouncement("We need a balloon trade port to trade.", null, () => { return(envoy.OtherFaction.GetNearestRoomOfType("Balloon Port", creature.Position) == null); }); World.Tutorial("trade"); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_negative_generic, 0.5f); RecallEnvoy(envoy); break; } if (creature.Tasks.Count == 0) { TradeEnvoy envoy1 = envoy; creature.Tasks.Add(new TradeTask(tradePort, envoy1)); } if (!tradePort.IsRestingOnZone(creature.Position)) { continue; } if (envoy.ExpiditionState != Expedition.State.Trading || !envoy.IsTradeWidgetValid()) { envoy.MakeTradeWidget(World); } envoy.StartTrading(World.Time.CurrentDate); envoy.ExpiditionState = Expedition.State.Trading; break; } } else if (envoy.ExpiditionState == Expedition.State.Leaving) { BoundingBox worldBBox = faction.World.ChunkManager.Bounds; foreach (CreatureAI creature in envoy.Creatures) { if (creature.Tasks.Count == 0) { creature.LeaveWorld(); } } foreach (CreatureAI creature in envoy.Creatures) { if (MathFunctions.Dist2D(worldBBox, creature.Position) < 2.0f) { creature.GetRoot().Delete(); } } } else { if (!envoy.IsTradeWidgetValid()) { envoy.MakeTradeWidget(World); } } if (envoy.Creatures.All(creature => creature.IsDead)) { envoy.ShouldRemove = true; World.GoalManager.OnGameEvent(new Goals.Triggers.TradeEnvoyKilled { PlayerFaction = envoy.OtherFaction, OtherFaction = envoy.OwnerFaction }); } } bool hadFactions = faction.TradeEnvoys.Count > 0; faction.TradeEnvoys.RemoveAll(t => t == null || t.ShouldRemove); if (hadFactions && faction.TradeEnvoys.Count == 0) { var music = World.Time.IsDay() ? "main_theme_day" : "main_theme_night"; SoundManager.PlayMusic(music); } }
public bool HasAvailableResources(int numVoxels, Faction faction) { foreach (KeyValuePair<ResourceLibrary.ResourceType, ResourceAmount> resources in RequiredResources) { ResourceAmount required = new ResourceAmount(resources.Value) { NumResources = (int) (numVoxels*resources.Value.NumResources*0.25f) }; if (!faction.HasResources(new List<ResourceAmount>() {required})) { return false; } } return true; }
public override bool IsComplete(Faction faction) { return(Ally.IsDead || !Ally.Status.Health.IsDissatisfied()); }
public bool Verify(List<Voxel> refs, Faction faction) { if (refs.Count == 0) { return false; } List<BoundingBox> boxes = refs.Select(voxel => voxel.GetBoundingBox()).ToList(); BoundingBox box = MathFunctions.GetBoundingBox(boxes); Vector3 extents = box.Max - box.Min; float maxExtents = Math.Max(extents.X, extents.Z); float minExtents = Math.Min(extents.X, extents.Z); if (maxExtents < MinimumSideLength || minExtents < MinimumSideWidth) { PlayState.GUI.ToolTipManager.Popup("Room is too small (minimum is " + MinimumSideLength + " x " + MinimumSideWidth +")!"); return false; } if (!HasAvailableResources(refs.Count, faction)) { PlayState.GUI.ToolTipManager.Popup("Not enough resources for this room."); return false; } int height = -1; foreach (Voxel voxel in refs) { if (voxel.IsEmpty) continue; if (voxel.Type.IsInvincible) continue; if (height == -1) { height = (int)voxel.GridPosition.Y; } else if (height != (int) voxel.GridPosition.Y && !CanBuildOnMultipleLevels) { PlayState.GUI.ToolTipManager.Popup("Room must be on flat ground!"); return false; } if (MustBeBuiltOnSoil) { if (!voxel.Type.IsSoil) { PlayState.GUI.ToolTipManager.Popup("Room must be built on soil!"); return false; } } if (!CanBuildAboveGround) { if (voxel.Chunk.Data.SunColors[voxel.Index] <= 5) continue; PlayState.GUI.ToolTipManager.Popup("Room can't be built aboveground!"); return false; } else if (!CanBuildBelowGround) { if (voxel.Chunk.Data.SunColors[voxel.Index] >= 5) continue; PlayState.GUI.ToolTipManager.Popup("Room can't be built belowground!"); return false; } } return true; }
public Politics GetPolitics(Faction factionA, Faction factionB) { return(FactionPolitics[new Pair <string>(factionA.Name, factionB.Name)]); }
public BalloonPort(Faction faction, IEnumerable<Voxel> voxels, ChunkManager chunks) : base(faction, voxels, BalloonPortData, chunks) { OnBuilt(); }
public PutDesignator(Faction faction, Texture2D blockTextures) { Faction = faction; Designations = new List <WallBuilder>(); BlockTextures = blockTextures; }
public Politics GetPolitics(Faction factionA, Faction factionB) { return(FactionPolitics[new Pair <Faction>(factionA, factionB)]); }
public Dwarf(ComponentManager manager, CreatureStats stats, string allies, PlanService planService, Faction faction, string name, ChunkManager chunks, GraphicsDevice graphics, ContentManager content, EmployeeClass workerClass, Vector3 position) : base(stats, allies, planService, faction, new Physics("Dwarf", manager.RootComponent, Matrix.CreateTranslation(position), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.0f, -0.25f, 0.0f), 1.0f, 1.0f, 0.999f, 0.999f, new Vector3(0, -10, 0)), chunks, graphics, content, name) { HasMeat = false; HasBones = false; Initialize(workerClass); }
public void Initialize(PlayState state, string name, string motto, NamedImageFrame logo, Color color) { if (Races == null) { InitializeRaces(); } if (Factions == null) { Factions = new Dictionary<string, Faction>(); Factions["Player"] = new Faction { Name = "Player", Race = Races["Dwarf"] }; } Factions["Goblins"] = new Faction { Name = "Goblins", Race = Races["Goblins"], IsRaceFaction = true }; Factions["Elf"] = new Faction { Name = "Elf", Race = Races["Elf"], IsRaceFaction = true }; Factions["Undead"] = new Faction { Name = "Undead", Race = Races["Undead"], IsRaceFaction = true }; Factions["Herbivore"] = new Faction { Name = "Herbivore", Race = Races["Herbivore"], IsRaceFaction = true }; Factions["Molemen"] = new Faction { Name = "Molemen", Race = Races["Molemen"], IsRaceFaction = true }; Factions["Player"].Economy = new Economy(Factions["Player"], 300.0f, state, name, motto, logo, color); }
public void SendTradeEnvoy(Faction natives) { // todo PlayState playState = (PlayState) GameState.Game.StateManager.GetState<PlayState>("PlayState"); if (playState.IsActiveState) { List<CreatureAI> creatures = PlayState.MonsterSpawner.Spawn(PlayState.MonsterSpawner.GenerateSpawnEvent(natives, PlayState.PlayerFaction, PlayState.Random.Next(4) + 1, false)); if (creatures.Count > 0) { PlayState.AnnouncementManager.Announce("Trade envoy from " + natives.Name + " has arrived!", "Click to zoom to location", creatures.First().ZoomToMe); } GameState.Game.StateManager.PushState(new DiplomacyState(GameState.Game, GameState.Game.StateManager, (PlayState) GameState.Game.StateManager.GetState<PlayState>("PlayState"), natives) { Name = "DiplomacyState_" + natives.Name}); } }
public TaskManager(Faction faction) { Faction = faction; TaskQueue = new Dictionary<Creature, Queue<Task>>(); }
public void Initialize(WorldManager world, CompanyInformation CompanyInformation) { Factions["Player"] = new Faction(world, new OverworldFaction { Name = "Player", Race = "Corporate", }); Factions["Corporate"] = new Faction(world, new OverworldFaction { Name = "Corporate", Race = "Corporate", InteractiveFaction = true, IsCorporate = true }); Factions["Herbivore"] = new Faction(world, new OverworldFaction { Name = "Herbivore", Race = "Herbivore" }); Factions["Carnivore"] = new Faction(world, new OverworldFaction { Name = "Carnivore", Race = "Carnivore" }); Factions["Evil"] = new Faction(world, new OverworldFaction { Name = "Evil", Race = "Evil" }); Factions["Dwarves"] = new Faction(world, new OverworldFaction { Name = "Dwarves", Race = "Dwarf" }); Factions["Goblins"] = new Faction(world, new OverworldFaction // Todo: Normalize race name { Name = "Goblins", Race = "Goblins" }); Factions["Elf"] = new Faction(world, new OverworldFaction { Name = "Elf", Race = "Elf" }); Factions["Undead"] = new Faction(world, new OverworldFaction { Name = "Undead", Race = "Undead" }); Factions["Demon"] = new Faction(world, new OverworldFaction { Name = "Demon", Race = "Demon" }); Factions["Molemen"] = new Faction(world, new OverworldFaction { Name = "Molemen", Race = "Molemen" }); }
public CraftBuilder(Faction faction) { Faction = faction; Designations = new List<CraftDesignation>(); IsEnabled = false; }
public void InitializeFactionPolitics(Faction New, DateTime Now) { TimeSpan forever = new TimeSpan(999999, 0, 0, 0); foreach (var faction in Factions.Factions) { Pair <string> pair = new Pair <string>(faction.Value.Name, New.Name); if (FactionPolitics.ContainsKey(pair)) { continue; } if (faction.Key == New.Name) { FactionPolitics[pair] = new Politics(Now, new TimeSpan(0, 0, 0)) { Faction = faction.Value, HasMet = true, RecentEvents = new List <PoliticalEvent>() { new PoliticalEvent() { Change = 1.0f, Description = "we are of the same faction", Duration = forever, Time = Now } } }; } else { Point c1 = faction.Value.Center; Point c2 = New.Center; double dist = Math.Sqrt(Math.Pow(c1.X - c2.X, 2) + Math.Pow(c1.Y - c2.Y, 2)); // Time always takes between 1 and 4 days of travel. double timeInMinutes = Math.Min(Math.Max(dist * 2.0f, 1440), 1440 * 4) + MathFunctions.RandInt(0, 250); Politics politics = new Politics(Now, new TimeSpan(0, (int)(timeInMinutes), 0)) { Faction = New, HasMet = false, RecentEvents = new List <PoliticalEvent>(), }; if (faction.Value.Race == New.Race) { politics.RecentEvents.Add(new PoliticalEvent() { Change = 0.5f, Description = "we are of the same people", Duration = forever, Time = Now }); } if (faction.Value.Race.NaturalEnemies.Any(name => name == New.Race.Name)) { if (!politics.HasEvent("we are taught to hate your kind")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = -10.0f, // Make this negative and we get an instant war party rush. Description = "we are taught to hate your kind", Duration = forever, Time = Now }); } } if (faction.Value.Race.IsIntelligent && New.Race.IsIntelligent) { float trustingness = faction.Value.GoodWill; if (trustingness < -0.8f) { if (!politics.HasEvent("we just don't trust you")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = -10.0f, // Make this negative and we get an instant war party rush. Description = "we just don't trust you", Duration = forever, Time = Now }); politics.WasAtWar = true; } if (!politics.HasEvent("you stole our land")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = -1.0f, Description = "you stole our land", Duration = forever, Time = Now }); } } else if (trustingness > 0.8f) { if (!politics.HasEvent("we just trust you")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = 10.0f, Description = "we just trust you", Duration = forever, Time = Now }); } } else if (faction.Value.ClaimsColony && !faction.Value.IsMotherland) { if (!politics.HasEvent("you stole our land")) { politics.RecentEvents.Add(new PoliticalEvent() { Change = -0.1f, Description = "you stole our land", Duration = forever, Time = Now }); } } } FactionPolitics[pair] = politics; } } FactionPolitics[new Pair <string>("Undead", "Player")].RecentEvents.Add(new PoliticalEvent() { Change = -10.0f, Description = "Test hate", Duration = forever, Time = Now }); }
public void Sense() { if (!Active) { return; } if (World.InitialEmbark.Difficulty == 0) { return; } if (Allies == null && Creature != null) { Allies = Creature.Faction; } List <CreatureAI> sensed = new List <CreatureAI>(); VoxelHandle currentVoxel = new VoxelHandle(World.ChunkManager.ChunkData, GlobalVoxelCoordinate.FromVector3(Position)); if (!(currentVoxel.IsValid && currentVoxel.IsEmpty)) { return; } foreach (var body in Manager.World.EnumerateIntersectingObjects(BoundingBox, CollisionType.Both)) { CreatureAI minion = body.GetRoot().GetComponent <CreatureAI>(); if (minion == null) { continue; } Faction faction = minion.Faction; if (World.Diplomacy.GetPolitics(Allies, faction).GetCurrentRelationship() != Relationship.Hateful) { continue; } if (!minion.Active) { continue; } if (!DetectCloaked && minion.Creature.IsCloaked) { continue; } else if (DetectCloaked && minion.Creature.IsCloaked) { minion.Creature.IsCloaked = false; } float dist = (minion.Position - GlobalTransform.Translation).LengthSquared(); if (dist < SenseRadius && !VoxelHelpers.DoesRayHitSolidVoxel( Manager.World.ChunkManager.ChunkData, Position, minion.Position)) { sensed.Add(minion); } } if (sensed.Count > 0) { OnEnemySensed.Invoke(sensed); } }
public Politics GetPolitics(Faction factionA, Faction factionB) { return FactionPolitics[new Pair<Faction>(factionA, factionB)]; }
public BuildStockpileOrder(Stockpile toBuild, Faction faction) : base(toBuild, faction) { }
public static Room CreateRoom(Faction faction, string name, List <VoxelHandle> designations, bool blueprint, WorldManager world) { // TODO(mklingen): omg get rid of this horrible legacy function! if (name == BalloonPort.BalloonPortName) { return(blueprint ? new BalloonPort(faction, true, designations, world) : new BalloonPort(faction, designations, world)); } else if (name == BedRoom.BedRoomName) { return(blueprint ? new BedRoom(true, designations, world, faction) : new BedRoom(designations, world, faction)); } else if (name == CommonRoom.CommonRoomName) { return(blueprint ? new CommonRoom(true, designations, world, faction) : new CommonRoom(designations, world, faction)); } else if (name == LibraryRoom.LibraryRoomName) { return(blueprint ? new LibraryRoom(true, designations, world, faction) : new LibraryRoom(designations, world, faction)); } else if (name == TrainingRoom.TrainingRoomName) { return(blueprint ? new TrainingRoom(true, designations, world, faction) : new TrainingRoom(designations, world, faction)); } else if (name == WorkshopRoom.WorkshopName) { return(blueprint ? new WorkshopRoom(true, designations, world, faction) : new WorkshopRoom(designations, world, faction)); } else if (name == Kitchen.KitchenName) { return(blueprint ? new Kitchen(true, designations, world, faction) : new Kitchen(designations, world, faction)); } else if (name == Stockpile.StockpileName) { Stockpile toBuild = new Stockpile(faction, world); foreach (var voxel in designations) { toBuild.AddVoxel(voxel); } return(toBuild); } else if (name == Graveyard.GraveyardName) { return(blueprint ? new Graveyard(faction, true, designations, world) : new Graveyard(faction, designations, world)); } else if (name == AnimalPen.AnimalPenName) { return(blueprint ? new AnimalPen(true, designations, world, faction) : new AnimalPen(designations, world, faction)); } else if (name == Treasury.TreasuryName) { Treasury toBuild = new Treasury(faction, world); foreach (var voxel in designations) { toBuild.AddVoxel(voxel); } return(toBuild); } else { return(null); } }
public Creature(CreatureStats stats, string allies, PlanService planService, Faction faction, Physics parent, ChunkManager chunks, GraphicsDevice graphics, ContentManager content, string name) : base(parent.Manager, name, parent, stats.MaxHealth, 0.0f, stats.MaxHealth) { Buffs = new List<Buff>(); IsOnGround = true; Physics = parent; Stats = stats; Chunks = chunks; Graphics = graphics; Content = content; Faction = faction; PlanService = planService; Allies = allies; Controller = new PIDController(Stats.MaxAcceleration, Stats.StoppingForce * 2, 0.0f); JumpTimer = new Timer(0.2f, true); Status = new CreatureStatus(); IsHeadClear = true; NoiseMaker = new NoiseMaker(); OverrideCharacterMode = false; SelectionCircle = new SelectionCircle(Manager, Physics) { IsVisible = false }; }
public static HireDialog Popup(DwarfGUI gui, Faction faction) { int w = gui.Graphics.Viewport.Width - 64; int h = gui.Graphics.Viewport.Height - 64; HireDialog toReturn = new HireDialog(gui, gui.RootComponent) { Faction = faction, LocalBounds = new Rectangle(gui.Graphics.Viewport.Width/2 - w/2, gui.Graphics.Viewport.Height/2 - h/2, w, h) }; toReturn.Initialize(ButtonType.OK, "Hire new Employees", ""); return toReturn; }
public void SendWarParty(Faction natives) { // todo PlayState.AnnouncementManager.Announce("War party from " + natives.Name + " has arrived!", ""); Politics politics = GetPolitics(natives, PlayState.PlayerFaction); PlayState.MonsterSpawner.Spawn(PlayState.MonsterSpawner.GenerateSpawnEvent(natives, PlayState.PlayerFaction, PlayState.Random.Next(5) + 1, true)); }
public void AddFaction(Faction Faction) { Factions[Faction.ParentFaction.Name] = Faction; }
public Elf(CreatureStats stats, string allies, PlanService planService, Faction faction, ComponentManager manager, string name, ChunkManager chunks, GraphicsDevice graphics, ContentManager content, Vector3 position) : base(stats, allies, planService, faction, new Physics("elf", manager.RootComponent, Matrix.CreateTranslation(position), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.0f, -0.25f, 0.0f), 1.0f, 1.0f, 0.999f, 0.999f, new Vector3(0, -10, 0)), chunks, graphics, content, name) { Initialize(); }
public MudGolem(CreatureStats stats, string blood, string allies, PlanService planService, Faction faction, ComponentManager manager, string name, Vector3 position) : base(manager, stats, allies, planService, faction, name) { Physics = new Physics(Manager, name, Matrix.CreateTranslation(position), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.0f, -0.25f, 0.0f), 1.0f, 1.0f, 0.999f, 0.999f, new Vector3(0, -10, 0)); Physics.AddChild(this); Initialize(blood); }