Beispiel #1
0
        public static GeometricObjectElementCollideAlignedBoxes Read(Reader reader, Pointer offset, GeometricObjectCollide geo)
        {
            MapLoader l = MapLoader.Loader;
            GeometricObjectElementCollideAlignedBoxes s = new GeometricObjectElementCollideAlignedBoxes(offset, geo);

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                s.off_boxes = Pointer.Read(reader);
                s.num_boxes = reader.ReadUInt16();
                reader.ReadInt16(); // -1
            }
            else
            {
                s.num_boxes = (ushort)reader.ReadUInt32();
                s.off_boxes = Pointer.Read(reader);
            }

            if (s.off_boxes != null)
            {
                Pointer off_current = Pointer.Goto(ref reader, s.off_boxes);
                s.boxes = new IndexedAlignedBox[s.num_boxes];
                for (uint i = 0; i < s.num_boxes; i++)
                {
                    s.boxes[i]              = new IndexedAlignedBox();
                    s.boxes[i].minPoint     = reader.ReadUInt16();
                    s.boxes[i].maxPoint     = reader.ReadUInt16();
                    s.boxes[i].off_material = Pointer.Read(reader);
                    s.boxes[i].gameMaterial = GameMaterial.FromOffsetOrRead(s.boxes[i].off_material, reader);
                }
                Pointer.Goto(ref reader, off_current);
            }
            return(s);
        }
Beispiel #2
0
        public static void SetInitListForMaterial()
        {
            if (itemTable != null && itemTable.Count > 0)
            {
                if (!itemTable.ContainsKey(table_material))
                {
                    return;
                }
                Hashtable parentTable = (Hashtable)itemTable [table_material];

                foreach (string stringkey in parentTable.Keys)
                {
                    //把每一行抓出來
                    Hashtable    currenttable     = (Hashtable)parentTable[stringkey];
                    GameMaterial current_material = new GameMaterial();
                    current_material.itemkey               = stringkey;
                    current_material.rate                  = Utilities.LoadInt(currenttable[key_material_rate], 0);
                    current_material.droprate              = Utilities.LoadInt(currenttable[key_material_droprate], 0);
                    current_material.price_value           = Utilities.LoadInt(currenttable[key_value], 0);
                    current_material.en                    = Utilities.LoadString(currenttable[key_english], "");
                    current_material.tw                    = Utilities.LoadString(currenttable [key_chinese], "");
                    current_material.en_desc               = Utilities.LoadString(currenttable [key_english_desc], "");
                    current_material.tw_desc               = Utilities.LoadString(currenttable [key_chinese_desc], "");
                    current_material.thumbnailpicture_name = Utilities.LoadString(currenttable [key_material_thumbnailpicture], "");
                    Utilities.DebugLog("material now is " + stringkey);
                    materialinfo_list.Add(current_material);
                }
            }
        }
Beispiel #3
0
    /// <summary>
    /// Open item after research.
    /// Could be changed by children
    /// Here: setting production as tools wherever it used
    /// </summary>
    public override void OpenItem()
    {
        foreach (var eff in m_effects)
        {
            var products = Productions.GetProductions(eff.Value.m_name);
            foreach (GameAbstractItem prod in products)
            {
                if (prod.m_isItOpen > 0)
                {
                    GameMaterial mat          = (GameMaterial)prod;
                    bool         hasItTheSame = false;
                    foreach (var effect in mat.m_tools)
                    {
                        hasItTheSame |= (effect.m_toolLink.m_name == m_name && effect.m_name == eff.Value.m_name);
                    }

                    if (hasItTheSame)
                    {
                        continue;
                    }
                    else
                    {
                        ItemsEffect neff = new ItemsEffect(eff.Value);
                        neff.m_production = mat;
                        mat.m_tools.Add(neff);
                        ArrowScript asc = ArrowScript.NewArrowScript(neff.m_toolLink.m_thisObject, mat.m_thisObject);
                        asc.m_isItTool = true;
                        mat.m_thisObject.m_toolsTo.Add(asc);
                        m_thisObject.m_toolsFrom.Add(asc);
                    }
                }
            }
        }
        base.OpenItem();
    }
Beispiel #4
0
    /// <summary>
    /// Copy from loaded item.
    /// shouldn't copy non-serialized fields
    /// </summary>
    /// <param name="source"> source for copying </param>
    public override void Copy(AbstractObject itm)
    {
        base.Copy(itm);
        GameMaterial mat = (GameMaterial)itm;

        m_storageSize  = mat.m_storageSize;
        m_lastCount    = mat.m_lastCount;
        m_productQueue = mat.m_productQueue;
    }
Beispiel #5
0
    public void Initialize(GameMaterial owner, FlammableTypeSO flammableType)
    {
        _flammableType = flammableType;
        Owner          = owner;
        IOElements     = new float[5];
        _airMedium     = GameObject.Find("MediumAir").GetComponent <Medium>();

        for (int i = 0; i < 5; i++)
        {
            IOElements[i] = _flammableType.IO[i].ValuePerTick;
        }
    }
Beispiel #6
0
    public void Load()
    {
        Data mdl = DataManager.XMLUnmarshalling <Data>("Assets/Data/materialData.xml");

        materials = new GameMaterial[mdl.materials.Length];

        for (int i = 0; i < mdl.materials.Length; i++)
        {
            materials[i] = new GameMaterial();
            //materials[i].FromData(mdl.materials[i]);
        }

        ToUI();
    }
Beispiel #7
0
        public static ScriptNode Read(Reader reader, Pointer offset, Script script) {
            MapLoader l = MapLoader.Loader;
            ScriptNode sn = new ScriptNode(offset);

            sn.script = script;
            sn.param = reader.ReadUInt32();
            sn.param_ptr = Pointer.GetPointerAtOffset(offset); // if parameter is pointer
            if (Settings.s.platform == Settings.Platform.DC) reader.ReadUInt32();

            if (Settings.s.mode == Settings.Mode.Rayman3GC) {
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                sn.type = reader.ReadByte();

                reader.ReadByte();
                reader.ReadByte();
                sn.indent = reader.ReadByte();
                reader.ReadByte();
            } else {
                reader.ReadByte();
                reader.ReadByte();
                sn.indent = reader.ReadByte();
                sn.type = reader.ReadByte();
            }
            sn.nodeType = NodeType.Unknown;
            if (Settings.s.aiTypes != null) sn.nodeType = Settings.s.aiTypes.GetNodeType(sn.type);
			
            if (sn.param_ptr != null && sn.nodeType != NodeType.Unknown) {
				//l.print("ScriptNode " + offset + " - " + sn.nodeType + " (" + sn.type + ") - " + sn.param_ptr);
				if (sn.nodeType == NodeType.WayPointRef) {
					WayPoint waypoint = WayPoint.FromOffsetOrRead(sn.param_ptr, reader);
				} else if (sn.nodeType == NodeType.String) {
					Pointer.DoAt(ref reader, sn.param_ptr, () => {
						string str = reader.ReadNullDelimitedString();
						l.strings[sn.param_ptr] = str;
					});
				} else if (sn.nodeType == NodeType.ObjectTableRef) {
					// In R2 some objects have object tables that aren't listed normally, but are referenced through scripts.
				} else if (sn.nodeType == NodeType.Button) {
					EntryAction.FromOffsetOrRead(sn.param_ptr, reader);
				} else if (sn.nodeType == NodeType.GameMaterialRef) {
                    GameMaterial.FromOffsetOrRead(sn.param_ptr, reader);
                } else if (sn.nodeType == NodeType.VisualMaterial) {
                    VisualMaterial.FromOffsetOrRead(sn.param_ptr, reader);
                }
            }
            return sn;
        }
Beispiel #8
0
        public static GeometricObjectElementCollideSpheres Read(Reader reader, Pointer offset, GeometricObjectCollide geo)
        {
            MapLoader l = MapLoader.Loader;
            GeometricObjectElementCollideSpheres s = new GeometricObjectElementCollideSpheres(offset, geo);

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                s.off_spheres     = Pointer.Read(reader);
                s.num_spheres     = reader.ReadUInt16();
                s.ind_parallelBox = reader.ReadInt16(); // -1
            }
            else
            {
                s.num_spheres = (ushort)reader.ReadUInt32();
                s.off_spheres = Pointer.Read(reader);
            }

            if (s.off_spheres != null)
            {
                Pointer off_current = Pointer.Goto(ref reader, s.off_spheres);
                s.spheres = new IndexedSphere[s.num_spheres];
                for (uint i = 0; i < s.num_spheres; i++)
                {
                    s.spheres[i] = new IndexedSphere();
                    if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
                    {
                        s.spheres[i].debug_radiusAddress = Pointer.Current(reader);
                        s.spheres[i].radius       = reader.ReadSingle();
                        s.spheres[i].off_material = Pointer.Read(reader);
                        s.spheres[i].centerPoint  = reader.ReadUInt16();
                        reader.ReadUInt16();
                    }
                    else
                    {
                        s.spheres[i].centerPoint = reader.ReadUInt16();
                        reader.ReadUInt16();
                        s.spheres[i].debug_radiusAddress = Pointer.Current(reader);
                        s.spheres[i].radius       = reader.ReadSingle();
                        s.spheres[i].off_material = Pointer.Read(reader);
                    }
                    if (!geo.isBoundingVolume)
                    {
                        s.spheres[i].gameMaterial = GameMaterial.FromOffsetOrRead(s.spheres[i].off_material, reader);
                    }
                }
                Pointer.Goto(ref reader, off_current);
            }
            return(s);
        }
Beispiel #9
0
 /// <summary>
 /// Copy items effect from loaded save game to already exists effects
 /// </summary>
 /// <typeparam name="T"> Item. GameMaterial or child </typeparam>
 /// <param name="list"> Item's list for copying </param>
 void CopyTools <T>(List <T> list) where T : GameMaterial
 {
     foreach (GameMaterial lItm in list)
     {
         foreach (AbstractObject itm in AbstractObject.m_sEverything)
         {
             GameMaterial mat = itm as GameMaterial;
             if (mat != null && lItm.m_name == itm.m_name && itm.GetType() == lItm.GetType())
             {
                 mat.CopyTools(lItm);
                 break;
             }
         }
     }
 }
