Esempio n. 1
0
    internal void ApplyMaterials(CreatureRaw race, MaterialPropertyBlock propertyBlock)
    {
        if (!gotShaderIds)
        {
            GetShaderIDs();
        }
        var renderer        = GetComponentInChildren <MeshRenderer>();
        var skinnedRenderer = GetComponentInChildren <SkinnedMeshRenderer>();

        if (renderer != null || skinnedRenderer != null)
        {
            var tissue     = race.tissues[layerRaw.tissue_id];
            var color      = ContentLoader.GetColor(tissue.material);
            var index      = ContentLoader.GetPatternIndex(tissue.material);
            var shapeIndex = ContentLoader.GetShapeIndex(tissue.material);
            propertyBlock.SetColor(_MatColorProperty, color);
            propertyBlock.SetColor(_Color1Property, color);
            propertyBlock.SetColor(_Color2Property, color);
            propertyBlock.SetColor(_Color3Property, color);
            propertyBlock.SetInt(_MatIndexProperty, index);
            propertyBlock.SetInt(_ShapeIndexProperty, shapeIndex);
            if (renderer != null)
            {
                renderer.SetPropertyBlock(propertyBlock);
            }
            if (skinnedRenderer != null)
            {
                skinnedRenderer.SetPropertyBlock(propertyBlock);
            }
        }
    }
Esempio n. 2
0
    static BodyDefinition GetBodyDefinition(CreatureBody.BodyCategory category, CreatureRaw race, CasteRaw caste)
    {
        Gender gender = Gender.Neuter;

        if (caste != null)
        {
            gender = (Gender)caste.gender;
        }
        BodyDefinition body = null;

        body = GetBodyDefinition(race, caste);
        if (body == null)
        {
            body = GetBodyDefinition(race);
        }
        if (body == null)
        {
            body = GetBodyDefinition(category, gender);
        }
        if (body == null)
        {
            body = GetBodyDefinition(category, Gender.Neuter);
        }
        return(body);
    }
Esempio n. 3
0
    public static BodyPartModel GetPart(CreatureBody.BodyCategory category, CreatureRaw race, CasteRaw caste, BodyPartRaw part)
    {
        if (categoryParts == null)
        {
            LoadDefaultBodyParts();
        }

        BodyPartModel partModel = null;
        var           bodyDef   = GetBodyDefinition(race, caste);

        if (bodyDef != null)
        {
            partModel = bodyDef.GetPart(part);
        }
        if (partModel != null)
        {
            return(partModel);
        }
        bodyDef = GetBodyDefinition(race);
        if (bodyDef != null)
        {
            partModel = bodyDef.GetPart(part);
        }
        if (partModel != null)
        {
            return(partModel);
        }
        bodyDef = GetBodyDefinition(category);
        if (bodyDef != null)
        {
            partModel = bodyDef.GetPart(part);
        }
        return(partModel);
    }
Esempio n. 4
0
 static BodyDefinition GetBodyDefinition(CreatureRaw race)
 {
     if (!raceParts.ContainsKey(race.creature_id))
     {
         raceParts[race.creature_id] = Resources.Load <BodyDefinition>("BodyDefinitions/" + race.creature_id + "/Default");
     }
     return(raceParts[race.creature_id]);
 }
 static BodyDefinition GetBodyDefinition(CreatureRaw race)
 {
     if (!raceParts.ContainsKey(GetCorrectedCreatureID(race)) || !Application.isPlaying)
     {
         raceParts[GetCorrectedCreatureID(race)] = Resources.Load <BodyDefinition>("BodyDefinitions/" + GetCorrectedCreatureID(race) + "/Default");
     }
     return(raceParts[GetCorrectedCreatureID(race)]);
 }
