Ejemplo n.º 1
0
        private MachineRegistration RegistrationForCubeValue(int cube, int value)
        {
            MachineRegistration machineRegistration = null;

            if (machineById.TryGetValue(new MachineKey(cube, value), out machineRegistration))
            {
                return(machineRegistration);
            }
            machineById.TryGetValue(new MachineKey(cube, -1), out machineRegistration);
            return(machineRegistration);
        }
Ejemplo n.º 2
0
        public void registerMachine(ModRegistrationData mrd, Type type)
        {
            object[] segEntityAttr = type.GetCustomAttributes(typeof(FCESegmentEntityAttribute), false);
            if (segEntityAttr.Length == 0)
            {
                return;
            }
            FCESegmentEntityAttribute segEntity = segEntityAttr[0] as FCESegmentEntityAttribute;

            log("Registering {0} to {1} ...", segEntity.key, type.FullName);
            if (machineByKey.ContainsKey(segEntity.key))
            {
                log("--- Key {0} is already registered to {1}", segEntity.key, machineByKey[segEntity.key].type.FullName);
                return;
            }
            // TODO: confirm that type it has a proper constructor
            mrd.RegisterEntityHandler(segEntity.key);

            // find the cubeType and CubeValue that was assigned
            TerrainDataEntry      terrainDataEntry;
            TerrainDataValueEntry terrainDataValueEntry;

            TerrainData.GetCubeByKey(segEntity.key, out terrainDataEntry, out terrainDataValueEntry);
            ushort?cubeType  = terrainDataEntry?.CubeType;
            ushort cubeValue = terrainDataValueEntry?.Value ?? 0;

            // add it to our list so that we can create it later
            MachineRegistration mr = new MachineRegistration(type, segEntity.objectType);

            machineById.Add(new MachineKey(cubeType, cubeValue), mr);
            machineByKey.Add(segEntity.key, mr);


            // Check the class to see if it has has global static fields to store the cube and value type in
            MemberInfo[] props = type.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (MemberInfo p in props)
            {
                if (p.GetCustomAttributes(typeof(FCECubeType), false).Length > 0)
                {
                    (p as PropertyInfo)?.SetValue(null, cubeType, null);
                    (p as FieldInfo)?.SetValue(null, cubeType);
                }
                if (p.GetCustomAttributes(typeof(FCECubeValue), false).Length > 0)
                {
                    (p as PropertyInfo)?.SetValue(null, cubeValue, null);
                    (p as FieldInfo)?.SetValue(null, cubeValue);
                }
            }

            log("  Registered {0} to {1} with key={2}, value={3}, objectType={4}", segEntity.key, type.Name, cubeType, cubeValue, segEntity.objectType);
        }
Ejemplo n.º 3
0
        public void CheckForCompletedMachine(ModCheckForCompletedMachineParameters parameters)
        {
            MachineRegistration           machineRegistration = null;
            FCEMultiblockMachineAttribute specs = machineRegistration.MultiblockAttributes;

            if (!machineByPlacement.TryGetValue(parameters.CubeValue, out machineRegistration))
            {
                return;
            }

            // Find the negative-most corner
            long x = parameters.X;
            long y = parameters.Y;
            long z = parameters.Z;

            long minY = parameters.Y, minX = parameters.X, minZ = parameters.Z;

            while (IsPlacement(parameters.Frustrum, minX - 1, minY, minZ, machineRegistration.PlacementBlock))
            {
                minX--;
            }
            while (IsPlacement(parameters.Frustrum, minX, minY - 1, minZ, machineRegistration.PlacementBlock))
            {
                minY--;
            }
            while (IsPlacement(parameters.Frustrum, minX, minY, minZ - 1, machineRegistration.PlacementBlock))
            {
                minZ--;
            }


            long maxY = minY + specs.Length, maxX = 0, maxZ = 0;

            if (IsPlacement(parameters.Frustrum, minX + specs.Length, maxY, maxZ + specs.Width, machineRegistration.PlacementBlock))
            {
                maxX = minX + specs.Length;
                maxZ = minZ + specs.Width;
            }
            else if (IsPlacement(parameters.Frustrum, minX + specs.Width, maxY, maxZ + specs.Length, machineRegistration.PlacementBlock))
            {
                maxX = minX + specs.Width;
                maxZ = minZ + specs.Length;
            }
            else
            {
                // Couldn't find opposite corner, so just throw it out
                return;
            }
        }
Ejemplo n.º 4
0
        public ModCreateSegmentEntityResults CreateSegmentEntity(ModCreateSegmentEntityParameters parameters)
        {
/*            log("Creating with params: " +
 *              "X = " + parameters.X + ", " +
 *              "Y = " + parameters.Y + ", " +
 *              "Z = " + parameters.Z + ", " +
 *              "Cube = " + parameters.Cube + ", " +
 *              "Value = " + parameters.Value + ", " +
 *              "Segment = " + parameters.Segment + ", " +
 *              "Type = " + parameters.Type + ", " +
 *              "Flags = " + parameters.Flags + ", " +
 *              "toString = \"" + parameters.ToString() + "\""
 *              );
 */
            ModCreateSegmentEntityResults res = new ModCreateSegmentEntityResults();

            MachineRegistration machineRegistration = RegistrationForCubeValue(parameters.Cube, parameters.Value);

            if (machineRegistration != null)
            {
                parameters.ObjectType = machineRegistration.objectType;
                parameters.Type       = eSegmentEntity.Mod;
                try
                {
                    res.Entity = (SegmentEntity)Activator.CreateInstance(machineRegistration.type, new Object[] { parameters });
                }
                catch (MissingMethodException e)
                {
                    log("No constructor for {1} that takes a ModCreateSegmentEntityParameters: {2}", machineRegistration.type.Name, e);
                }
            }
            else
            {
                log("Requested an unknown Segment Entity: " +
                    "X = " + parameters.X + ", " +
                    "Y = " + parameters.Y + ", " +
                    "Z = " + parameters.Z + ", " +
                    "Cube = " + parameters.Cube + ", " +
                    "Value = " + parameters.Value + ", " +
                    "Segment = " + parameters.Segment + ", " +
                    "Type = " + parameters.Type + ", " +
                    "Flags = " + parameters.Flags + ", " +
                    "toString = \"" + parameters.ToString() + "\""
                    );
            }

            return(res);
        }