Esempio n. 1
0
    public void init(UnitType type, SpriteDrawer drawer)
    {
        Main.unitManager.addUnit(this);
        //
        //  Initialise unit structure (must be zero filled!)
        //
        unitType = type;

        seen.Frame              = UnitNotSeen; // Unit isn't yet seen
        spriteDrawer            = drawer;
        drawer.unit             = this;
        drawer.m_transform      = drawer.transform;
        drawer.m_spriteRenderer = drawer.GetComponent <SpriteRenderer>();
        // Frame = type->StillFrame;

        //if (UnitManager.unitTypeVar.NumberVariable)
        //{
        //    Assert(!Variable);
        //    Variable = new CVariable[UnitTypeVar.NumberVariable];
        //    memcpy(Variable, Type->Variable,
        //        UnitTypeVar.NumberVariable * sizeof(*Variable));
        //}

        // Set a heading for the unit if it Handles Directions
        // Don't set a building heading, as only 1 construction direction
        //   is allowed.
        if (type.numDirections > 1 && type.sprite != null && !type.isBuilding)
        {
            Direction = MathUtil.GetIntRandomNumber(0, 359);//(MyRand() >> 8) & 0xFF; // 0-225 random heading
            updateHeading( );
        }

        if (type.canCastSpell)
        {
            //AutoCastSpell = new char[SpellTypeTable.size()];
            //if (Type->AutoCastActive)
            //{
            //    memcpy(AutoCastSpell, Type->AutoCastActive, SpellTypeTable.size());
            //}
            //else
            //{
            //    memset(AutoCastSpell, 0, SpellTypeTable.size());
            //}
        }
        Active = true;

        Removed = true;

        //Assert(Orders.empty());

        orders.Add(new Order());

        OrderCount       = 1; // No orders
        orders[0].action = UnitAction.UnitActionStill;
        orders[0].x      = orders[0].y = -1;
        //  Assert(!Orders[0]->Goal);
        newOrder.action = UnitAction.UnitActionStill;
        newOrder.x      = newOrder.y = -1;
        // Assert(!NewOrder.Goal);
        savedOrder.action = UnitAction.UnitActionStill;
        savedOrder.x      = savedOrder.y = -1;
        // Assert(!SavedOrder.Goal);
        criticalOrder.action = UnitAction.UnitActionStill;
        criticalOrder.x      = criticalOrder.y = -1;
        // Assert(!CriticalOrder.Goal);
    }