Esempio n. 6
0
 bool FitsFilter(CreatureRaw creature)
 {
     if (!string.IsNullOrEmpty(filter) && (filterName || filterDescription || filterToken || filterParts))
     {
         bool matched = false;
         if (filterToken && creature.creature_id.ToUpper().Contains(filter.ToUpper()))
         {
             matched = true;
         }
         if (filterName && creature.name[0].ToUpper().Contains(filter.ToUpper()))
         {
             matched = true;
         }
         if (!matched)
         {
             foreach (var caste in creature.caste)
             {
                 if (filterName && caste.caste_name[0].ToUpper().Contains(filter.ToUpper()))
                 {
                     matched = true;
                 }
                 if (filterDescription && caste.description.ToUpper().Contains(filter.ToUpper()))
                 {
                     matched = true;
                 }
                 if (filterParts)
                 {
                     foreach (var part in caste.body_parts)
                     {
                         if (part.category.ToUpper().Contains(filter.ToUpper()))
                         {
                             matched = true;
                             break;
                         }
                     }
                 }
             }
         }
         if (!matched)
         {
             return(false);
         }
     }
     if (bodyCategoryFilter != CreatureBody.BodyCategory.None)
     {
         foreach (var caste in creature.caste)
         {
             if (bodyCategoryFilter == CreatureBody.FindBodyCategory(caste))
             {
                 return(true);
             }
         }
         return(false);
     }
     return(true);
 }
Esempio n. 7
0
    public static Vector3 GetBodyScale(CreatureBody.BodyCategory category, CreatureRaw race, CasteRaw caste)
    {
        var body = GetBodyDefinition(category, race, caste);

        if (body == null)
        {
            return(Vector3.one);
        }
        return(body.bodyScale);
    }
Esempio n. 8
0
    public static BodyPartModel GetPart(CreatureBody.BodyCategory category, CreatureRaw race, CasteRaw caste, BodyPartRaw part)
    {
        Gender gender = Gender.Neuter;

        if (caste != null)
        {
            gender = (Gender)caste.gender;
        }
        BodyPartModel partModel = null;
        var           bodyDef   = GetBodyDefinition(race, caste);

        if (bodyDef != null)
        {
            partModel = bodyDef.GetPart(part);
        }
        if (partModel != null)
        {
            return(partModel);
        }
        bodyDef = GetBodyDefinition(race);
        if (bodyDef != null)
        {
            partModel = bodyDef.GetPart(part);
        }
        if (partModel != null)
        {
            return(partModel);
        }
        bodyDef = GetBodyDefinition(category, gender);
        if (bodyDef != null)
        {
            partModel = bodyDef.GetPart(part);
        }
        if (partModel != null)
        {
            return(partModel);
        }
        bodyDef = GetBodyDefinition(category, Gender.Neuter);
        if (bodyDef != null)
        {
            partModel = bodyDef.GetPart(part);
        }
        if (partModel != null)
        {
            return(partModel);
        }
        bodyDef = GetBodyDefinition(CreatureBody.BodyCategory.None);
        if (bodyDef != null)
        {
            partModel = bodyDef.GetPart(part);
        }
        return(partModel);
    }
Esempio n. 9
0
 static BodyDefinition GetBodyDefinition(CreatureRaw race, CasteRaw caste)
 {
     if (!casteParts.ContainsKey(race.creature_id))
     {
         casteParts[race.creature_id] = new Dictionary <string, BodyDefinition>();
     }
     if (!casteParts[race.creature_id].ContainsKey(caste.caste_id))
     {
         casteParts[race.creature_id][caste.caste_id] = Resources.Load <BodyDefinition>("BodyDefinitions/" + race.creature_id + "/" + caste.caste_id);
     }
     return(casteParts[race.creature_id][caste.caste_id]);
 }
Esempio n. 10
0
 static BodyDefinition GetBodyDefinition(CreatureRaw race, CasteRaw caste)
 {
     if (!casteParts.ContainsKey(GetCorrectedCreatureID(race, caste)))
     {
         casteParts[GetCorrectedCreatureID(race)] = new Dictionary <string, BodyDefinition>();
     }
     if (!casteParts[GetCorrectedCreatureID(race)].ContainsKey(caste.caste_id) || !Application.isPlaying)
     {
         casteParts[GetCorrectedCreatureID(race)][caste.caste_id] = Resources.Load <BodyDefinition>("BodyDefinitions/" + GetCorrectedCreatureID(race) + "/" + caste.caste_id);
     }
     return(casteParts[GetCorrectedCreatureID(race)][caste.caste_id]);
 }
