Exemplo n.º 1
0
    /*
     * Load all Houses from a file.
     * @param fp The file to load from.
     * @param length The length of the data chunk.
     * @return True if and only if all bytes were read successful.
     */
    internal static bool House_LoadOld(BinaryReader fp, uint length)
    {
        while (length > 0)
        {
            CHouse hl = null;

            /* Read the next House from disk */
            if (!SaveLoad_Load(s_saveHouse, fp, hl))
            {
                return(false);
            }

            /* See if it is a human house */
            if (hl.flags.human)
            {
                g_playerHouseID = (HouseType)hl.index;
                break;
            }

            length -= SaveLoad_GetLength(s_saveHouse);
        }
        if (length == 0)
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 2
0
 /*
  * Initialize the House array.
  *
  * @param address If non-zero, the new location of the House array.
  */
 internal static void House_Init()
 {
     for (var i = 0; i < g_houseArray.Length; i++)
     {
         g_houseArray[i] = new CHouse();                             //memset(g_houseArray, 0, sizeof(g_houseArray));
     }
     Array.Fill(g_houseFindArray, null, 0, g_houseFindArray.Length); //memset(g_houseFindArray, 0, sizeof(g_houseFindArray));
     g_houseFindCount = 0;
 }
Exemplo n.º 3
0
    /*
     * Updates the radar state for the given house.
     * @param h The house.
     * @return True if and only if the radar has been activated.
     */
    internal static bool House_UpdateRadarState(CHouse h)
    {
        /*WSAObject*/
        (WSAHeader header, Array <byte> buffer)wsa;
        ushort frame;
        ushort frameCount;
        bool   activate;

        if (h == null || h.index != (byte)g_playerHouseID)
        {
            return(false);
        }

        activate = h.flags.radarActivated;

        if (h.flags.radarActivated)
        {
            /* Deactivate radar */
            if ((h.structuresBuilt & (1 << (byte)StructureType.STRUCTURE_OUTPOST)) == 0 || h.powerProduction < h.powerUsage)
            {
                activate = false;
            }
        }
        else
        {
            /* Activate radar */
            if ((h.structuresBuilt & (1 << (byte)StructureType.STRUCTURE_OUTPOST)) != 0 && h.powerProduction >= h.powerUsage)
            {
                activate = true;
            }
        }

        if (h.flags.radarActivated == activate)
        {
            return(false);
        }

        wsa = WSA_LoadFile("STATIC.WSA", GFX_Screen_Get_ByIndex(Screen.NO1), GFX_Screen_GetSize_ByIndex(Screen.NO1), true);
        //frameCount = WSA_GetFrameCount(wsa);

        g_textDisplayNeedsUpdate = true;

        GUI_Mouse_Hide_Safe();

        while (Driver_Voice_IsPlaying())
        {
            SleepIdle();
        }

        Voice_Play(62);

        Sound_Output_Feedback((ushort)(activate ? 28 : 29));

        frameCount = WSA_GetFrameCount(wsa);

        for (frame = 0; frame < frameCount; frame++)
        {
            WSA_DisplayFrame(wsa, (ushort)(activate ? frameCount - frame : frame), 256, 136, Screen.NO0);
            GUI_PaletteAnimate();

            Timer_Sleep(3);
        }

        h.flags.radarActivated = activate;

        WSA_Unload(wsa);

        g_viewport_forceRedraw = true;

        GUI_Mouse_Show_Safe();

        GUI_Widget_Viewport_RedrawMap(Screen.NO0);

        return(activate);
    }
Exemplo n.º 4
0
    /*
     * Calculate the power usage and production, and the credits storage.
     *
     * @param h The house to calculate the numbers for.
     */
    internal static void House_CalculatePowerAndCredit(CHouse h)
    {
        var find = new PoolFindStruct();

        if (h == null)
        {
            return;
        }

        h.powerUsage      = 0;
        h.powerProduction = 0;
        h.creditsStorage  = 0;

        find.houseID = h.index;
        find.index   = 0xFFFF;
        find.type    = 0xFFFF;

        while (true)
        {
            StructureInfo si;
            CStructure    s;

            s = Structure_Find(find);
            if (s == null)
            {
                break;
            }
            /* ENHANCEMENT -- Only count structures that are placed on the map, not ones we are building. */
            if (g_dune2_enhanced && s.o.flags.isNotOnMap)
            {
                continue;
            }

            si = g_table_structureInfo[s.o.type];

            h.creditsStorage += si.creditsStorage;

            /* Positive values means usage */
            if (si.powerUsage >= 0)
            {
                h.powerUsage += (ushort)si.powerUsage;
                continue;
            }

            /* Negative value and full health means everything goes to production */
            if (s.o.hitpoints >= si.o.hitpoints)
            {
                h.powerProduction += (ushort)-si.powerUsage;
                continue;
            }

            /* Negative value and partial health, calculate how much should go to production (capped at 50%) */
            /* ENHANCEMENT -- The 50% cap of Dune2 is silly and disagress with the GUI. If your hp is 10%, so should the production. */
            if (!g_dune2_enhanced && s.o.hitpoints <= si.o.hitpoints / 2)
            {
                h.powerProduction += (ushort)((-si.powerUsage) / 2);
                continue;
            }
            h.powerProduction += (ushort)((-si.powerUsage) * s.o.hitpoints / si.o.hitpoints);
        }

        /* Check if we are low on power */
        if (h.index == (byte)g_playerHouseID && h.powerUsage > h.powerProduction)
        {
            GUI_DisplayText(String_Get_ByIndex(Text.STR_INSUFFICIENT_POWER_WINDTRAP_IS_NEEDED), 1);
        }

        /* If there are no buildings left, you lose your right on 'credits without storage' */
        if (h.index == (byte)g_playerHouseID && h.structuresBuilt == 0 && g_validateStrictIfZero == 0)
        {
            g_playerCreditsNoSilo = 0;
        }
    }