Beispiel #10
0
    //Load Materials
    void LoadMaterialsToSell()
    {
        TextAsset xml = Resources.Load <TextAsset>(MaterialsToSellPath);

        GameMaterial.MaterialDataList mdl = DataManager.XMLUnmarshallingFromText <GameMaterial.MaterialDataList>(xml.text);

        //GameMaterial.MaterialDataList mdl = DataManager.XMLUnmarshalling<GameMaterial.MaterialDataList>(MaterialsToSellPath);
        IItem[] items = new IItem[mdl.materials.Length];

        for (int i = 0; i < items.Length; i++)
        {
            //Add the materials to the Dictionary
            items[i] = GameMaterial.FromDataToShop(mdl.materials[i]);
            materials.Add(items[i].Code, items[i]);
        }
    }
Beispiel #11
0
    /// <summary>
    /// parsing excel data into current format
    /// </summary>
    /// <param name="itm">target</param>
    /// <param name="repItm">source</param>
    /// <returns> parsed item </returns>
    public static new AbstractObject Parse(AbstractObject itm, ExcelLoading.AbstractObject repItm)
    {
        ExcelLoading.Process rep = (ExcelLoading.Process)repItm;
        Process proc             = (Process)itm;

        proc.m_onWork = proc.WorkComplite;

        proc._duration      = rep.duration;
        proc.m_itemsStarted = new ProcessItems[proc._duration + 1];
        for (int i = 0; i <= proc._duration; i++)
        {
            proc.m_itemsStarted[i] = new ProcessItems();
        }

        return(GameMaterial.Parse(itm, repItm));
    }
Beispiel #12
0
    public void Randomize()
    {
        materials = new GameMaterial[MaterialSize];

        for (int i = 0; i < MaterialSize; i++)
        {
            materials[i] = new GameMaterial();

            materials[i].id   = "ID00" + i;
            materials[i].name = "LOREM IPSUM " + Random.Range(0, 1000);
            //materials[i].Costo = Random.Range(0, 1000);
            materials[i].color  = Random.ColorHSV();
            materials[i].sprite = SpritePool.RandomSprite();
        }

        //ToUI();
    }