Esempio n. 11
0
    internal void UpdateCreature(UnitDefinition unit)
    {
        if (!inited)
        {
            InitProperties();
        }
        if (!localInited)
        {
            InitLocal();
        }
        this.unit = unit;
        if (DFConnection.Instance.CreatureRaws != null)
        {
            creatureRaw = DFConnection.Instance.CreatureRaws[unit.race.mat_type];
        }
        else
        {
            return; //can't work without raws
        }
        casteRaw = creatureRaw.caste[unit.race.mat_index];

        if (unit.profession_color != null)
        {
            professionColor = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
        }
        else
        {
            professionColor = new Color(1, 1, 1, 0.5f);
        }


        var layers = LayeredSpriteManager.Instance.GetCreatureSprite(unit);

        //no size info indicates that the unit was only given the most basic data.
        if (layers != null && unit.size_info != null)
        {
            layeredSprite.SpriteCollection = layers;
            layeredSprite.enabled          = true;
            legacySprite.gameObject.SetActive(false);
            layeredSprite.UpdateLayers(unit, creatureRaw, casteRaw);
        }
        else
        {
            layeredSprite.SpriteCollection = null;
            layeredSprite.enabled          = false;
            legacySprite.gameObject.SetActive(true);
            UpdateTileCreature();
        }
    }
Esempio n. 12
0
    static BodyDefinition GetBodyDefinition(CreatureBody.BodyCategory category, CreatureRaw race, CasteRaw caste)
    {
        BodyDefinition body = null;

        body = GetBodyDefinition(race, caste);
        if (body == null)
        {
            body = GetBodyDefinition(race);
        }
        if (body == null)
        {
            body = GetBodyDefinition(category);
        }
        return(body);
    }
Esempio n. 13
0
    internal void UpdateCreature(UnitDefinition unit)
    {
        if (!inited)
        {
            InitProperties();
        }
        if (!localInited)
        {
            InitLocal();
        }
        this.unit = unit;
        if (DFConnection.Instance.CreatureRaws != null)
        {
            creatureRaw = DFConnection.Instance.CreatureRaws[unit.race.mat_type];
        }
        else
        {
            return; //can't work without raws
        }
        casteRaw = creatureRaw.caste[unit.race.mat_index];

        if (unit.profession_color != null)
        {
            professionColor = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
        }
        else
        {
            professionColor = new Color(1, 1, 1, 0.5f);
        }


        var layers = LayeredSpriteManager.Instance.GetCreatureSprite(unit);

        if (layers != null)
        {
            layeredSprite.SpriteCollection = layers;
            layeredSprite.enabled          = true;
            legacySprite.enabled           = false;
            layeredSprite.UpdateLayers(unit, creatureRaw, casteRaw);
        }
        else
        {
            layeredSprite.SpriteCollection = layers;
            layeredSprite.enabled          = false;
            legacySprite.enabled           = true;
            UpdateTileCreature();
        }
    }
Esempio n. 14
0
 bool FitsFilter(CreatureRaw creature)
 {
     if (!string.IsNullOrEmpty(filter) && !creature.creature_id.ToUpper().Contains(filter.ToUpper()))
     {
         return(false);
     }
     if (bodyCategoryFilter != CreatureBody.BodyCategory.None)
     {
         foreach (var caste in creature.caste)
         {
             if (bodyCategoryFilter == CreatureBody.FindBodyCategory(caste))
             {
                 return(true);
             }
         }
         return(false);
     }
     return(true);
 }
Esempio n. 15
0
 public void ApplyMaterials(CreatureRaw race, MaterialPropertyBlock propertyBlock)
 {
     if (!inited)
     {
         Init();
     }
     if (renderer != null)
     {
         var tissue     = race.tissues[layerRaw.tissue_id];
         var color      = ContentLoader.GetColor(tissue.material);
         var index      = ContentLoader.GetPatternIndex(tissue.material);
         var shapeIndex = ContentLoader.GetShapeIndex(tissue.material);
         propertyBlock.SetColor(_MatColorProperty, color);
         propertyBlock.SetColor(_Color1Property, color);
         propertyBlock.SetColor(_Color2Property, color);
         propertyBlock.SetColor(_Color3Property, color);
         propertyBlock.SetInt(_MatIndexProperty, index);
         propertyBlock.SetInt(_ShapeIndexProperty, shapeIndex);
         renderer.SetPropertyBlock(propertyBlock);
     }
 }
