Esempio n. 1
0
        // Add object group to symbol table
        internal void AddObjectDef(string name, IList <string> others, LogicOperator oper)
        {
            var sym = CollectObjects(others.Select(o => ParseSymbol(o)).ToList());

            sym.Name = name;

            // if it's a collection of all objects then make a decision
            if (sym.Kind == SymbolKind.Real && sym.ObjectIds.Count > 1)
            {
                sym.Kind = (oper == LogicOperator.And) ? SymbolKind.Aggregate : SymbolKind.Property;
            }

            // these are bad, otherwise use whatever we have
            if ((oper == LogicOperator.And && sym.Kind != SymbolKind.Aggregate) ||
                (oper == LogicOperator.Or && sym.Kind != SymbolKind.Property))
            {
                CompileError("incompatible symbols: {0}", others.Join());
            }
            _symbols[name] = sym;
            var decode = name.All(c => (int)c <= 255) ? ""
        : " (" + name.Select(c => ((int)c).ToString("X")).Join() + ")";

            DebugLog("Define '{0}'{1}: {2} <{3}>",
                     name, decode, sym.Kind, sym.ObjectIds.Select(o => _gamedef.ShowName(o)).Join());
        }
Esempio n. 2
0
        // check whether a sound has been triggered
        // NOTE: sound may not happen if some other command takes precedence
        internal void CheckTrigger(SoundTrigger trigger, int obj = 0, Direction direction = Direction.None)
        {
            Logger.WriteLine(3, "Check trigger {0} {1} {2}", trigger, _gamedef.ShowName(obj), direction);
            var sound = _gamedef.GameSounds.SafeLookup(trigger);

            if (sound == null)
            {
                var sact = _gamedef.ObjectSounds.FirstOrDefault(s => s.Trigger == trigger && s.ObjectIds.Contains(obj) &&
                                                                (s.Directions == null || s.Directions.Contains(direction)));
                if (sact != null)
                {
                    sound = sact.Seed;
                }
            }
            if (sound != null)
            {
                AddCommand(CommandName.Sound_, sound);
            }
        }
Esempio n. 3
0
        // move an object at location in a direction
        // direction None used to cancel existing movement
        internal void MoveObject(int obj, int cellindex, Direction direction, RuleGroup rulegroup)
        {
            if (!(GameDef.MoveDirections.Contains(direction) || direction == Direction.Stationary))
            {
                throw Error.Assert("move {0}", direction);
            }
            // only move an object if it's here, else add a new mover
            if (_level[cellindex, _gamedef.GetLayer(obj)] == obj)
            {
                var found = false;

                // first try to update move list
                // do not use rule group in comparison -- if rigid, this may cause a problem
                for (var movex = 0; movex < _movers.Count; ++movex)
                {
                    var mover = _movers[movex];
                    if (mover.ObjectId == obj && mover.CellIndex == cellindex)
                    {
                        found = true;
                        if (_movers[movex].Direction != direction)
                        {
                            Logger.WriteLine(2, "Mover now {0} to {1} at {2}", direction, _gamedef.ShowName(obj), cellindex);
                            if (direction == Direction.Stationary)
                            {
                                _movers.RemoveAt(movex);
                            }
                            else
                            {
                                _movers[movex].Direction = direction;
                            }
                            //_vm_moved = true;    // TODO: only for net change
                        }
                        break;
                    }
                }
                // otherwise add a new mover
                if (!found && direction != Direction.Stationary)
                {
                    Logger.WriteLine(2, "Mover set {0} to {1} at {2}", direction, _gamedef.ShowName(obj), cellindex);
                    _movers.Add(Mover.Create(obj, cellindex, _gamedef.GetLayer(obj), direction, rulegroup));
                    //_vm_moved = true;    // TODO: only for net change
                }
            }
        }