// Like mini-AStar, maybe move to AStar?? public static List<Tile> getMovementRange(Grid grid, Character character) { int max_dist = character.move_speed; List<Tile> stack = new List<Tile> (); // Like open set List<Tile> move_range = new List<Tile> (){character.current_tile}; Dictionary<Tile, int> dist = new Dictionary<Tile, int> (); // Walking distance from character foreach (var tile in Grid.getNeighboringTiles(grid, character.current_tile)) { dist[tile] = 1; stack.Add(tile); } while (stack.Count > 0) { Tile tile = stack[0]; stack.Remove(tile); if (!move_range.Contains(tile)) { move_range.Add(tile); if (dist[tile] < max_dist) { foreach (var neighbor in Grid.getNeighboringTiles(grid, tile)) { //TODO: Limit by vision if (!move_range.Contains(neighbor)) { dist[neighbor] = dist[tile] + 1; stack.Add(neighbor); } } } } } return move_range; }
public static void AutomaticallyLitStripMining(BuildConstructionJob buildConstructionJob, Character character) { Vector3 jobPosition = buildConstructionJob.Position; int depth = (int)(GnomanEmpire.Instance.Map.SurfaceLevel - jobPosition.Z); if (depth > -8) return; BuildConstructionJobData jobData = (BuildConstructionJobData)buildConstructionJob.Data; if (jobData.ConstructionID != ConstructionID.Torch) return; Map map = GnomanEmpire.Instance.Map; int mapWidth = map.MapWidth; int mapHeight = map.MapHeight; for (int x = (int)(jobPosition.X - SafeTorchDistance); x <= jobPosition.X + SafeTorchDistance; x++) { if (x < 1) x = 1; if (x > mapHeight - 2) break; CreateSafeMineJob(map, new Vector3(x, jobPosition.Y, jobPosition.Z), character); } for (int y = (int)(jobPosition.Y - SafeTorchDistance); y <= jobPosition.Y + SafeTorchDistance; y++) { if (y < 1) y = 1; if (y > mapWidth - 2) break; CreateSafeMineJob(map, new Vector3(jobPosition.X, y, jobPosition.Z), character); } }
public World() { Random rnd = new Random(); #if SILVERLIGHT Res.SearchPath.addPath("file://K:/Projects/steel/moora/Resources"); // dirs.Add("http://division.kindex.lv/moora/terrain"); #else Res.SearchPath.addPath("../../../Resources"); Res.SearchPath.addPath("Resources"); #endif terrain = new Terrain(rnd); // map = new RandomMap(21, 18, terrain, rnd); List<string> file = Res.TextFile.GetTextFile("map.txt"); map = new FileMap(terrain, file); int char_x; int char_y; int try_number = 0; do { char_x = rnd.Next(0, map.X); char_y = rnd.Next(0, map.Y); if (try_number++ > 1000) { break; } } while (map.getTerrain(char_x, char_y) != TerrainType.Sand); character = new Character(char_x, char_y, map); }
public ItemCreator() { creator = GnomanEmpire.Instance.EntityManager.Entities .Where(x => x.Value.TypeID() == (int) GameEntityType.Character) .Select(x => x.Value) .Cast<Character>() .First(x => x.RaceID == RaceID.Gnome.ToString()); }
public Character FindAttackTarget(Character c) { var charSquad = c.Squad.Name.ToLower(); var index = GetSquadIndex(c.Squad); if (!attackTargets.ContainsKey(index)) index = AllSquads; return attackTargets[index].Where(t => !c.ShouldRunFromTarget(t) && c.CanTarget(t)).FirstOrDefault(); }
public GnomeStats(Character gnome) { // Mind Happiness = gnome.Mind.HappinessLevel; // Body BloodLevel = gnome.Body.BloodLevel; Hunger = gnome.Body.HungerLevel; Rest = gnome.Body.RestLevel; Thirst = gnome.Body.ThirstLevel; }
public void AddTarget(IEnumerable<int> squadIndexes, Character target) { foreach (var index in squadIndexes) { if (!attackTargets.ContainsKey(index)) attackTargets.Add(index, new List<Character>()); if (!attackTargets[index].Contains(target)) attackTargets[index].Add(target); } }
public Gnome(Character gnome, SkillDef[] skillDefinitions) { ID = gnome.ID; Name = gnome.Name(); Location = new Location(gnome.Position); Stats = new GnomeStats(gnome); Profession = new GnomeProfession(gnome.Mind.Profession); BodyParts = GnomeBodyPartStatus.GetBodyStatus(gnome); LaborSkills = GnomeSkill.GetGnomeSkills(GnomeSkill.GnomeSkillType.Labor, skillDefinitions, gnome); CombatSkills = GnomeSkill.GetGnomeSkills(GnomeSkill.GnomeSkillType.Combat, skillDefinitions, gnome); }
public static GnomeSkill[] GetGnomeSkills(GnomeSkillType skillType, SkillDef[] skillDefinitions, Character gameGnome) { List<String> skillNames = new List<String>(); if (skillType.HasFlag(GnomeSkillType.Labor)) { skillNames.AddRange(GnomanEmpire.Instance.GameDefs.CharacterSettings.LaborSkills); } if (skillType.HasFlag(GnomeSkillType.Combat)) { skillNames.AddRange(GnomanEmpire.Instance.GameDefs.CharacterSettings.CombatSkills); } var skills = skillDefinitions.Where(obj => skillNames.Contains(obj.Name)).Select(skill => new GnomeSkill(gameGnome, skill)).ToArray(); return skills; }
public static Attack GetAttack(string keyPress, Character character) { if(keyPress == "Button B") { return new Squash(character); } if(keyPress == "Button C") { return new Punch(character); } if (keyPress == "Button D") { return new Bump(character); } return null; }
public GnomeRow(Character character) : base(character) { Name = character.Name(); Profession = character.Mind.Profession; Mining = character.SkillLevel(CharacterSkillType.Mining.ToString()); Masonry = character.SkillLevel(CharacterSkillType.Masonry.ToString()); Stonecarving = character.SkillLevel(CharacterSkillType.Stonecarving.ToString()); WoodCutting = character.SkillLevel(CharacterSkillType.Woodcutting.ToString()); Carpentry = character.SkillLevel(CharacterSkillType.Carpentry.ToString()); Woodcarving = character.SkillLevel(CharacterSkillType.Woodcarving.ToString()); Smelting = character.SkillLevel(CharacterSkillType.Smelting.ToString()); Blacksmithing = character.SkillLevel(CharacterSkillType.Blacksmithing.ToString()); Metalworking = character.SkillLevel(CharacterSkillType.Metalworking.ToString()); WeaponCrafting = character.SkillLevel(CharacterSkillType.WeaponCrafting.ToString()); ArmorCrafting = character.SkillLevel(CharacterSkillType.ArmorCrafting.ToString()); Gemcutting = character.SkillLevel(CharacterSkillType.Gemcutting.ToString()); JewelryMaking = character.SkillLevel(CharacterSkillType.JewelryMaking.ToString()); Weaving = character.SkillLevel(CharacterSkillType.Weaving.ToString()); Tailoring = character.SkillLevel(CharacterSkillType.Tailoring.ToString()); Pottery = character.SkillLevel(CharacterSkillType.Pottery.ToString()); Leatherworking = character.SkillLevel(CharacterSkillType.Leatherworking.ToString()); Bonecarving = character.SkillLevel(CharacterSkillType.Bonecarving.ToString()); Prospecting = character.SkillLevel(CharacterSkillType.Prospecting.ToString()); Tinkering = character.SkillLevel(CharacterSkillType.Tinkering.ToString()); Machining = character.SkillLevel(CharacterSkillType.Machining.ToString()); Engineering = character.SkillLevel(CharacterSkillType.Engineering.ToString()); Mechanic = character.SkillLevel(CharacterSkillType.Mechanic.ToString()); AnimalHusbandry = character.SkillLevel(CharacterSkillType.AnimalHusbandry.ToString()); Butchery = character.SkillLevel(CharacterSkillType.Butchery.ToString()); Horticulture = character.SkillLevel(CharacterSkillType.Horticulture.ToString()); Farming = character.SkillLevel(CharacterSkillType.Farming.ToString()); Cooking = character.SkillLevel(CharacterSkillType.Cooking.ToString()); Brewing = character.SkillLevel(CharacterSkillType.Brewing.ToString()); Medic = character.SkillLevel(CharacterSkillType.Medic.ToString()); Caretaking = character.SkillLevel(CharacterSkillType.Caretaking.ToString()); Construction = character.SkillLevel(CharacterSkillType.Construction.ToString()); Hauling = character.SkillLevel(CharacterSkillType.Hauling.ToString()); }
public IResponseFormatter Add() { var skillDefinitions = GnomanEmpire.Instance.GetSkillDefs(); var faction = GnomanEmpire.Instance.World.AIDirector.PlayerFaction; var entryPosition = faction.FindRegionEntryPosition(); var gnomadRaceClassDefs = faction.FactionDef.Squads.SelectMany(squad => squad.Classes.Where(squadClass => squadClass.Name == "Gnomad")).ToList(); Int32 defCount = gnomadRaceClassDefs.Count; Int32 raceClassDefIndex = GnomanEmpire.Instance.Rand.Next(defCount); var raceClassDef = gnomadRaceClassDefs[raceClassDefIndex]; var gnomad = new Character(entryPosition, raceClassDef, faction.ID); gnomad.SetBehavior(BehaviorType.PlayerCharacter); Dictionary<String, Int32> orderedProfessions = GetBestProfessions(gnomad); var bestProfession = orderedProfessions.OrderByDescending(obj => obj.Value).First().Key; SetProfession(gnomad, bestProfession); GnomanEmpire.Instance.EntityManager.SpawnEntityImmediate(gnomad); GnomanEmpire.Instance.World.NotificationManager.AddNotification(String.Format("The Gnomad {0} has arrived and been assigned as a {1}", gnomad.Name(), bestProfession)); Gnome gnome = new Gnome(gnomad, skillDefinitions); return JsonResponse(gnome); }
public static TillSoilJob FindTillSoilJobForSeed(FarmManager farmManager, Character character) { TillSoilJob tillSoilJob = farmManager.FindTillSoilJob(character); if (tillSoilJob == null) { return null; } Vector3 position = tillSoilJob.Position; Map map = GnomanEmpire.Instance.Map; MapCell cell = map.GetCell(position); Designation designation = cell.Designation; Farm farm = designation as Farm; if (farm != null) { int seedMaterial = farm.SeedMaterial; StockManager stockManager = GnomanEmpire.Instance.Fortress.StockManager; if (stockManager.FindClosestItem(position, ItemID.Seed, seedMaterial) != null) { return tillSoilJob; } } tillSoilJob.Cancel(); return null; }
public static bool ImprovedFarming(Character character, out bool returnValue) { if (character.Mind.IsSkillAllowed(CharacterSkillType.Farming)) { FarmManager farmManager = GnomanEmpire.Instance.Fortress.FarmManager; Job job = farmManager.FindPlantSeedJob(character); if (job != null) { JobField.SetValue(character, job); job.Claim(character); returnValue = true; return true; } job = FindTillSoilJobForSeed(farmManager, character); if (job != null) { JobField.SetValue(character, job); job.Claim(character); returnValue = true; return true; } job = farmManager.FindHarvestJob(character); if (job != null) { JobField.SetValue(character, job); job.Claim(character); returnValue = true; return true; } job = farmManager.FindTillSoilJob(character); if (job != null) { JobField.SetValue(character, job); job.Claim(character); returnValue = true; return true; } } returnValue = false; return true; }
public void RemoveAttackTarget(Character c) { foreach (var targets in attackTargets.Values) targets.Remove(c); }
private void setSelect(Informant informant, bool select) { if (IsSameOrSubclass(typeof(GridThing), informant.GetType())) { GridThing gridThing = informant as GridThing; gridThing.setSelected(select); // If tile, that contains a character, set select for character as well if (IsSameOrSubclass(typeof(Tile), informant.GetType())) { Tile tile = informant as Tile; if (tile.character) { setSelect(tile.character, select); } } // If character, select tiles in movement range if (select && IsSameOrSubclass(typeof(Character), informant.GetType())) { Character character = informant as Character; //TODO: for now this switches to movement mode, // in the future this should be trigged by a button in the UI or a keypress or something explicit // not just by click a character should it prompt a move... this.selectedCharacter = character; foreach (var tile in character.move_range) { tile.setWalkableForSelectedCharacter(select); this.mode = UI_Mode.player_unit_turn_during_action; this.action = UI_Action.move; } } } }
/// <summary> /// Adds a character to the campaign. /// </summary> /// <param name="id">The character ID.</param> /// <param name="character">The character.</param> protected void AddCharacter(string id, Character character) { this.characters.Add(id, character); }
public Bump(Character character) { strengthMean += BumpAttackAmount + (character.Level * LevelBonus); }
private void SetProfession(Character gnomad, String professionTitle) { var professions = GnomanEmpire.Instance.Fortress.Professions; var matchingProfession = professions.SingleOrDefault(obj => obj.Title == professionTitle); if (matchingProfession != null) { gnomad.Mind.Profession = matchingProfession; } }
public static GnomeBodyPartStatus[] GetBodyStatus(Character gameGnome) { var statuses = gameGnome.Body.BodySections.Select(bodySection => new GnomeBodyPartStatus(bodySection)).ToArray(); return statuses; }
public Punch(Character character) { strengthMean += PunchAttackAmount + (character.Level * LevelBonus); }
public void drawCharacter(Character character) { Canvas.SetLeft(character.display, character.positionX); Canvas.SetTop(character.display, character.positionY); GameArea.Children.Add(character.display); }
public GnomeSkill(Character gameGnome, SkillDef skill) { Name = skill.Name; Skill = gameGnome.SkillLevel(skill.ID); }
public GnomeAccess(Character gnome) { Gnome = gnome; }
public Gnome(Character gnome, int level, int row, int column, int mapCellPosition, int realIndex) { this.name = gnome.Name(); this.id = realIndex; this.level = level; this.row = row; this.column = column; this.position = mapCellPosition; this.profession = gnome.Mind.Profession; this.mining = gnome.SkillLevel(CharacterSkillType.Mining); foreach (var skill in SkillDef.AllLaborSkills()) this.laborSkills.Add(new SkillEntry(skill, gnome.SkillLevel(skill), gnome.Mind.IsSkillAllowed(skill))); foreach (var skill in SkillDef.AllCombatSkills()) this.combatSkills.Add(new SkillEntry(skill, gnome.SkillLevel(skill), gnome.Mind.IsSkillAllowed(skill))); foreach (var attribute in Enum.GetValues(typeof(CharacterAttributeType))) this.attributes.Add(new AttributeEntry((CharacterAttributeType)attribute, gnome.AttributeLevel((CharacterAttributeType)attribute))); }
private Dictionary<String, Int32> GetBestProfessions(Character gnome) { var professionSkills = GetSkillsByProfession(); Dictionary<String, Int32> professionScores = new Dictionary<String, Int32>(); foreach (var professionSkill in professionSkills) { var profession = professionSkill.Key; var skills = professionSkill.Value; Int32 score = 0; Int32 skillCount = skills.Count; var skillWeights = GetRatios(skillCount); for (Int32 i = 0; i < skillCount; i++) { // Professions consist of multiple jobs. // The other of the jobs within the profession is used when determining the next job a Gnome will perform. // Note: All tasks must be completed for all higher jobs before a gnome will queue a task in a lower priority job // As a result, we should weight each gnome's skills based on the likelihood of them queuing for those tasks in a given job. Int32 rawSkill = gnome.SkillLevel(skills[i]); Double weightedSkill = rawSkill * skillWeights[i]; Int32 weightedRoundedSkill = (Int32)Math.Round(weightedSkill, 0); score += weightedRoundedSkill; } professionScores.Add(profession, score); } return professionScores.OrderByDescending(obj => obj.Value).ToDictionary(obj => obj.Key, obj => obj.Value); }
/// <summary> /// Remove attack targer Game.Military.RemoveAttackTarget is called /// </summary> public static void RemoveAttackTarget(Game.Military m, Character c) { military.RemoveAttackTarget(c); }
/// <summary> /// Override Game.Military.FindAttackTarget /// </summary> public static Character FindAttackTarget(Game.Military m, Character c) { return military.FindAttackTarget(c); }
public EnemyRow(Character character) : base(character) { Name = character.NameAndTitle(); }
public Squash(Character character) { strengthMean += SquashAttackAmount + (character.Level * LevelBonus); }
/// <summary> /// Moves a character to another room. If the character is the palyer this will also change /// the currently active room of the campaign. /// </summary> /// <param name="character">The character object.</param> /// <param name="room">The room ID.</param> public void ChangeRoom(Character character, string room) { foreach (KeyValuePair<string, Room> currentRoom in this.rooms) { if (currentRoom.Value.Characters.Contains(character)) { currentRoom.Value.Characters.Remove(character); } } this.rooms[room].Characters.Add(character); if (!character.IsPlayer) { return; } this.CurrentRoom = this.rooms[room]; }