Esempio n. 16
0
    public static string GetCorrectedCreatureID(CreatureRaw race, CasteRaw caste = null)
    {
        if (race.flags.Count == 0)
        {
            return(race.creature_id);
        }
        if (!race.flags[(int)CreatureRawFlags.RawFlags.GENERATED])
        {
            return(race.creature_id);
        }
        if (usableRaceNames.ContainsKey(race.index))
        {
            return(usableRaceNames[race.index]);
        }
        if (caste == null)
        {
            caste = race.caste[0];
        }
        var descParts = caste.description.Split('.');

        foreach (var type in generatedCreatureTypes)
        {
            if (Regex.IsMatch(descParts[0], @"\b" + type + @"\b", RegexOptions.IgnoreCase))
            {
                if (Regex.IsMatch(descParts[0], @"\bHUMANOID\b", RegexOptions.IgnoreCase))
                {
                    return(usableRaceNames[race.index] = type + "_MAN");
                }
                else
                {
                    return(usableRaceNames[race.index] = type);
                }
            }
        }
        if (Regex.IsMatch(descParts[0], @"\bHUMANOID\b", RegexOptions.IgnoreCase))
        {
            return(usableRaceNames[race.index] = "HUMANOID");
        }
        return(usableRaceNames[race.index] = race.creature_id);
    }