Beispiel #13
0
 /// <summary>
 /// Copting ItemsEffects from another material
 /// </summary>
 /// <param name="source">source</param>
 public void CopyTools(GameMaterial source)
 {
     if (m_tools != null && source.m_tools != null)
     {
         foreach (ItemsEffect tool in m_tools)
         {
             foreach (ItemsEffect matTool in source.m_tools)
             {
                 if (tool.m_toolName == matTool.m_toolName)
                 {
                     tool.Copy(matTool);
                     break;
                 }
             }
         }
     }
 }
    /// <summary>
    /// All items work
    /// </summary>
    public static void DoWork()
    {
        foreach (AbstractObject itm in m_sEverything)
        {
            //clearing variables before calculating
            try
            {
                itm.m_productivity = 0;
                itm.m_oredered     = 0;
                itm.m_consumed     = 0;
                itm.m_maxProduced  = 0;
                if (itm is GameMaterial)
                {
                    GameMaterial mat = (GameMaterial)itm;
                    mat.m_maxProduced = mat.CountMaxProduction();
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("AbstractObject: DoWork 1:" + ex.Message);
            }
        }

        for (int i = 0; i < m_sEverything.Count; i++)
        {
            try
            {
                AbstractObject mat = m_sEverything[i];
                mat.Working();
            }
            catch (Exception ex)
            {
                Debug.Log("AbstractObject: DoWork 2:" + ex.Message);
                Camera.main.GetComponent <TimeScript>().m_timeTxt = ex.Message;
            }
        }

        foreach (var itm in m_sEverything)
        {
            if (itm.m_isItOpen > 0)
            {
                itm.CalcProductivity();
            }
        }
    }
Beispiel #15
0
    /// <summary>
    /// parsing excel data into current format
    /// </summary>
    /// <param name="itm">target</param>
    /// <param name="repItm">source</param>
    /// <returns> parsed item </returns>
    public new static AbstractObject Parse(AbstractObject itm, ExcelLoading.AbstractObject repItm)
    {
        ExcelLoading.ItemItem rep = (ExcelLoading.ItemItem)repItm;
        Items itms = (Items)itm;

        itms.m_bug = rep.bug;
        itms.m_bugFixingPerPerson = rep.bug_fixing_per_second;
        itms.m_isItDestroyable    = true;
        itms.m_tooltipDamaged     = Localization.GetLocalization().m_ui.m_itemsDamaged;

        string[] crtc = rep.critical.Split(' ');
        itms.m_critical = uint.Parse(crtc[2]);
        string[] effTps = rep.effect_type.Split(';');
        foreach (string effect in effTps)
        {
            try
            {
                string[]    parts       = effect.Split('*');
                string      effName     = parts[0].Trim();
                float       effValue    = FloatParse(parts[1].Trim());
                ItemsEffect itemsEffect = effName.CheckType() ?
                                          new ContainerEffect(effName, effValue, itms)
                    : new ItemsEffect(effName, effValue, itms);

                itms.m_effects.Add(effName, itemsEffect);
                Productions.AddTools(itemsEffect, effName);

                if (itemsEffect.GetType() == typeof(ContainerEffect))
                {
                    itms.m_containerEffect = itemsEffect as ContainerEffect;
                    Camera.main.GetComponent <Storage>().AddStorageItem(itms);
                }
                if (itemsEffect.m_name == "happy" || itemsEffect.m_name == "maxHappy")
                {
                    itms.m_happyEffect = itemsEffect;
                }
            }
            catch (Exception ex)
            {
                Debug.Log(ex.Message);
            }
        }

        return(GameMaterial.Parse(itm, repItm));
    }
Beispiel #16
0
        public static GameMaterial FindMaterialByKey(string materialkey)
        {
            if (materialinfo_list == null || materialinfo_list.Count == 0)
            {
                return(null);
            }
            GameMaterial rmaterial = null;

            foreach (GameMaterial material in materialinfo_list)
            {
                if (material.itemkey.CompareTo(materialkey) == 0)
                {
                    rmaterial = material;
                    break;
                }
            }
            return(rmaterial);
        }
Beispiel #17
0
    /// <summary>
    /// parsing excel data into current format
    /// </summary>
    /// <param name="itm">target</param>
    /// <param name="repItm">source</param>
    /// <returns> parsed item </returns>
    public static new AbstractObject Parse(AbstractObject itm, ExcelLoading.AbstractObject repItm)
    {
        ExcelLoading.MaterialItem rep = (ExcelLoading.MaterialItem)repItm;
        GameMaterial mat = (GameMaterial)itm;

        mat.m_size      = rep.container;
        mat.m_container = rep.container_type.ParseCont();
        string[] prods = rep.production_type.Split('&');
        foreach (string prod in prods)
        {
            string prodTmp = prod.Trim();
            mat.m_productionType.Add(prodTmp);
            Productions.AddProduction(mat, prodTmp);
        }
        mat.m_onWork = mat.WorkComplite;

        return(GameAbstractItem.Parse(mat, rep));
    }
Beispiel #18
0
        // Use this for initialization
        void Start()
        {
            LoadingData.LoadItem();

            Utilities.DebugLog("LoadingData.GetTabCount " + LoadingData.GetTabCount(LoadingData.table_equipment));
            BlackSmithAddition getback          = LoadingData.FindBlackSmithAdditionByKey(blacksmithfindkey);
            Equipment          getback2         = LoadingData.FindEquipmentInfoByKey(equipmentfindkey);
            GameMaterial       getback3         = LoadingData.FindMaterialByKey(materialfindkey);
            MissionPoint       missionpointback = LoadingData.FindMissionByKey(missionpointfindkey);
            Stage   stageback   = LoadingData.FindStageByKey(stagefindkey);
            Alchemy alchemyback = LoadingData.FindAlchemyByKey(alchemyfindkey);

            Utilities.DebugLog("addition info " + getback.itemkey);
            Utilities.DebugLog("need add " + getback.param.Count + "  item");
            foreach (KeyValuePair <string, int> param in getback.param)
            {
                Utilities.DebugLog("addition key " + param.Key + "  value " + param.Value);
            }
            Utilities.DebugLog("================================");
            Utilities.DebugLog("weapon info " + getback2.equipmentkey);

            Utilities.DebugLog("weapon type " + getback2.type);

            Utilities.DebugLog("weapon price " + getback2.price_value);

            Utilities.DebugLog("material info " + getback3.itemkey);

            Utilities.DebugLog("weapon tw " + getback3.tw);

            Utilities.DebugLog("weapon desc " + getback2.tw_desc);

            Utilities.DebugLog("mission point now is " + missionpointback.key);

            Utilities.DebugLog("stageback now is " + stageback.key);
            Utilities.DebugLog("stageback point now is " + stageback.checkpointcount);
            Utilities.DebugLog("stageback king is " + stageback.kingname);

            Utilities.DebugLog("alchemyback now is " + alchemyback.itemkey);
            foreach (KeyValuePair <GameMaterial, int> param in alchemyback.param)
            {
                Utilities.DebugLog("addition key " + param.Key.tw + "  value " + param.Value);
            }
        }
Beispiel #19
0
        public static void SetInitListForAlchemy()
        {
            if (itemTable != null && itemTable.Count > 0)
            {
                if (!itemTable.ContainsKey(table_alchemy))
                {
                    return;
                }
                Hashtable parentTable = (Hashtable)itemTable [table_alchemy];

                foreach (string stringkey in parentTable.Keys)
                {
                    //把每一行抓出來
                    Hashtable currenttable    = (Hashtable)parentTable[stringkey];
                    Alchemy   current_alchemy = new Alchemy();
                    current_alchemy.itemkey = stringkey;
                    current_alchemy.param   = new Dictionary <GameMaterial, int> ();
                    GameMaterial firstmaterial = FindMaterialByKey(Utilities.LoadString(currenttable[key_alchemy_param1], ""));
                    if (firstmaterial == null)
                    {
                        Utilities.DebugLog("alchemy can't find in material " + Utilities.LoadString(currenttable[key_alchemy_param1]));
                        return;
                    }
                    current_alchemy.param.Add(firstmaterial, Utilities.LoadInt(currenttable[key_alchemy_param1count], 0));
                    string checking = Utilities.LoadString(currenttable[key_alchemy_param2], "");
                    if (checking != null && checking.CompareTo("") != 0)
                    {
                        GameMaterial secondmaterial = FindMaterialByKey(Utilities.LoadString(currenttable[key_alchemy_param2], ""));
                        if (secondmaterial == null)
                        {
                            Utilities.DebugLog("alchemy can't find in material " + Utilities.LoadString(currenttable[key_alchemy_param2]));
                            return;
                        }
                        current_alchemy.param.Add(secondmaterial, Utilities.LoadInt(currenttable[key_alchemy_param2count], 0));
                    }

                    Utilities.DebugLog("alchemy now is " + stringkey);
                    alchemyinfo_list.Add(current_alchemy);
                }
            }
        }
Beispiel #20
0
    /// <summary>
    /// loading data from xml files
    /// </summary>
    public void Loading()
    {
        //order is important! from parents to children, science the last one
        EffectTypeHolder.Load("effect_map");
        MineralResource.Load("mineralResource_Map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        Resource.Load("resource_Map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        GameMaterial.Load("materials_Map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        Items.Load("items_Map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        Buildings.Load("buildings_Map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        Army.Load("army_map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        Process.Load("process_map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        Science.Load("science_map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        DomesticAnimal.Load("domesticAnimal_map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());
        WildAnimal.Load("wildAnimal_map");
        //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount());

        LearningTip.Load("AllTips_Map");

        GameAbstractItem.ParseDependency();
        Population ppl = new Population {
            m_people = GetComponent <People>(), m_isItOpen = 1
        };

        AbstractObject.m_sEverything.Add(ppl);
        Localization.GetLocalization().FirstLoad();
        Localization.GetLocalization().ChangeLanguage(Localization.GetLocalization().m_currentLanguage);
        AbstractObject.ClearUnparsed();

        Debug.Log("loading finished");
    }
Beispiel #21
0
        public static GeometricObjectElementCollideTriangles Read(Reader reader, Pointer offset, GeometricObjectCollide geo)
        {
            MapLoader l = MapLoader.Loader;
            GeometricObjectElementCollideTriangles sm = new GeometricObjectElementCollideTriangles(offset, geo);

            sm.off_material = Pointer.Read(reader);
            if (Settings.s.game == Settings.Game.R2Revolution || Settings.s.game == Settings.Game.LargoWinch)
            {
                sm.num_triangles = reader.ReadUInt16();
                reader.ReadUInt16();
                sm.off_triangles = Pointer.Read(reader);
                if (Settings.s.game == Settings.Game.LargoWinch)
                {
                    sm.off_normals = Pointer.Read(reader);
                    sm.off_unk     = Pointer.Read(reader);
                }
            }
            else
            {
                if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                {
                    sm.num_triangles = reader.ReadUInt16();
                    sm.num_mapping   = reader.ReadUInt16();
                    sm.off_triangles = Pointer.Read(reader);
                    sm.off_mapping   = Pointer.Read(reader);
                    sm.off_normals   = Pointer.Read(reader);
                    sm.off_uvs       = Pointer.Read(reader);
                    if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                    {
                        reader.ReadUInt32();
                    }
                    if (Settings.s.game != Settings.Game.TTSE)
                    {
                        Pointer.Read(reader);                        // table of num_unk vertex indices (vertices, because max = num_vertices - 1)
                        reader.ReadUInt16();                         // num_unk
                        sm.ind_parallelBox = reader.ReadInt16();
                    }
                }
                else
                {
                    sm.off_triangles   = Pointer.Read(reader);
                    sm.off_normals     = Pointer.Read(reader);
                    sm.num_triangles   = reader.ReadUInt16();
                    sm.ind_parallelBox = reader.ReadInt16();
                    reader.ReadUInt32();
                    if (Settings.s.game != Settings.Game.Dinosaur)
                    {
                        sm.off_mapping = Pointer.Read(reader);
                        sm.off_unk     = Pointer.Read(reader);                     // num_mapping_entries * 3 floats
                        sm.off_unk2    = Pointer.Read(reader);                     // num_mapping_entries * 1 float
                        sm.num_mapping = reader.ReadUInt16();
                        reader.ReadUInt16();
                    }
                }
            }
            if (!geo.isBoundingVolume)
            {
                if (sm.off_material != null)
                {
                    sm.gameMaterial = GameMaterial.FromOffsetOrRead(sm.off_material, reader);
                }
            }
            else
            {
                // Sector superobject
            }
            Pointer.Goto(ref reader, sm.off_triangles);
            sm.triangles = new int[sm.num_triangles * 3];
            for (int j = 0; j < sm.num_triangles; j++)
            {
                sm.triangles[(j * 3) + 0] = reader.ReadInt16();
                sm.triangles[(j * 3) + 1] = reader.ReadInt16();
                sm.triangles[(j * 3) + 2] = reader.ReadInt16();
            }
            Pointer.DoAt(ref reader, sm.off_normals, () => {
                sm.normals = new Vector3[sm.num_triangles];
                for (int j = 0; j < sm.num_triangles; j++)
                {
                    float x       = reader.ReadSingle();
                    float z       = reader.ReadSingle();
                    float y       = reader.ReadSingle();
                    sm.normals[j] = new Vector3(x, y, z);
                }
            });

            if (sm.num_mapping > 0 && sm.off_mapping != null)
            {
                Pointer.Goto(ref reader, sm.off_mapping);
                sm.mapping = new int[sm.num_triangles * 3];
                for (int i = 0; i < sm.num_triangles; i++)
                {
                    sm.mapping[(i * 3) + 0] = reader.ReadInt16();
                    sm.mapping[(i * 3) + 1] = reader.ReadInt16();
                    sm.mapping[(i * 3) + 2] = reader.ReadInt16();
                }
                if (sm.off_uvs != null)
                {
                    Pointer.Goto(ref reader, sm.off_uvs);
                    sm.uvs = new Vector2[sm.num_mapping];
                    for (int i = 0; i < sm.num_mapping; i++)
                    {
                        sm.uvs[i] = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                    }
                }
            }

            /*R3Pointer.Goto(ref reader, sm.off_mapping);
             * sm.mapping = new int[sm.num_triangles * 3];
             * for (int j = 0; j < sm.num_triangles; j++) {
             *  sm.mapping[(j * 3) + 0] = reader.ReadInt16();
             *  sm.mapping[(j * 3) + 1] = reader.ReadInt16();
             *  sm.mapping[(j * 3) + 2] = reader.ReadInt16();
             * }
             * R3Pointer.Goto(ref reader, sm.off_unk);
             * sm.normals = new Vector3[sm.num_mapping_entries];
             * for (int j = 0; j < sm.num_mapping_entries; j++) {
             *  float x = reader.ReadSingle();
             *  float z = reader.ReadSingle();
             *  float y = reader.ReadSingle();
             *  sm.normals[j] = new Vector3(x, y, z);
             * }*/
            return(sm);
        }
Beispiel #22
0
        async UniTask LoadLVLSNA()
        {
            loadingState = "Loading level memory";
            await WaitIfNecessary();

            Reader  reader = files_array[Mem.Lvl].reader;
            Pointer off_current;
            SNA     sna = (SNA)files_array[Mem.Lvl];

            // First read GPT
            files_array[Mem.Lvl].GotoHeader();
            reader = files_array[Mem.Lvl].reader;
            print("LVL GPT offset: " + Pointer.Current(reader));

            if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
            {
                // SDA

                /*sna.GotoSDA();
                 * print(Pointer.Current(reader));
                 * reader.ReadUInt32();
                 * reader.ReadUInt32(); // same as next
                 * uint num_strings = reader.ReadUInt32();
                 * uint indexOfTextGlobal = reader.ReadUInt32(); // dword_6EEE78
                 * uint dword_83EC58 = reader.ReadUInt32();
                 * print(num_strings + " - " + Pointer.Current(reader));
                 *
                 * // DLG
                 * sna.GotoDLG();
                 * Pointer off_strings = Pointer.Read(reader);
                 * for (int i = 0; i < num_strings; i++) {
                 *  Pointer.Read(reader);
                 * }
                 * reader.ReadUInt32();*/

                // GPT
                sna.GotoHeader();
                if (Settings.s.game != Settings.Game.PlaymobilLaura)
                {
                    Pointer.Read(reader); // sound related
                }
                Pointer.Read(reader);
                Pointer.Read(reader);
                reader.ReadUInt32();
            }
            if (Settings.s.engineVersion != Settings.EngineVersion.Montreal)
            {
                loadingState = "Reading settings for persos in fix";
                await WaitIfNecessary();

                // Fill in fix -> lvl pointers for perso's in fix
                uint      num_persoInFixPointers = reader.ReadUInt32();
                Pointer[] persoInFixPointers     = new Pointer[num_persoInFixPointers];
                for (int i = 0; i < num_persoInFixPointers; i++)
                {
                    Pointer off_perso = Pointer.Read(reader);
                    if (off_perso != null)
                    {
                        off_current = Pointer.Goto(ref reader, off_perso);
                        reader.ReadUInt32();
                        Pointer off_stdGame = Pointer.Read(reader);
                        if (off_stdGame != null)
                        {
                            if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                            {
                                Pointer.Goto(ref reader, off_stdGame);
                                reader.ReadUInt32(); // type 0
                                reader.ReadUInt32(); // type 1
                                reader.ReadUInt32(); // type 2
                                Pointer off_superObject = Pointer.Read(reader);
                                Pointer.Goto(ref reader, off_current);
                                if (off_superObject == null)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                Pointer.Goto(ref reader, off_current);
                            }
                            // First read everything from the GPT
                            Pointer off_newSuperObject = null, off_nextBrother = null, off_prevBrother = null, off_father = null;
                            byte[]  matrixData = null, floatData = null, renderBits = null;
                            if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                            {
                                off_newSuperObject = Pointer.Read(reader);
                                matrixData         = reader.ReadBytes(0x58);
                                renderBits         = reader.ReadBytes(4);
                                floatData          = reader.ReadBytes(4);
                                off_nextBrother    = Pointer.Read(reader);
                                off_prevBrother    = Pointer.Read(reader);
                                off_father         = Pointer.Read(reader);
                            }
                            else
                            {
                                matrixData         = reader.ReadBytes(0x58);
                                off_newSuperObject = Pointer.Read(reader);
                                Pointer.DoAt(ref reader, off_stdGame + 0xC, () => {
                                    ((SNA)off_stdGame.file).AddPointer(off_stdGame.offset + 0xC, off_newSuperObject);
                                });
                            }

                            // Then fill everything in
                            off_current = Pointer.Goto(ref reader, off_newSuperObject);
                            uint    newSOtype             = reader.ReadUInt32();
                            Pointer off_newSOengineObject = Pointer.Read(reader);
                            if (SuperObject.GetSOType(newSOtype) == SuperObject.Type.Perso)
                            {
                                persoInFixPointers[i] = off_newSOengineObject;
                                Pointer.Goto(ref reader, off_newSOengineObject);
                                Pointer off_p3dData = Pointer.Read(reader);
                                if (Settings.s.game == Settings.Game.R2Demo)
                                {
                                    ((SNA)off_p3dData.file).OverwriteData(off_p3dData.FileOffset + 0x1C, matrixData);
                                }
                                else
                                {
                                    ((SNA)off_p3dData.file).OverwriteData(off_p3dData.FileOffset + 0x18, matrixData);
                                }

                                if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                                {
                                    FileWithPointers file = off_newSuperObject.file;
                                    file.AddPointer(off_newSuperObject.FileOffset + 0x14, off_nextBrother);
                                    file.AddPointer(off_newSuperObject.FileOffset + 0x18, off_prevBrother);
                                    file.AddPointer(off_newSuperObject.FileOffset + 0x1C, off_father);
                                    ((SNA)file).OverwriteData(off_newSuperObject.FileOffset + 0x30, renderBits);
                                    ((SNA)file).OverwriteData(off_newSuperObject.FileOffset + 0x38, floatData);
                                }
                            }
                            else
                            {
                                persoInFixPointers[i] = null;
                            }
                        }
                        Pointer.Goto(ref reader, off_current);
                    }
                }
            }
            loadingState = "Loading globals";
            await WaitIfNecessary();

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                globals.off_actualWorld          = Pointer.Read(reader);
                globals.off_dynamicWorld         = Pointer.Read(reader);
                globals.off_inactiveDynamicWorld = Pointer.Read(reader);
                globals.off_fatherSector         = Pointer.Read(reader);
                globals.off_firstSubMapPosition  = Pointer.Read(reader);
            }
            else
            {
                globals.off_actualWorld  = Pointer.Read(reader);
                globals.off_dynamicWorld = Pointer.Read(reader);
                globals.off_fatherSector = Pointer.Read(reader);
                uint soundEventIndex = reader.ReadUInt32(); // In Montreal version this is a pointer, also sound event related
                if (Settings.s.game == Settings.Game.PlaymobilLaura)
                {
                    Pointer.Read(reader);
                }
            }

            globals.num_always      = reader.ReadUInt32();
            globals.spawnablePersos = LinkedList <Perso> .ReadHeader(reader, Pointer.Current(reader), LinkedList.Type.Double);

            globals.off_always_reusableSO = Pointer.Read(reader); // There are (num_always) empty SuperObjects starting with this one.
            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                globals.off_always_reusableUnknown1 = Pointer.Read(reader); // (num_always) * 0x2c blocks
                globals.off_always_reusableUnknown2 = Pointer.Read(reader); // (num_always) * 0x4 blocks
            }
            else
            {
                reader.ReadUInt32(); // 0x6F. In Montreal version this is a pointer to a pointer table for always
                globals.spawnablePersos.FillPointers(reader, globals.spawnablePersos.off_tail, globals.spawnablePersos.offset);
            }

            if (Settings.s.game == Settings.Game.DD)
            {
                reader.ReadUInt32();
            }
            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                Pointer dword_4A6B1C_always_header = Pointer.Read(reader);
                Pointer dword_4A6B20_always_last   = Pointer.Read(reader);

                Pointer v28 = Pointer.Read(reader);
                Pointer v31 = Pointer.Read(reader);
                Pointer v32 = Pointer.Read(reader);
                Pointer v33 = Pointer.Read(reader);

                // These things aren't parsed, but in raycap they're null. This way we'll notice when they aren't.
                if (v28 != null)
                {
                    print("v28 is not null, it's " + v28);
                }
                if (v31 != null)
                {
                    print("v31 is not null, it's " + v31);
                }
                if (v32 != null)
                {
                    print("v32 is not null, it's " + v32);
                }
                if (v33 != null)
                {
                    print("v33 is not null, it's " + v33);
                }

                // Fill in pointers for the unknown table related to "always".
                FillLinkedListPointers(reader, dword_4A6B20_always_last, dword_4A6B1C_always_header);
            }

            // Fill in pointers for the object type tables and read them
            objectTypes = new ObjectType[3][];
            for (uint i = 0; i < 3; i++)
            {
                Pointer off_names_header = Pointer.Current(reader);
                Pointer off_names_first  = Pointer.Read(reader);
                Pointer off_names_last   = Pointer.Read(reader);
                uint    num_names        = reader.ReadUInt32();

                FillLinkedListPointers(reader, off_names_last, off_names_header);
                ReadObjectNamesTable(reader, off_names_first, num_names, i);
            }

            // Begin of engineStructure
            loadingState = "Loading engine structure";
            await WaitIfNecessary();

            print("Start of EngineStructure: " + Pointer.Current(reader));
            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                reader.ReadByte();
                string mapName = reader.ReadString(0x1E);
                reader.ReadChars(0x1E);
                string mapName2 = reader.ReadString(0x1E);
                reader.ReadByte();
                reader.ReadBytes(0x178); // don't know what this data is
            }
            else
            {
                reader.ReadByte();
                string mapName = reader.ReadString(0x104);
                reader.ReadChars(0x104);
                string mapName2 = reader.ReadString(0x104);
                if (Settings.s.game == Settings.Game.PlaymobilLaura)
                {
                    reader.ReadChars(0x104);
                    reader.ReadChars(0x104);
                }
                string mapName3 = reader.ReadString(0x104);
                if (Settings.s.game == Settings.Game.TT)
                {
                    reader.ReadBytes(0x47F7); // don't know what this data is
                }
                else if (Settings.s.game == Settings.Game.TTSE)
                {
                    reader.ReadBytes(0x240F);
                }
                else if (Settings.s.game == Settings.Game.PlaymobilLaura)
                {
                    reader.ReadBytes(0x240F); // don't know what this data is
                }
                else                          // Hype & Alex
                {
                    reader.ReadBytes(0x2627); // don't know what this data is
                }
            }
            Pointer off_unknown_first = Pointer.Read(reader);
            Pointer off_unknown_last  = Pointer.Read(reader);
            uint    num_unknown       = reader.ReadUInt32();

            families = LinkedList <Family> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double);

            families.FillPointers(reader, families.off_tail, families.off_head);

            if (Settings.s.game == Settings.Game.PlaymobilLaura)
            {
                LinkedList <int> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double);
            }

            LinkedList <SuperObject> alwaysActiveCharacters = LinkedList <SuperObject> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double);

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                if (Settings.s.game == Settings.Game.RedPlanet || Settings.s.game == Settings.Game.R2Demo)
                {
                    reader.ReadUInt32();
                }
                Pointer off_languages = Pointer.Read(reader);
                reader.ReadUInt32();

                Pointer.DoAt(ref reader, off_languages, () => {
                    ReadLanguages(reader, off_languages, localization.num_languages);
                });

                for (uint i = 0; i < 2; i++)
                {
                    Pointer off_matrix = Pointer.Current(reader);
                    Matrix  mat        = Matrix.Read(reader, off_matrix);
                }

                reader.ReadUInt32();
                reader.ReadUInt16();

                ReadLevelNames(reader, Pointer.Current(reader), 80);
                uint num_mapNames = reader.ReadUInt32();
                Array.Resize(ref levels, (int)num_mapNames);
                reader.ReadUInt16();
                reader.ReadUInt32();
                reader.ReadUInt32();

                if (Settings.s.game == Settings.Game.DD)
                {
                    reader.ReadUInt32();
                }

                // End of engineStructure
                Pointer off_light    = Pointer.Read(reader); // the offset of a light. It's just an ordinary light.
                Pointer off_mainChar = Pointer.Read(reader); // superobject
                Pointer off_characterLaunchingSoundEvents = Pointer.Read(reader);
                if (Settings.s.game == Settings.Game.DD)
                {
                    globals.off_backgroundGameMaterial = Pointer.Read(reader);
                }
                Pointer off_shadowPolygonVisualMaterial   = Pointer.Read(reader);
                Pointer off_shadowPolygonGameMaterialInit = Pointer.Read(reader);
                Pointer off_shadowPolygonGameMaterial     = Pointer.Read(reader);
                Pointer off_textureOfTextureShadow        = Pointer.Read(reader);
                Pointer off_col_taggedFacesTable          = Pointer.Read(reader);

                for (int i = 0; i < 10; i++)
                {
                    Pointer off_elementForShadow      = Pointer.Read(reader);
                    Pointer off_geometricShadowObject = Pointer.Read(reader);
                }
                Pointer.Read(reader); // DemoSOList

                if (Settings.s.game == Settings.Game.R2Demo || Settings.s.game == Settings.Game.RedPlanet || Settings.s.mode == Settings.Mode.DonaldDuckPCDemo)
                {
                    Pointer.Read(reader);
                }

                if (Settings.s.mode == Settings.Mode.DonaldDuckPCDemo)
                {
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                }

                loadingState = "Loading level animation bank";
                //print("Animation bank: " + Pointer.Current(reader));
                await WaitIfNecessary();

                AnimationBank.Read(reader, Pointer.Current(reader), 0, 1, files_array[Mem.LvlKeyFrames], append: true);
                animationBanks[1] = animationBanks[0];
            }
            if (FileSystem.mode != FileSystem.Mode.Web)
            {
                string levelsFolder = gameDataBinFolder + ConvertPath(gameDsb.levelsDataPath) + "/";
                ((SNA)files_array[0]).CreateMemoryDump(levelsFolder + "fix.dmp", true);
                ((SNA)files_array[1]).CreateMemoryDump(levelsFolder + lvlName + "/" + lvlName + ".dmp", true);
            }

            // Read PTX
            loadingState = "Loading level textures";
            await WaitIfNecessary();

            // Can't yield inside a lambda, so we must do it the old fashioned way, with off_current
            if (sna.PTX != null)
            {
                off_current = Pointer.Goto(ref reader, sna.PTX);
                await ReadTexturesLvl(reader, Pointer.Current(reader));

                Pointer.Goto(ref reader, off_current);
            }

            /*Pointer.DoAt(ref reader, sna.PTX, () => {
             * ReadTexturesLvl(reader, Pointer.Current(reader));
             * });*/

            // Read background game material (DD only)
            globals.backgroundGameMaterial = GameMaterial.FromOffsetOrRead(globals.off_backgroundGameMaterial, reader);

            // Parse actual world & always structure
            loadingState = "Loading families";
            await WaitIfNecessary();

            ReadFamilies(reader);

            loadingState = "Creating animation bank";
            await WaitIfNecessary();

            if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
            {
                animationBanks    = new AnimationBank[2];
                animationBanks[0] = new AnimationBank(null)
                {
                    animations = new Animation.Component.AnimA3DGeneral[0]
                };
                animationBanks[1] = animationBanks[0];
            }
            else if (Settings.s.engineVersion <= Settings.EngineVersion.TT)
            {
                uint maxAnimIndex = 0;
                foreach (State s in states)
                {
                    if (s.anim_ref != null && s.anim_ref.anim_index > maxAnimIndex)
                    {
                        maxAnimIndex = s.anim_ref.anim_index;
                    }
                }
                animationBanks    = new AnimationBank[2];
                animationBanks[0] = new AnimationBank(null)
                {
                    animations = new Animation.Component.AnimA3DGeneral[maxAnimIndex + 1]
                };
                foreach (State s in states)
                {
                    if (s.anim_ref != null)
                    {
                        animationBanks[0].animations[s.anim_ref.anim_index] = s.anim_ref.a3d;
                    }
                }
                animationBanks[1] = animationBanks[0];
            }

            loadingState = "Loading superobject hierarchy";
            await WaitIfNecessary();
            await ReadSuperObjects(reader);

            loadingState = "Loading always structure";
            await WaitIfNecessary();

            ReadAlways(reader);
            loadingState = "Filling in cross-references";
            await WaitIfNecessary();

            ReadCrossReferences(reader);

            // TODO: Make more generic
            if (Settings.s.game == Settings.Game.R2)
            {
                loadingState = "Filling in comport names";
                await WaitIfNecessary();

                string path = gameDataBinFolder + "R2DC_Comports.json";

                if (!FileSystem.FileExists(path))
                {
                    path = "Assets/StreamingAssets/R2DC_Comports.json"; // Offline, the json doesn't exist, so grab it from StreamingAssets
                }

                Stream stream = FileSystem.GetFileReadStream(path);
                if (stream != null)
                {
                    ReadAndFillComportNames(stream);
                }
            }
        }
