private void ResolveEnum(IExpression enumExpr, IExpression constantExpr)
        {
            Contract.Requires(enumExpr != null);
            Contract.Requires(constantExpr != null);

            var targetType = enumExpr.Type.ResolvedType;

            if (targetType.IsEnum && constantExpr is ICompileTimeConstant)
            {
                var constant = (ICompileTimeConstant)constantExpr;

                var value = targetType.Fields.FirstOrDefault(f => f.IsCompileTimeConstant && constant.Value.Equals(f.CompileTimeValue.Value));

                if (value != null)
                {
                    // Celeriac uses reflection-style names for inner types, need to be consistent here
                    var name = string.Join(".", TypeHelper.GetTypeName(targetType, NameFormattingOptions.UseReflectionStyleForNestedTypeNames), value.Name);
                    TryAdd(constantExpr, name);
                    AddInstanceExpr(targetType, constantExpr);
                    StaticNames.Add(constantExpr);
                }
                else
                {
                    try
                    {
                        // Enum is defined in another assembly
                        var enumType = TypeManager.ConvertAssemblyQualifiedNameToType(
                            TypeManager.ConvertCCITypeToAssemblyQualifiedName(targetType)).GetSingleType;
                        Contract.Assume(enumType.IsEnum, "CCI enum type resolved to non-enum type");
                        var name = string.Join(".", enumType.FullName, enumType.GetEnumName(constant.Value));
                        TryAdd(constantExpr, name);
                    }
                    catch (Exception)
                    {
                        // Issue #84: debug errors locating enums in other assemblies
                    }
                }
            }
        }