Esempio n. 17
0
    public void UpdateUnit(UnitDefinition unit)
    {
        bool needsRegen = false;

        if ((MatPairStruct)this.unit.race != unit.race)
        {
            race       = CreatureRaws.Instance[unit.race.mat_type];
            caste      = race.caste[unit.race.mat_index];
            needsRegen = true;
        }
        if (oldWounds != null || unit.wounds != null)
        {
            if (oldWounds == null && unit.wounds != null)
            {
                needsRegen = true;
            }
            else if (oldWounds != null && unit.wounds == null)
            {
                needsRegen = true;
            }
            else if (oldWounds.Count != unit.wounds.Count)
            {
                needsRegen = true;
            }
            else
            {
                for (int i = 0; i < unit.wounds.Count; i++)
                {
                    if (oldWounds[i].severed_part != unit.wounds[i].severed_part)
                    {
                        needsRegen = true;
                        break;
                    }
                    if (oldWounds[i].parts.Count != unit.wounds[i].parts.Count)
                    {
                        needsRegen = true;
                        break;
                    }
                }
            }
        }
        oldWounds = unit.wounds;
        this.unit = unit;
        if (needsRegen || oldChibiSize != GameSettings.Instance.units.chibiness || oldScaleUnits != GameSettings.Instance.units.scaleUnits)
        {
            oldScaleUnits = GameSettings.Instance.units.scaleUnits;
            oldChibiSize  = GameSettings.Instance.units.chibiness;
            MakeBody();
        }

        if (((UnitFlags1)unit.flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground)
        {
            if (!onGround)
            {
                rootPart.transform.localRotation = Quaternion.Euler(90, 0, 0);
                rootPart.transform.localPosition = new Vector3(0, bounds.max.z, 0);
                onGround = true;
            }
        }
        else
        {
            if (onGround)
            {
                rootPart.transform.localRotation = Quaternion.identity;
                rootPart.transform.localPosition = new Vector3(0, -bounds.min.y, 0);
                onGround = false;
            }
        }
        if (unit.facing != null && GameMap.DFtoUnityDirection(unit.facing).sqrMagnitude > 0 && unit.rider_id < 0)
        {
            transform.rotation = Quaternion.LookRotation(GameMap.DFtoUnityDirection(unit.facing));
        }
        else if (unit.rider_id >= 0)
        {
            transform.rotation = Quaternion.identity;
        }

        if (InventoryChanged(unit.inventory))
        {
            foreach (var part in spawnedParts)
            {
                part.Value.inventory.Clear();
            }
            //Here we add pants first before shirts because otherwise the layering looks bad.
            foreach (var item in unit.inventory)
            {
                if (!ClothingTexture.GetTexture(item.item.type).isDress)
                {
                    AddInventoryItem(item);
                }
            }
            foreach (var item in unit.inventory)
            {
                if (ClothingTexture.GetTexture(item.item.type).isDress)
                {
                    AddInventoryItem(item);
                }
            }
            foreach (var part in spawnedParts)
            {
                part.Value.UpdateItems(unit);
            }
        }
    }
Esempio n. 18
0
    internal void UpdateCreature(UnitDefinition unit)
    {
        if (!inited)
        {
            InitProperties();
        }
        if (!localInited)
        {
            InitLocal();
        }
        this.unit = unit;
        if (DFConnection.Instance.CreatureRaws != null)
        {
            creatureRaw = DFConnection.Instance.CreatureRaws[unit.race.mat_type];
        }
        else
        {
            return; //can't work without raws
        }
        casteRaw = creatureRaw.caste[unit.race.mat_index];

        if (unit.profession_color != null)
        {
            professionColor = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
        }
        else
        {
            professionColor = new Color(1, 1, 1, 0.5f);
        }


        var layers = LayeredSpriteManager.Instance.GetCreatureSprite(unit);

        //no size info indicates that the unit was only given the most basic data.
        if (layers != null && unit.size_info != null)
        {
            layeredSprite.SpriteCollection = layers;
            layeredSprite.enabled          = true;
            legacySprite.gameObject.SetActive(false);
            layeredSprite.UpdateLayers(unit, creatureRaw, casteRaw);
            var group = GetComponentInChildren <LODGroup>();
            if (group != null)
            {
                var lods = new LOD[1];
                lods[0] = new LOD(0.05f, GetComponentsInChildren <SpriteRenderer>());
                group.SetLODs(lods);
                group.RecalculateBounds();
            }
        }
        else
        {
            layeredSprite.SpriteCollection = null;
            layeredSprite.enabled          = false;
            legacySprite.gameObject.SetActive(true);
            UpdateTileCreature();
            var group = GetComponentInChildren <LODGroup>();
            if (group != null)
            {
                var lods = new LOD[1];
                lods[0] = new LOD(0.05f, GetComponentsInChildren <MeshRenderer>());
                group.SetLODs(lods);
                group.RecalculateBounds();
            }
        }
    }
Esempio n. 19
0
    void UpdateCreatures()
    {
        unitList = DFConnection.Instance.PopUnitListUpdate();
        if (unitList == null)
        {
            return;
        }
        foreach (var unit in unitList.creature_list)
        {
            if (creatureList == null)
            {
                creatureList = new Dictionary <int, AtlasSprite>();
            }
            UnitFlags1 flags1 = (UnitFlags1)unit.flags1;
            //UnitFlags2 flags2 = (UnitFlags2)unit.flags2;
            //UnitFlags3 flags3 = (UnitFlags3)unit.flags3;
            if (((flags1 & UnitFlags1.dead) == UnitFlags1.dead) ||
                ((flags1 & UnitFlags1.left) == UnitFlags1.left))
            {
                if (creatureList.ContainsKey(unit.id))
                {
                    Destroy(creatureList[unit.id]);
                    creatureList.Remove(unit.id);
                }
            }
            else
            {
                CreatureRaw creatureRaw = null;
                if (DFConnection.Instance.NetCreatureRawList != null)
                {
                    creatureRaw = DFConnection.Instance.NetCreatureRawList.creature_raws[unit.race.mat_type];
                }

                if (!creatureList.ContainsKey(unit.id))
                {
                    creatureList[unit.id] = Instantiate(creatureTemplate);
                    creatureList[unit.id].transform.parent = gameObject.transform;
                    creatureList[unit.id].ClearMesh();

                    Color color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 1);

                    if (creatureRaw != null)
                    {
                        creatureList[unit.id].AddTile(creatureRaw.creature_tile, color);
                    }
                }
                creatureList[unit.id].gameObject.SetActive(unit.pos_z <PosZ && unit.pos_z> (PosZ - cameraViewDist));
                if (creatureList[unit.id].gameObject.activeSelf) //Only update stuff if it's actually visible.
                {
                    Vector3 position = DFtoUnityCoord(unit.pos_x, unit.pos_y, unit.pos_z);
                    if ((flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground)
                    {
                        creatureList[unit.id].transform.position   = position + new Vector3(0, 0.51f, 0);
                        creatureList[unit.id].cameraFacing.enabled = false;
                        creatureList[unit.id].transform.rotation   = Quaternion.Euler(90, 0, 0);
                    }
                    else
                    {
                        creatureList[unit.id].transform.position   = position + new Vector3(0, 1.5f, 0);
                        creatureList[unit.id].cameraFacing.enabled = true;
                    }
                    creatureList[unit.id].SetColor(0, new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 1));
                    if (creatureRaw != null)
                    {
                        if (unit.is_soldier)
                        {
                            creatureList[unit.id].SetTile(0, creatureRaw.creature_soldier_tile);
                        }
                        else
                        {
                            creatureList[unit.id].SetTile(0, creatureRaw.creature_tile);
                        }
                    }
                }
            }
        }
    }