Beispiel #23
0
    /// <summary>
    /// One cycle of working.
    /// If we have 1 tool1, 1 tool2, 2 tool3 and 4 workers, it works 3 times:
    /// first:  1 worker with 1 tool1, 1 tool2 and 1 tool3,
    /// second: 1 worker with 1 tool2,
    /// third:  2 workers with no tools
    /// Tools should be sorted by tools count from smaller to bigger count
    /// </summary>
    /// <param name="worked"> how many workers have work here </param>
    /// <param name="startIndex"> witch tools already worked </param>
    /// <param name="producePerPerson"> how many items could produce a worker </param>
    /// <returns> how many items was produced </returns>
    protected long WorkingWithTools(long worked, int startIndex, float producePerPerson)
    {
        float effect    = 1;
        float mulEffect = 1;

        while (startIndex < m_tools.Count && (long)m_tools[startIndex].m_toolsCount == worked) //moving to the first unused tool
        {
            startIndex++;
        }

        //calculate effects of tools
        for (int it = startIndex; it < m_tools.Count; it++)
        {
            var tool = m_tools[it];
            if (tool.m_type == EffectTypes.speed)
            {
                effect += tool.m_value;
            }
            else if (tool.m_type == EffectTypes.result)
            {
                mulEffect += tool.m_value;
            }
        }

        float maxWorkers = CountMaxWorkers(effect, mulEffect);

        //current amount of workers with tools
        long wrks = m_workers < maxWorkers ? m_workers : (int)maxWorkers;

        wrks -= worked;
        if (wrks < 1)
        {
            return(worked);
        }

        //long depWorks = wrks;

        long toolsMax = wrks;

        if (startIndex < m_tools.Count)
        {
            toolsMax = toolsMax < m_tools[startIndex].m_toolsCount ?
                       toolsMax : m_tools[startIndex].m_toolsCount;
        }

        wrks = wrks < toolsMax ? wrks : toolsMax;


        if (m_dependencyCount != null && m_dependencyCount.Length > 0 && !m_isItFix)
        {
            //current amount of workers depends on the resources count
            for (int iL = 0; iL < m_dependencyCount.Length; iL++)
            {
                int count = 0;
                for (int i = 0; i < m_dependencyCount[iL].m_dependency.Count; i++)
                {
                    var dep = m_dependencyCount[iL].m_dependency[i];
                    count += (int)(dep.Count / (effect * m_dependencyCount[iL].m_value[i]));
                    if (dep.GetType() == typeof(Process))
                    {
                        Process proc = dep as Process;
                        mulEffect = proc.m_mulEffect;
                    }
                }
                wrks = wrks < count ? wrks : count;
            }

            //depWorks = wrks > 0 ? wrks : depWorks;

            //consume resources
            for (int iL = 0; iL < m_dependencyCount.Length; iL++)
            {
                long depWrks = wrks;
                for (int i = 0; i < m_dependencyCount[iL].m_dependency.Count && depWrks > 0; i++)
                {
                    long tmpwrks = depWrks;
                    var  dep     = m_dependencyCount[iL].m_dependency[i];
                    int  maxWkrs = (int)(dep.Count / (effect * m_dependencyCount[iL].m_value[i]));
                    tmpwrks = tmpwrks < maxWkrs ? tmpwrks : maxWkrs;
                    float consum = effect * tmpwrks * m_dependencyCount[iL].m_value[i];
                    m_dependencyCount[iL].m_dependency[i].Count      -= consum;
                    m_dependencyCount[iL].m_dependency[i].m_consumed += consum;
                    depWrks -= tmpwrks;
                }
            }
        }

        //working
        for (int i = startIndex; i < m_tools.Count; i++)
        {
            m_tools[i].ToolUsed((long)wrks);
        }

        float effectWorker = effect * wrks;

        //it is fix
        if (producePerPerson != m_producePerPerson[0].m_value[0])
        {
            float prodFinished = effectWorker * producePerPerson;

            if (m_onWork != null)
            {
                m_onWork(prodFinished, 1);
            }
            else
            {
                Count += prodFinished;
                if (Count * m_size > StorageSize)
                {
                    Count = StorageSize / m_size;
                }
            }
        }
        else //this is production
        {
            for (int it = 0; it < m_producePerPerson.Length; it++)
            {
                var dep = m_producePerPerson[it];
                if (it == 0 && m_onWork != null && this == dep.m_dependency[0])
                {
                    m_onWork(effectWorker * producePerPerson, mulEffect);
                }
                else
                {
                    for (int i = 0; i < dep.m_dependency.Count; i++)
                    {
                        dep.m_dependency[i].m_count +=
                            (dep.m_dependency[i].m_name == "empty field" ||
                             dep.m_dependency[i].m_name == "farm field" ?
                             1 : mulEffect) * effectWorker * dep.m_value[i];

                        GameMaterial mat = dep.m_dependency[i] as GameMaterial;
                        if (mat != null)
                        {
                            float maxCount = ((float)mat.StorageSize / mat.m_size);
                            if (dep.m_dependency[i].m_count > maxCount)
                            {
                                dep.m_dependency[i].m_count = maxCount;
                            }
                        }
                    }
                }
            }
        }

        //finishing the working cycle
        worked += wrks;
        if ((wrks > 0 || wrks == toolsMax) && worked < m_workers && startIndex < m_tools.Count)
        {
            return(WorkingWithTools(worked, ++startIndex, producePerPerson));
        }

        return(worked);
    }