Example #2
0
    void Start()
    {
        checkEndGame();

        TileInfo[] bTiles = BaseSaver.getTiles();
        UnitInfo[] bUnits = BaseSaver.getUnits();

        HexCell hPos = cells [0];

        if (bTiles != null && bUnits != null)
        {
            game = BaseSaver.getGame();
            for (int i = 0; i < cells.Length; i++)
            {
                cells [i].SetInfo(bUnits[i]);
                cells [i].SetTile(bTiles[i]);

                if (bUnits[i].human)
                {
                    int mv = game.movement - game.fatigue;
                    cells [i].GetInfo().actions = mv < 0 ? 0 : mv;
                    hPos = cells [i];
                    focusOnCell(cells [i]);
                }
            }

            GameObject.Find("TurnImg").GetComponent <Image>().color = playerColors [0];
            setPTurn(0);

            /*
             * Here is where the new quests need to be calculated if there are any
             */
            foreach (QuestInfo quest in game.quests)
            {
                if (!quest.placed)
                {
                    quest.startIdx = hPos.coordinates;
                    List <HexCell> dests = new List <HexCell> ();
                    for (int i = 0; i < cells.Length; i++)
                    {
                        if (cells[i].GetTile().type == quest.locType && !cells[i].GetTile().interaction)
                        {
                            HexCell[] path = HexAI.aStar(cells, hPos, cells[i]);
                            if (path != null && path.Length < 10)
                            {
                                dests.Add(cells[i]);
                            }
                        }
                    }
                    if (dests.Count > 0)
                    {
                        HexCell[] theseDests = dests.ToArray();
                        HexUtilities.ShuffleArray(theseDests);
                        theseDests [0].GetTile().interaction = true;
                        quest.endIdx = theseDests [0].coordinates;
                        quest.placed = true;
                        Debug.Log("Destination Set: " + quest.endIdx.ToString());
                        Debug.Log("Tiles saved");
                        BaseSaver.putBoard(cells, BaseSaver.getBoardInfo().name,
                                           BaseSaver.getBoardInfo().height, BaseSaver.getBoardInfo().width);
                        BaseSaver.putGame(game);
                    }
                    else
                    {
                        Debug.Log("No destinations! Quest invalid...");
                    }
                }
            }

            ResetCells();
            hexMesh.Triangulate(cells);
//			BaseSaver.resetBoard ();
        }
        else
        {
            Debug.Log("Maps: ");
            foreach (MapInfo mp in BaseSaver.getMaps())
            {
                Debug.Log(mp.name);
            }


//			foreach(HexCell cell in cells) {
//				cell.GetTile ().fog = true;
//			}

//			MapInfo map = BaseSaver.getMap("Basic Level");
//      MapInfo map = BaseSaver.getMap(MAP_NAME);

            Debug.Log("Next Map: " + BaseSaver.getNextMap());

            MapInfo map = BaseSaver.getMap(BaseSaver.getNextMap());

            List <int> playerPos = new List <int> ();
            List <int> enemyPos  = new List <int> ();

            for (int i = 0; i < cells.Length; i++)
            {
                if (map.tiles[i].type == TileInfo.tileType.pSpawn)
                {
                    cells[i].setType(TileInfo.tileType.Road);
                    playerPos.Add(i);
                }
                else if (map.tiles[i].type == TileInfo.tileType.eSpawn)
                {
                    cells[i].setType(TileInfo.tileType.Road);
                    enemyPos.Add(i);
                }
                else
                {
                    cells[i].setType(map.tiles[i].type);
                    if (cells[i].GetTile().type == TileInfo.tileType.Castle || cells[i].GetTile().type == TileInfo.tileType.City)
                    {
                        cells [i].GetTile().meta = StaticNames.getTownName();
                        Debug.Log("Town Name: " + cells [i].GetTile().meta);
                    }
                }
            }

            int[] pArr = playerPos.ToArray();
            int[] eArr = enemyPos.ToArray();

            HexUtilities.ShuffleArray(pArr);
            HexUtilities.ShuffleArray(eArr);


            placePlayer(cells[pArr[0]], 0, false, UnitInfo.unitType.Adventure, true);
            cells [pArr[0]].removeFog();

            placePlayer(cells[eArr[0]], 1, false, UnitInfo.unitType.Adventure, false);

//			if (players > 2) {
//				placePlayer(cells[cells.Length - width], 2, false, UnitInfo.unitType.Adventure, false);
//			}
//
//			if (players > 3) {
//				placePlayer (cells [width - 1], 3, false, UnitInfo.unitType.Adventure, false);
//			}

//			foreach (HexCell cell in cells) {
//				//			cell.setType((TileInfo.tileType) Random.Range(0, 7));
//				cell.setType(TileInfo.tileType.Grass);
//			}

//			HexCell[] road = HexAI.aStar (cells, cells[0], cells[cells.Length - 1]);
//			foreach (HexCell cell in road) {
//				cell.setType(TileInfo.tileType.Road);
//			}
//
//      HexAdventureGenerator.generateMap (cells, height, width);
//
//			int mountain = Random.Range (3, cells.Length - 3);
//			cells [mountain].setType (TileInfo.tileType.Mountain);
//			foreach(HexDirection dir in cells [mountain].dirs) {
//				if (cells [mountain].GetNeighbor(dir) && TileInfo.tileType.Grass == cells [mountain].GetNeighbor(dir).GetTile().type) {
//					cells [mountain].GetNeighbor (dir).setType (TileInfo.tileType.Forest);
//				}
//			}

//			foreach (HexCell cell in cells){
//				if (cell.GetPlayer() == -1) {
//					int chp = Random.Range(0, 4);
//					if (chp == 0) {
//						cell.GetTile ().interaction = true;
////						cell.setLabel ("I");
//					}
//				}
//			}

            hexMesh.Triangulate(cells);
            setPTurn(players - 1);
            EndTurn();
            ResetCells();
        }
    }
        private void HandleBundle(IExpression outer, object definition, IExpression instance)
        {
            Contract.Requires(outer != null);
            Contract.Requires(definition != null);

            if (definition is IParameterDefinition)
            {
                var name = ((IParameterDefinition)definition).Name.Value;

                if (!string.IsNullOrEmpty(name))
                {
                    TryAdd(outer, name);
                }
                else
                {
                    // NO OP: implicit this of superclass is not named (e.g., for default ctor of subclass)
                }
            }
            else if (definition is IPropertyDefinition)
            {
                var name = ((IPropertyDefinition)definition).Name.Value;
                Contract.Assume(!string.IsNullOrWhiteSpace(name), Context());
                TryAdd(outer, name);
            }
            else if (definition is IFieldReference)
            {
                var field = ((IFieldReference)definition).ResolvedField;

                if (!(field is Dummy) && !field.Attributes.Any(a => TypeManager.IsCompilerGenerated(field)))
                {
                    if (field.IsStatic)
                    {
                        var container = field.ContainingType.ResolvedType;
                        // Celeriac uses reflection-style names for inner types, need to be consistent here
                        var name = string.Join(".", TypeHelper.GetTypeName(container, NameFormattingOptions.UseReflectionStyleForNestedTypeNames), field.Name.Value);
                        TryAdd(outer, name);
                        AddInstanceExpr(container, outer);
                        StaticNames.Add(outer);
                    }
                    else
                    {
                        Contract.Assume(instance != null, "Non-static field reference '" + field.Name + "' has no provided instance; " + Context());
                        if (instance != null && NameTable.ContainsKey(instance))
                        {
                            var name = NameTable[instance] + "." + field.Name;
                            TryAdd(outer, name);
                            AddInstanceExpr(Type, outer);
                        }
                        else
                        {
                            // NO OP (we aren't tracking the name of the instance)
                        }
                    }
                }
            }
            else if (definition is IArrayIndexer)
            {
                var def = (IArrayIndexer)definition;
                if (NameTable.ContainsKey(def.IndexedObject))
                {
                    TryAdd(outer, FormElementsExpression(NameTable[def.IndexedObject]));

                    // propogate instance expression information
                    if (InstanceExpressionsReferredTypes.ContainsKey(def.IndexedObject))
                    {
                        AddInstanceExpr(InstanceExpressionsReferredTypes[def.IndexedObject], outer);
                    }
                }
                else
                {
                    // NO OP (we aren't tracking the name of the instance)
                }
            }
            else if (definition is ILocalDefinition)
            {
                var def = (ILocalDefinition)definition;
                TryAdd(outer, "<local>" + def.Name.Value);
            }
            else if (definition is IAddressDereference)
            {
                // NO OP
            }
            else
            {
                throw new NotSupportedException("Comparability: Unexpected bundled type " + definition.GetType().Name);
            }
        }