Esempio n. 20
0
    void ShowCursorInfo()
    {
        cursorProperties.text  = "";
        cursorProperties.text += "Cursor: ";
        cursorProperties.text += cursX + ",";
        cursorProperties.text += cursY + ",";
        cursorProperties.text += cursZ + "\n";
        var maybeTile = MapDataStore.Main[cursX, cursY, cursZ];

        if (maybeTile != null)
        {
            var tile = maybeTile.Value;
            cursorProperties.text += "Tiletype:\n";
            var tiletype = DFConnection.Instance.NetTiletypeList.tiletype_list
                           [tile.tileType];
            cursorProperties.text += tiletype.name + "\n";
            cursorProperties.text +=
                tiletype.shape + ":" +
                tiletype.special + ":" +
                tiletype.material + ":" +
                tiletype.variant + ":" +
                tiletype.direction + "\n";
            var mat = tile.material;
            cursorProperties.text += "Material: ";
            cursorProperties.text += mat.mat_type + ",";
            cursorProperties.text += mat.mat_index + "\n";

            if (materials.ContainsKey(mat))
            {
                cursorProperties.text += "Material Name: ";
                cursorProperties.text += materials[mat].id + "\n";
            }
            else
            {
                cursorProperties.text += "Unknown Material\n";
            }

            cursorProperties.text += "\n";

            var basemat = tile.base_material;
            cursorProperties.text += "Base Material: ";
            cursorProperties.text += basemat.mat_type + ",";
            cursorProperties.text += basemat.mat_index + "\n";

            if (materials.ContainsKey(basemat))
            {
                cursorProperties.text += "Base Material Name: ";
                cursorProperties.text += materials[basemat].id + "\n";
            }
            else
            {
                cursorProperties.text += "Unknown Base Material\n";
            }

            cursorProperties.text += "\n";

            var layermat = tile.layer_material;
            cursorProperties.text += "Layer Material: ";
            cursorProperties.text += layermat.mat_type + ",";
            cursorProperties.text += layermat.mat_index + "\n";

            if (materials.ContainsKey(layermat))
            {
                cursorProperties.text += "Layer Material Name: ";
                cursorProperties.text += materials[layermat].id + "\n";
            }
            else
            {
                cursorProperties.text += "Unknown Layer Material\n";
            }

            cursorProperties.text += "\n";

            var veinmat = tile.vein_material;
            cursorProperties.text += "Vein Material: ";
            cursorProperties.text += veinmat.mat_type + ",";
            cursorProperties.text += veinmat.mat_index + "\n";

            if (materials.ContainsKey(veinmat))
            {
                cursorProperties.text += "Vein Material Name: ";
                cursorProperties.text += materials[veinmat].id + "\n";
            }
            else
            {
                cursorProperties.text += "Unknown Vein Material\n";
            }

            cursorProperties.text += "\n";

            var cons = tile.construction_item;
            cursorProperties.text += "Construction Item: ";
            cursorProperties.text += cons.mat_type + ",";
            cursorProperties.text += cons.mat_index + "\n";

            if (materials.ContainsKey(cons))
            {
                cursorProperties.text += "Construction Item Name: ";
                cursorProperties.text += items[cons].id + "\n";
            }
            else
            {
                cursorProperties.text += "Unknown Construction Item\n";
            }
        }

        if (unitList != null)
        {
            foreach (UnitDefinition unit in unitList.creature_list)
            {
                UnitFlags1 flags1 = (UnitFlags1)unit.flags1;
                UnitFlags2 flags2 = (UnitFlags2)unit.flags2;
                UnitFlags3 flags3 = (UnitFlags3)unit.flags3;

                if (((flags1 & UnitFlags1.dead) == UnitFlags1.dead) ||
                    ((flags1 & UnitFlags1.left) == UnitFlags1.left))
                {
                    continue;
                }
                if (unit.pos_x != cursX || unit.pos_y != cursY || unit.pos_z != cursZ)
                {
                    continue;
                }

                CreatureRaw creatureRaw = null;
                if (DFConnection.Instance.NetCreatureRawList != null)
                {
                    creatureRaw = DFConnection.Instance.NetCreatureRawList.creature_raws[unit.race.mat_type];
                }

                if (creatureRaw != null)
                {
                    cursorProperties.text += "Unit:   \n";

                    cursorProperties.text += "Race: ";
                    cursorProperties.text += creatureRaw.creature_id + ":";
                    cursorProperties.text += creatureRaw.caste[unit.race.mat_index].caste_id;
                    cursorProperties.text += "\n";

                    cursorProperties.text += flags1 + "\n";
                    cursorProperties.text += flags2 + "\n";
                    cursorProperties.text += flags3 + "\n";
                }
                break;
            }
        }
    }