Beispiel #24
0
    /// <summary>
    /// Move all scales
    /// </summary>
    void ScaleScales()
    {
        //split types
        if (m_thisItem.GetType() == typeof(Science))
        {
            Science sc = (Science)m_thisItem;
            _tmpPos.x = 0;
            _tmpPos.y = 0;
            _tmpPos.z = 0;
            _productivityMinus.transform.localScale = _tmpPos;
            MoveStorageScale(sc.Count, sc.m_maxCount);
            MoveScale(sc.m_productivity, 100, _productivityPlus.gameObject);
        }
        else
        {
            GameMaterial mat = m_thisItem as GameMaterial;
            if (mat != null)
            {
                MoveStorageScale(mat.Count * mat.m_size, mat.StorageSize);

                if (m_thisItem.m_isItDestroyable)
                {
                    Items itm = m_thisItem as Items;
                    MoveScale(itm.m_damagedCount * mat.m_size, mat.StorageSize, _damagedCount.gameObject);
                }


                float prodPer = 100 * 2 * mat.m_productivity / mat.StorageSize;
                if (prodPer > 100)
                {
                    prodPer = 100;
                }
                if (prodPer >= 0 && prodPer < 1f)
                {
                    prodPer = 1;
                }
                if (prodPer < -100)
                {
                    prodPer = -100;
                }
                if (prodPer <= 0 && prodPer > -1f)
                {
                    prodPer = -1;
                }
                if (float.IsNaN(prodPer))
                {
                    prodPer = 1;
                }
                float prodScale = /*two times shorter*/ (XMaxScale / 2) * (prodPer / 100f);
                if (m_thisItem.m_productivity > 0)
                {
                    _tmpPos.x = 0;
                    _tmpPos.y = YScale;
                    _tmpPos.z = 0;
                    _productivityMinus.transform.localScale = _tmpPos;

                    _tmpPos.x = prodScale;
                    _productivityPlus.transform.localScale = _tmpPos;

                    _tmpPos   = _productivityPlus.transform.localPosition;
                    _tmpPos.x = XMiddlePositionProductivityPlus * prodPer / 100f;

                    _productivityPlus.transform.localPosition = _tmpPos;
                }
                else
                {
                    _tmpPos.x = 0;
                    _tmpPos.y = YScale;
                    _tmpPos.z = 0;
                    _productivityPlus.transform.localScale = _tmpPos;

                    _tmpPos.x = prodScale;
                    _productivityMinus.transform.localScale = _tmpPos;
                    _tmpPos   = _productivityMinus.transform.localPosition;
                    _tmpPos.x = XMiddlePositionProductivityPlus * prodPer / 100f;
                    _productivityMinus.transform.localPosition = _tmpPos;
                }
            }
        }
    }
Beispiel #25
0
        public EDsgVar GetExportableDsgVar(DsgVarInfoEntry infoEntry)
        {
            EDsgVar d = new EDsgVar();

            d.type = infoEntry.type;

            if (infoEntry.value == null)
            {
                return(d);
            }

            switch (infoEntry.type)
            {
            default:
                d.value = infoEntry.value;
                break;

            case DsgVarInfoEntry.DsgVarType.None:
                break;

            case DsgVarInfoEntry.DsgVarType.List:     // TODO: figure out lists
                break;

            case DsgVarInfoEntry.DsgVarType.Comport:     // TODO: comport
                break;

            case DsgVarInfoEntry.DsgVarType.Action:     // TODO: action
                break;

            case DsgVarInfoEntry.DsgVarType.Input:     // TODO: check if this works
                //d.value = infoEntry.value
                break;

            case DsgVarInfoEntry.DsgVarType.SoundEvent:     // TODO: check
                break;

            case DsgVarInfoEntry.DsgVarType.Light:     // TODO: check
                break;

            case DsgVarInfoEntry.DsgVarType.GameMaterial:
                d.value = HashUtils.MD5Hash(GameMaterial.FromOffset((Pointer)(infoEntry.value)).ToJSON());
                break;

            case DsgVarInfoEntry.DsgVarType.VisualMaterial:
                d.value = HashUtils.MD5Hash(VisualMaterial.FromOffset((Pointer)(infoEntry.value)).ToJSON());
                break;

            case DsgVarInfoEntry.DsgVarType.Perso:
                d.value = Perso.FromOffset((Pointer)(infoEntry.value))?.namePerso;
                break;

            case DsgVarInfoEntry.DsgVarType.Waypoint:     // TODO
                d.value = ((Pointer)infoEntry.value).ToString();
                break;

            case DsgVarInfoEntry.DsgVarType.Graph:     // TODO
                d.value = ((Pointer)infoEntry.value).ToString();
                break;

            case DsgVarInfoEntry.DsgVarType.Text:     // TODO: check
                goto default;

            case DsgVarInfoEntry.DsgVarType.SuperObject:     // TODO: check
                break;

            case DsgVarInfoEntry.DsgVarType.SOLinks:     // TODO
                break;

            case DsgVarInfoEntry.DsgVarType.PersoArray:

                List <string> persoNames = new List <string>();
                foreach (object persoPointer in (object[])infoEntry.value)
                {
                    if (persoPointer == null)
                    {
                        continue;
                    }

                    if (!(persoPointer is Pointer))
                    {
                        persoNames.Add("Not a valid pointer: " + (persoPointer).ToString());     // TODO: fix
                        continue;
                    }

                    Perso perso = Perso.FromOffset((Pointer)persoPointer);
                    if (perso != null)
                    {
                        persoNames.Add(perso.namePerso);
                    }
                    else
                    {
                        persoNames.Add("NullPointer");
                    }
                }

                break;

            case DsgVarInfoEntry.DsgVarType.WayPointArray:     // TODO
                break;

            case DsgVarInfoEntry.DsgVarType.TextArray:     // TODO: check
                goto default;

            //break;
            case DsgVarInfoEntry.DsgVarType.TextRefArray:     // TODO: check
                goto default;

            case DsgVarInfoEntry.DsgVarType.Array6:
                break;

            case DsgVarInfoEntry.DsgVarType.Array9:
                break;

            case DsgVarInfoEntry.DsgVarType.SoundEventArray:     // TODO: check
                goto default;

            case DsgVarInfoEntry.DsgVarType.Array11:
                break;

            case DsgVarInfoEntry.DsgVarType.Way:
                break;

            case DsgVarInfoEntry.DsgVarType.ActionArray:     // TODO
                break;

            case DsgVarInfoEntry.DsgVarType.SuperObjectArray:     // TODO
                break;
            }

            return(d);
        }
Beispiel #26
0
 //TODO
 //ACTUALLY SAVE THE QUANTITY LEFT OF "ITEMS"
 void SaveMaterialsToSell()
 {
     DataManager.XMLMarshalling(MaterialsToSellPath, GameMaterial.ExampleData());
 }
Beispiel #27
0
    /// <summary>
    /// Move arrows and change colors
    /// </summary>
    void Update()
    {
        try
        {
            if (!TimeScript.m_isItPaused && !m_isItPaused)
            {
                //position of one of the end object has changed
                if (m_from != null && m_to != null &&
                    (m_from.transform.position != _fromCoord || m_to.transform.position != _toCoord))
                {
                    MoveArrow();
                }

                SpriteRenderer   rend     = _bodyRender;
                SpriteRenderer   rendBody = _bodyRender2;
                GameAbstractItem itm      = m_to.m_thisItem as GameAbstractItem;
                GameMaterial     matFrom  = m_from.m_thisItem as GameMaterial;
                if (m_isItTool)
                {
                    Color clr = rend.color;
                    if (m_from.m_thisItem.m_count > 0)
                    {
                        clr = _sArrowToolsEnough;
                    }
                    else
                    {
                        clr = _sArrowToolsNotEnough;
                    }
                    if (!clr.Equals(rend.color))
                    {
                        if (_isItHimself)
                        {
                            _arrowBody2.color = clr;
                            _arrowBody3.color = clr;
                        }
                        else
                        {
                            rend.color = clr;
                        }
                    }
                }
                else if (itm != null && (itm.m_workers == 0))
                {
                    rend.color = _sArrowMaterialsNotUsed;
                }
                else if (matFrom != null && matFrom.m_productivity < 0)
                {
                    rend.color = _sArrowMaterialsNotEnough;
                }
                else
                {
                    rend.color = _sArrowMaterialsEnough;
                }


                rendBody.color = rend.color;
            }
        }
        catch (Exception ex)
        {
            Debug.LogError("ArrowScript update exception:" + ex.Message);
        }
    }