Esempio n. 21
0
    internal void UpdateLayers(UnitDefinition unit, CreatureRaw creatureRaw, CasteRaw casteRaw)
    {
        for (int i = 0; i < spriteList.Count; i++)
        {
            var spriteLayerDef = SpriteCollection.spriteLayers[i];
            var sprite         = spriteList[i];
            switch (spriteLayerDef.spriteSource)
            {
            case CreatureSpriteLayer.SpriteSource.Static:
                sprite.enabled = true;
                switch (spriteLayerDef.colorSource)
                {
                case CreatureSpriteLayer.ColorSource.Fixed:
                    sprite.color = spriteLayerDef.color;
                    break;

                case CreatureSpriteLayer.ColorSource.Job:
                    sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
                    break;

                default:
                    sprite.color = new Color32(128, 128, 128, 128);
                    break;
                }
                break;

            case CreatureSpriteLayer.SpriteSource.Bodypart:
                sprite.enabled = true;
                switch (spriteLayerDef.colorSource)
                {
                case CreatureSpriteLayer.ColorSource.Fixed:
                    sprite.color = spriteLayerDef.color;
                    break;

                case CreatureSpriteLayer.ColorSource.Material:
                    ColorDefinition unitColor     = new ColorDefinition();
                    int             colorModIndex = casteRaw.color_modifiers.FindIndex(x => x.part == spriteLayerDef.token && x.start_date == 0);
                    if (colorModIndex >= 0)
                    {
                        unitColor    = casteRaw.color_modifiers[colorModIndex].patterns[unit.appearance.colors[colorModIndex]].colors[spriteLayerDef.patternIndex];
                        sprite.color = new Color32((byte)unitColor.red, (byte)unitColor.green, (byte)unitColor.blue, 128);
                    }
                    else
                    {
                        int tissueIndex = creatureRaw.tissues.FindIndex(x => x.name == spriteLayerDef.token);
                        if (tissueIndex >= 0)
                        {
                            sprite.color = ContentLoader.GetColor(creatureRaw.tissues[tissueIndex].material);
                        }
                        else
                        {
                            sprite.enabled = false;
                        }
                        break;
                    }
                    break;

                case CreatureSpriteLayer.ColorSource.Job:
                    sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
                    break;

                case CreatureSpriteLayer.ColorSource.BodyPart:
                    var part = casteRaw.body_parts.Find(x => x.token == spriteLayerDef.token);
                    if (part == null)
                    {
                        sprite.enabled = false;
                        break;
                    }
                    sprite.color = ContentLoader.GetColor(creatureRaw.tissues[part.layers[0].tissue_id].material);
                    break;

                default:
                    sprite.color = new Color32(128, 128, 128, 128);
                    break;
                }
                switch (spriteLayerDef.hairType)
                {
                case CreatureSpriteLayer.HairType.Hair:
                    if (unit.inventory.FindIndex(x => x.item.type.mat_type == (int)item_type.HELM) >= 0)
                    {
                        sprite.enabled = false;
                        break;
                    }
                    if (unit.appearance == null || unit.appearance.hair == null)
                    {
                        sprite.enabled = spriteLayerDef.hairStyle == HairStyle.UNKEMPT;
                    }
                    else
                    {
                        sprite.enabled = (spriteLayerDef.hairStyle == unit.appearance.hair.style) &&
                                         (spriteLayerDef.hairMin <= unit.appearance.hair.length) &&
                                         ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.hair.length));
                    }
                    break;

                case CreatureSpriteLayer.HairType.Beard:
                    if (unit.appearance == null || unit.appearance.beard == null)
                    {
                        sprite.enabled = spriteLayerDef.hairStyle == HairStyle.UNKEMPT;
                    }
                    else
                    {
                        sprite.enabled = (spriteLayerDef.hairStyle == unit.appearance.beard.style) &&
                                         (spriteLayerDef.hairMin <= unit.appearance.beard.length) &&
                                         ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.beard.length));
                    }
                    break;

                case CreatureSpriteLayer.HairType.Moustache:
                    if (unit.appearance == null || unit.appearance.moustache == null)
                    {
                        sprite.enabled = spriteLayerDef.hairStyle == HairStyle.UNKEMPT;
                    }
                    else
                    {
                        sprite.enabled = (spriteLayerDef.hairStyle == unit.appearance.moustache.style) &&
                                         (spriteLayerDef.hairMin <= unit.appearance.moustache.length) &&
                                         ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.moustache.length));
                    }
                    break;

                case CreatureSpriteLayer.HairType.Sideburns:
                    if (unit.appearance == null || unit.appearance.sideburns == null)
                    {
                        sprite.enabled = spriteLayerDef.hairStyle == HairStyle.UNKEMPT;
                    }
                    else
                    {
                        sprite.enabled = (spriteLayerDef.hairStyle == unit.appearance.sideburns.style) &&
                                         (spriteLayerDef.hairMin <= unit.appearance.sideburns.length) &&
                                         ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.sideburns.length));
                    }
                    break;

                default:
                    sprite.enabled = true;
                    break;
                }
                break;

            case CreatureSpriteLayer.SpriteSource.Equipment:
                int inventoryIndex = unit.inventory.FindIndex(
                    x =>
                    (x.mode == InventoryMode.Weapon || x.mode == InventoryMode.Worn) &&
                    spriteLayerDef.token == GameMap.items[x.item.type].id
                    );
                if (inventoryIndex < 0)
                {
                    sprite.enabled = false;
                    break;
                }
                else
                {
                    sprite.enabled = true;
                }
                var item = unit.inventory[inventoryIndex].item;

                switch (spriteLayerDef.colorSource)
                {
                case CreatureSpriteLayer.ColorSource.Fixed:
                    sprite.color = spriteLayerDef.color;
                    break;

                case CreatureSpriteLayer.ColorSource.Material:
                    sprite.color = ContentLoader.GetColor(item);
                    break;

                case CreatureSpriteLayer.ColorSource.Job:
                    sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
                    break;

                default:
                    sprite.color = new Color32(128, 128, 128, 128);
                    break;
                }
                break;

            default:
                sprite.enabled = false;
                break;
            }
            if (sprite.color.a < 0.5f)
            {
                sprite.sharedMaterial = SpriteMatTrans;
            }
            else
            {
                sprite.sharedMaterial = SpriteMat;
            }
        }
    }