Beispiel #28
0
        public string ToString(Perso perso, TranslatedScript.TranslationSettings ts, bool advanced = false)
        {
            MapLoader l    = MapLoader.Loader;
            short     mask = 0;

            AITypes aiTypes = Settings.s.aiTypes;

            Vector3 vector3 = new Vector3 {
                x = 0, y = 0, z = 0
            };

            switch (nodeType)
            {
            case ScriptNode.NodeType.KeyWord:                     // KeyWordFunctionPtr
                if (param < aiTypes.keywordTable.Length)
                {
                    if (ts.exportMode)
                    {
                        if (aiTypes.keywordTable[param] == "Me")
                        {
                            return("this");
                        }
                        if (aiTypes.keywordTable[param] == "MainActor")
                        {
                            return("Controller.MainActor");
                        }
                        if (aiTypes.keywordTable[param] == "Nobody" || aiTypes.keywordTable[param] == "NoInput" || aiTypes.keywordTable[param] == "Nowhere" || aiTypes.keywordTable[param] == "NoGraph" || aiTypes.keywordTable[param] == "NoAction" || aiTypes.keywordTable[param] == "CapsNull")
                        {
                            return("null");
                        }
                    }

                    return(aiTypes.keywordTable[param]);
                }
                return("UnknownKeyword_" + param);

            case ScriptNode.NodeType.Condition:                     // GetConditionFunctionPtr
                if (param < aiTypes.conditionTable.Length)
                {
                    return(aiTypes.conditionTable[param]);
                }
                return("UnknownCondition_" + param);

            case ScriptNode.NodeType.Operator:                     // GetOperatorFunctionPtr
                if (advanced)
                {
                    if (param < aiTypes.operatorTable.Length)
                    {
                        return(aiTypes.operatorTable[param] + " (" + param + ")");
                    }
                }
                if (param < aiTypes.operatorTable.Length)
                {
                    return(aiTypes.operatorTable[param]);
                }
                return("UnknownOperator_" + param);

            case ScriptNode.NodeType.Function:                     // GetFunctionFunctionPtr
                if (param < aiTypes.functionTable.Length)
                {
                    return(aiTypes.functionTable[param]);
                }
                return("UnknownFunction_" + param);

            case ScriptNode.NodeType.Procedure:                     // ProcedureFunctionReturn
                if (param < aiTypes.procedureTable.Length)
                {
                    return(aiTypes.procedureTable[param]);
                }
                return("UnknownProcedure_" + param);

            case ScriptNode.NodeType.MetaAction:                     // meta action
                if (param < aiTypes.metaActionTable.Length)
                {
                    return(aiTypes.metaActionTable[param]);
                }
                return("UnknownMetaAction_" + param);

            case ScriptNode.NodeType.BeginMacro:
                return("BeginMacro");

            case ScriptNode.NodeType.EndMacro:
                return("EndMacro");

            case ScriptNode.NodeType.Field:
                if (param < aiTypes.fieldTable.Length)
                {
                    return(aiTypes.fieldTable[param]);
                }
                return("UnknownField_" + param);

            case ScriptNode.NodeType.DsgVarRef:                     // Dsg Var
                if (perso != null && perso.brain != null && perso.brain.mind != null)
                {
                    Mind mind = perso.brain.mind;
                    if (mind.dsgMem != null && mind.dsgMem.dsgVar != null)
                    {
                        if (param < mind.dsgMem.dsgVar.dsgVarInfos.Length)
                        {
                            return(mind.dsgMem.dsgVar.dsgVarInfos[param].NiceVariableName);
                        }
                    }
                    else if (mind.AI_model != null && mind.AI_model.dsgVar != null)
                    {
                        if (param < mind.AI_model.dsgVar.dsgVarInfos.Length)
                        {
                            return(mind.AI_model.dsgVar.dsgVarInfos[param].NiceVariableName);
                        }
                    }
                }
                return("dsgVar_" + param);

            case ScriptNode.NodeType.Constant:
                if (advanced)
                {
                    return("Constant: " + BitConverter.ToInt32(BitConverter.GetBytes(param), 0));
                }
                return(BitConverter.ToInt32(BitConverter.GetBytes(param), 0).ToString());

            case ScriptNode.NodeType.Real:
                NumberFormatInfo nfi = new NumberFormatInfo()
                {
                    NumberDecimalSeparator = "."
                };
                if (advanced)
                {
                    return("Real: " + BitConverter.ToSingle(BitConverter.GetBytes(param), 0).ToString(nfi));
                }
                return(BitConverter.ToSingle(BitConverter.GetBytes(param), 0).ToString(nfi) + "f");

            case ScriptNode.NodeType.Button:     // Button/entryaction
                EntryAction ea = EntryAction.FromOffset(param_ptr);

                if (ea == null)
                {
                    return("ERR_ENTRYACTION_NOTFOUND");
                }

                string eaName = (advanced ? ea.ToString() : ea.ToBasicString());
                if (advanced)
                {
                    return("Button: " + eaName + "(" + param_ptr + ")");
                }

                if (!ts.expandEntryActions && ea != null)
                {
                    return("\"" + ea.ExportName + "\"");
                }
                return(eaName);

            case ScriptNode.NodeType.ConstantVector:
                return("Constant Vector: " + "0x" + param.ToString("x8"));    // TODO: get from address

            case ScriptNode.NodeType.Vector:
                return("new Vector3");    // TODO: same

            case ScriptNode.NodeType.Mask:
                mask = (short)param;     // TODO: as short
                if (advanced)
                {
                    return("Mask: " + (mask).ToString("x4"));
                }
                if (ts.exportMode)
                {
                    return("\"" + (mask).ToString("x4") + "\"");
                }
                return("Mask(" + (mask).ToString("x4") + ")");

            case ScriptNode.NodeType.ModuleRef:
                if (advanced)
                {
                    return("ModuleRef: " + "0x" + (param).ToString("x8"));
                }
                return("GetModule(" + (int)param + ")");

            case ScriptNode.NodeType.DsgVarId:
                if (advanced)
                {
                    return("DsgVarId: " + "0x" + (param).ToString("x8"));
                }
                return("DsgVarId(" + param + ")");

            case ScriptNode.NodeType.String:
                string str = "ERR_STRING_NOTFOUND";
                if (l.strings.ContainsKey(param_ptr))
                {
                    str = l.strings[param_ptr];
                }
                if (advanced)
                {
                    return("String: " + param_ptr + " (" + str + ")");
                }
                return("\"" + str + "\"");

            case ScriptNode.NodeType.LipsSynchroRef:
                return("LipsSynchroRef: " + param_ptr);

            case ScriptNode.NodeType.FamilyRef:
                if (advanced)
                {
                    return("FamilyRef: " + param_ptr);
                }
                Family f = Family.FromOffset(param_ptr);
                if (f != null)
                {
                    return("GetFamily(\"" + f.name + "\")");
                }
                else
                {
                    return("Family.FromOffset(\"" + param_ptr + "\")");
                }

            case ScriptNode.NodeType.PersoRef:
                Perso argPerso = Perso.FromOffset(param_ptr);
                if (argPerso != null && perso != null && argPerso.offset == perso.offset)
                {
                    if (advanced)
                    {
                        return("PersoRef: this");
                    }
                    return("this");
                }
                string persoName = argPerso == null ? "ERR_PERSO_NOTFOUND" : argPerso.fullName;
                if (advanced)
                {
                    return("PersoRef: " + param_ptr + " (" + persoName + ")");
                }
                if (argPerso?.brain?.mind?.AI_model != null)
                {
                    AIModel aiModel = argPerso.brain.mind.AI_model;
                    // Make sure to add a cast in case the AI Model is accessed
                    return("((" + aiModel.name + ")GetPerso(\"" + argPerso.namePerso + "\"))");
                }
                return("GetPerso(\"" + argPerso.namePerso + "\")");

            case ScriptNode.NodeType.ActionRef:
                State  state     = State.FromOffset(param_ptr);
                string stateName = state == null ? "ERR_STATE_NOTFOUND" : state.ShortName;
                if (advanced)
                {
                    return("ActionRef: " + param_ptr + " " + stateName);
                }
                if (ts.useStateIndex)
                {
                    return("GetAction(" + state.index.ToString() + ")");
                }
                return(stateName);

            case ScriptNode.NodeType.SuperObjectRef:
                if (advanced)
                {
                    return("SuperObjectRef: " + param_ptr);
                }
                SuperObject so = SuperObject.FromOffset(param_ptr);
                if (so != null)
                {
                    return("GetSuperObject(\"" + so.Gao.name + "\")");
                }
                else
                {
                    return("SuperObject.FromOffset(\"" + param_ptr + "\")");
                }

            case ScriptNode.NodeType.WayPointRef:
                if (advanced)
                {
                    return("WayPointRef: " + param_ptr);
                }
                return("WayPoint.FromOffset(\"" + param_ptr + "\")");

            case ScriptNode.NodeType.TextRef:
                if (l.localization == null)
                {
                    return("TextRef");
                }
                if (advanced)
                {
                    return("TextRef: " + param + " (" + l.localization.GetTextForHandleAndLanguageID((int)param, 0) + ")");
                }
                if (ts.expandStrings)
                {
                    return("\"" + l.localization.GetTextForHandleAndLanguageID((int)param, 0) + "\"");    // Preview in english
                }
                else
                {
                    return("new TextReference(" + (int)param + ")");
                }

            case ScriptNode.NodeType.ComportRef:
                Behavior comportRef = Behavior.FromOffset(param_ptr);

                if (comportRef == null)
                {
                    if (advanced)
                    {
                        return("ComportRef: " + param_ptr + " (null)");
                    }
                    return("null");
                }
                else
                {
                    return(comportRef.ShortName);
                    //string type = comportRef.type == Behavior.BehaviorType.Normal ? "normalBehavior" : "reflexBehavior";
                    //return type + "[" + script.behaviorOrMacro.aiModel.GetBehaviorIndex(comportRef) + "]";
                }

            case ScriptNode.NodeType.SoundEventRef:
                if (advanced)
                {
                    return("SoundEventRef: " + (int)param);
                }
                return("SoundEvent.FromID(0x" + ((int)param).ToString("X8") + ")");

            case ScriptNode.NodeType.ObjectTableRef:
                if (advanced)
                {
                    return("ObjectTableRef: " + param_ptr);
                }

                if (ts.useHashIdentifiers)
                {
                    string objectListJson = ObjectList.FromOffset(param_ptr).ToJSON();

                    string objectListHash = HashUtils.MD5Hash(objectListJson);
                    return("ObjectList.FromHash(\"" + objectListHash + "\")");
                }

                return("ObjectTable.FromOffset(\"" + param_ptr + "\")");

            case ScriptNode.NodeType.GameMaterialRef:
                if (advanced)
                {
                    return("GameMaterialRef: " + param_ptr);
                }
                if (ts.useHashIdentifiers)
                {
                    string gmtJson = GameMaterial.FromOffset(param_ptr).ToJSON();

                    string gmtHash = HashUtils.MD5Hash(gmtJson);
                    return("GameMaterial.FromHash(\"" + gmtHash + "\")");
                }
                return("GameMaterial.FromOffset(\"" + param_ptr + "\")");

            case ScriptNode.NodeType.ParticleGenerator:
                return("ParticleGenerator: " + "0x" + (param).ToString("x8"));

            case ScriptNode.NodeType.VisualMaterial:
                if (advanced)
                {
                    return("VisualMaterial: " + param_ptr);
                }

                if (ts.useHashIdentifiers)
                {
                    string vmtJson = VisualMaterial.FromOffset(param_ptr).ToJSON();

                    string vmtHash = HashUtils.MD5Hash(vmtJson);
                    return("VisualMaterial.FromHash(\"" + vmtHash + "\")");
                }

                return("VisualMaterial.FromOffset(\"" + param_ptr + "\")");

            case ScriptNode.NodeType.ModelRef:                     // ModelCast
                if (advanced)
                {
                    return("AIModel: " + param_ptr);
                }
                AIModel model = AIModel.FromOffset(param_ptr);
                return(model != null ? model.name : "null");

            case ScriptNode.NodeType.DataType42:
                if (advanced)
                {
                    return("EvalDataType42: " + "0x" + (param).ToString("x8"));
                }
                return("EvalDataType42(" + "0x" + (param).ToString("x8") + ")");

            case ScriptNode.NodeType.CustomBits:
                if (advanced)
                {
                    return("CustomBits: " + "0x" + (param).ToString("x8"));
                }
                if (ts.exportMode)
                {
                    return("0x" + (param).ToString("x8"));
                }
                return("CustomBits(" + "0x" + (param).ToString("x8") + ")");

            case ScriptNode.NodeType.Caps:
                if (advanced)
                {
                    return("Caps: " + "0x" + (param).ToString("x8"));
                }
                if (ts.exportMode)
                {
                    return("0x" + (param).ToString("x8"));
                }
                return("Caps(" + "0x" + (param).ToString("x8") + ")");

            case ScriptNode.NodeType.SubRoutine:
                if (advanced)
                {
                    return("Eval SubRoutine: " + param_ptr);
                }
                Macro macro = Macro.FromOffset(param_ptr);
                if (macro == null)
                {
                    return("null");
                }
                return("evalMacro(" + macro.ShortName + ");");

            case ScriptNode.NodeType.Null:
                return("null");

            case ScriptNode.NodeType.GraphRef:
                if (advanced)
                {
                    return("Graph: " + "0x" + (param).ToString("x8"));
                }
                return("Graph.FromOffset(\"" + param_ptr + "\")");
            }

            return("unknown");
        }
Beispiel #29
0
        public void Read(Reader reader)
        {
            offset = Pointer.Current(reader);
            switch (type)
            {
            case DsgVarInfoEntry.DsgVarType.Boolean:
                valueBool = reader.ReadBoolean(); break;

            case DsgVarInfoEntry.DsgVarType.Byte:
                valueByte = reader.ReadSByte(); break;

            case DsgVarInfoEntry.DsgVarType.UByte:
                valueUByte = reader.ReadByte(); break;

            case DsgVarInfoEntry.DsgVarType.Float:
                valueFloat = reader.ReadSingle(); break;

            case DsgVarInfoEntry.DsgVarType.Int:
                valueInt = reader.ReadInt32(); break;

            case DsgVarInfoEntry.DsgVarType.UInt:
                valueUInt = reader.ReadUInt32(); break;

            case DsgVarInfoEntry.DsgVarType.Short:
                valueShort = reader.ReadInt16(); break;

            case DsgVarInfoEntry.DsgVarType.UShort:
                valueUShort = reader.ReadUInt16(); break;

            case DsgVarInfoEntry.DsgVarType.Vector:
                float x = reader.ReadSingle();
                float y = reader.ReadSingle();
                float z = reader.ReadSingle();
                valueVector = new Vector3(x, y, z);
                break;

            case DsgVarInfoEntry.DsgVarType.Text:
                valueText = reader.ReadInt32(); break;

            case DsgVarInfoEntry.DsgVarType.Graph:
                valuePointer = Pointer.Read(reader);
                valueGraph   = Graph.FromOffsetOrRead(valuePointer, reader);
                break;

            case DsgVarInfoEntry.DsgVarType.WayPoint:
                valuePointer  = Pointer.Read(reader);
                valueWayPoint = WayPoint.FromOffsetOrRead(valuePointer, reader);
                break;

            case DsgVarInfoEntry.DsgVarType.GameMaterial:
                valuePointer      = Pointer.Read(reader);
                valueGameMaterial = GameMaterial.FromOffsetOrRead(valuePointer, reader);
                break;

            case DsgVarInfoEntry.DsgVarType.VisualMaterial:
                valuePointer        = Pointer.Read(reader);
                valueVisualMaterial = VisualMaterial.FromOffsetOrRead(valuePointer, reader);
                break;

            case DsgVarInfoEntry.DsgVarType.ObjectList:
                valuePointer    = Pointer.Read(reader);
                valueObjectList = ObjectList.FromOffsetOrRead(valuePointer, reader);
                break;

            case DsgVarInfoEntry.DsgVarType.List:
                valueList = new List();
                valueList.Read(reader);
                break;

            case DsgVarInfoEntry.DsgVarType.Light:
                valuePointer = Pointer.Read(reader);
                valueLight   = MapLoader.Loader.FromOffsetOrRead <LightInfo>(reader, valuePointer);
                break;

            case DsgVarInfoEntry.DsgVarType.Comport:
                valuePointer = Pointer.Read(reader);
                valueComport = MapLoader.Loader.FromOffsetOrRead <Behavior>(reader, valuePointer);
                break;

            case DsgVarInfoEntry.DsgVarType.Input:
                valuePointer = Pointer.Read(reader);
                valueInput   = EntryAction.FromOffsetOrRead(valuePointer, reader);
                break;

            // Fill these in after loading
            case DsgVarInfoEntry.DsgVarType.Perso:
                valuePointer = Pointer.Read(reader);
                // Don't fill in perso yet
                MapLoader.Loader.onPostLoad.Add(InitPostLoad);
                break;

            case DsgVarInfoEntry.DsgVarType.Action:
                valuePointer = Pointer.Read(reader);
                // Don't fill in state yet
                MapLoader.Loader.onPostLoad.Add(InitPostLoad);
                break;

            case DsgVarInfoEntry.DsgVarType.SuperObject:
                valuePointer = Pointer.Read(reader);
                // Don't fill in SO yet
                MapLoader.Loader.onPostLoad.Add(InitPostLoad);
                break;

            // TODO: Figure these out
            case DsgVarInfoEntry.DsgVarType.Caps:
                valueCaps = reader.ReadUInt32(); break;

            case DsgVarInfoEntry.DsgVarType.SOLinks:
                valueSOLinks = reader.ReadUInt32(); break;

            case DsgVarInfoEntry.DsgVarType.SoundEvent:
                valueSoundEvent = reader.ReadUInt32(); break;

            case DsgVarInfoEntry.DsgVarType.Way:
                valueWay = reader.ReadUInt32(); break;

            // Arrays
            case DsgVarInfoEntry.DsgVarType.ActionArray:
            case DsgVarInfoEntry.DsgVarType.FloatArray:
            case DsgVarInfoEntry.DsgVarType.IntegerArray:
            case DsgVarInfoEntry.DsgVarType.PersoArray:
            case DsgVarInfoEntry.DsgVarType.SoundEventArray:
            case DsgVarInfoEntry.DsgVarType.SuperObjectArray:
            case DsgVarInfoEntry.DsgVarType.TextArray:
            case DsgVarInfoEntry.DsgVarType.TextRefArray:
            case DsgVarInfoEntry.DsgVarType.VectorArray:
            case DsgVarInfoEntry.DsgVarType.WayPointArray:
            case DsgVarInfoEntry.DsgVarType.GraphArray:
            case DsgVarInfoEntry.DsgVarType.Array11:
            case DsgVarInfoEntry.DsgVarType.Array9:
                ReadArray(reader); break;
            }
        }
Beispiel #30
0
        public static GeometricObjectElementSprites Read(Reader reader, Pointer offset, GeometricObject m)
        {
            MapLoader l = MapLoader.Loader;
            GeometricObjectElementSprites s = new GeometricObjectElementSprites(offset, m);

            s.name = "Sprite @ pos " + offset;
            //l.print(s.name);

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                if (Settings.s.platform == Settings.Platform.DC)
                {
                    s.off_sprites = offset;
                    s.num_sprites = 1;
                }
                else
                {
                    s.off_sprites = Pointer.Read(reader);
                    s.num_sprites = reader.ReadUInt16();
                    reader.ReadInt16(); // -1
                    if (Settings.s.game != Settings.Game.R2Revolution)
                    {
                        reader.ReadUInt32();
                        if (Settings.s.game != Settings.Game.LargoWinch)
                        {
                            reader.ReadUInt32();
                        }
                    }
                }
            }
            else
            {
                s.num_sprites = (ushort)reader.ReadUInt32();
                s.off_sprites = Pointer.Read(reader);
                reader.ReadUInt32();
            }
            if (Settings.s.game == Settings.Game.R2Revolution)
            {
                Pointer.DoAt(ref reader, s.off_sprites, () => {
                    s.sprites = new IndexedSprite[s.num_sprites];
                    for (uint i = 0; i < s.num_sprites; i++)
                    {
                        s.sprites[i]            = new IndexedSprite();
                        uint type               = reader.ReadUInt32();
                        s.sprites[i].info_scale = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                        if (type == 0x20)
                        {
                            // Light cookie sprite
                            uint index                              = reader.ReadUInt32();
                            R2PS2Loader ps2l                        = MapLoader.Loader as R2PS2Loader;
                            s.sprites[i].visualMaterial             = ps2l.lightCookieMaterial.Clone();
                            s.sprites[i].visualMaterial.diffuseCoef = ps2l.lightCookieColors[index];
                        }
                        else
                        {
                            s.sprites[i].off_material = Pointer.Read(reader);
                            if (s.sprites[i].off_material != null)
                            {
                                s.sprites[i].visualMaterial = VisualMaterial.FromOffsetOrRead(s.sprites[0].off_material, reader);
                            }
                        }
                    }
                });
            }
            else if (Settings.s.platform == Settings.Platform.DC)
            {
                s.sprites    = new IndexedSprite[1];
                s.sprites[0] = new IndexedSprite();
                s.sprites[0].off_material = Pointer.Read(reader);
                if (s.sprites[0].off_material != null)
                {
                    s.sprites[0].visualMaterial = VisualMaterial.FromOffsetOrRead(s.sprites[0].off_material, reader);
                }
                s.sprites[0].info_scale = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                reader.ReadUInt16();
                s.sprites[0].centerPoint = reader.ReadUInt16();
                reader.ReadUInt16();
                reader.ReadUInt16();
                reader.ReadUInt16();
                reader.ReadUInt16();
            }
            else
            {
                if (s.off_sprites != null)
                {
                    Pointer.Goto(ref reader, s.off_sprites);
                    s.sprites = new IndexedSprite[s.num_sprites];
                    for (uint i = 0; i < s.num_sprites; i++)
                    {
                        s.sprites[i] = new IndexedSprite();
                        if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
                        {
                            reader.ReadUInt32();
                        }
                        s.sprites[i].off_info = Pointer.Read(reader);
                        s.sprites[i].size     = new Vector2(reader.ReadSingle(), reader.ReadSingle());

                        if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
                        {
                            if (Settings.s.game != Settings.Game.LargoWinch)
                            {
                                s.sprites[i].constraint = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                                s.sprites[i].uv1        = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                                s.sprites[i].uv2        = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                            }
                            s.sprites[i].centerPoint = reader.ReadUInt16();
                            reader.ReadUInt16();
                            if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                            {
                                reader.ReadUInt32();
                            }
                        }

                        if (s.sprites[i].off_info != null)
                        {
                            Pointer off_current = Pointer.Goto(ref reader, s.sprites[i].off_info);
                            reader.ReadUInt32();
                            Pointer.Read(reader);
                            Pointer.Read(reader);
                            Pointer off_info_scale   = Pointer.Read(reader);
                            Pointer off_info_unknown = Pointer.Read(reader);
                            s.sprites[i].off_material_pointer = Pointer.Read(reader);
                            Pointer.Goto(ref reader, off_current);

                            Pointer.DoAt(ref reader, off_info_scale, () => {
                                s.sprites[i].info_scale = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                            });
                            Pointer.DoAt(ref reader, off_info_unknown, () => {
                                s.sprites[i].info_unknown = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                            });
                            if (s.sprites[i].off_material_pointer != null)
                            {
                                off_current = Pointer.Goto(ref reader, s.sprites[i].off_material_pointer);
                                s.sprites[i].off_material = Pointer.Read(reader);
                                if (s.sprites[i].off_material != null)
                                {
                                    if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                                    {
                                        s.sprites[i].gameMaterial   = GameMaterial.FromOffsetOrRead(s.sprites[i].off_material, reader);
                                        s.sprites[i].visualMaterial = s.sprites[i].gameMaterial.visualMaterial;
                                    }
                                    else
                                    {
                                        s.sprites[i].visualMaterial = VisualMaterial.FromOffsetOrRead(s.sprites[i].off_material, reader);
                                    }
                                }
                                Pointer.Goto(ref reader, off_current);
                            }
                        }
                    }
                }
            }

            return(s);
        }