Пример #1
0
void cGameFactory::createDependenciesForPlayers() {
	logbook("cGameFactory:createDependenciesForPlayers [BEGIN]");

	for (int i = HUMAN; i < MAX_PLAYERS; i++) {
		cPlayer * thePlayer = &player[i];
		thePlayer->setId(i);

		cItemBuilder * itemBuilder = new cItemBuilder(thePlayer);
		thePlayer->setItemBuilder(itemBuilder);

		cSideBar * sidebar = cSideBarFactory::getInstance()->createSideBar(thePlayer, 9);
		thePlayer->setSideBar(sidebar);

		cBuildingListUpdater * buildingListUpdater = new cBuildingListUpdater(thePlayer);
		thePlayer->setBuildingListUpdater(buildingListUpdater);

		cStructurePlacer * structurePlacer = new cStructurePlacer(thePlayer);
		thePlayer->setStructurePlacer(structurePlacer);

		cUpgradeBuilder * upgradeBuilder = new cUpgradeBuilder(thePlayer);
		thePlayer->setUpgradeBuilder(upgradeBuilder);

		cOrderProcesser * orderProcesser = new cOrderProcesser(thePlayer);
		thePlayer->setOrderProcesser(orderProcesser);

		thePlayer->setTechLevel(9);
	}
	logbook("cGameFactory:createDependenciesForPlayers [END]");
}
Пример #2
0
void cGameFactory::createNewDependenciesForGame(GameState state) {
	logbook("cGameFactory:createNewDependenciesForGame [BEGIN]");

	createDependenciesForPlayers();
	createGameControlsContextsForPlayers();

	createNewGameDrawerAndSetCreditsForHuman();
	createInteractionManagerForHumanPlayer(state);

	logbook("cGameFactory:createNewDependenciesForGame [END]");
}
Пример #3
0
void cGameFactory::createNewGameDrawerAndSetCreditsForHuman() {
	logbook("cGameFactory:createNewGameDrawerAndSetCreditsForHuman [BEGIN]");
	if (gameDrawer) {
		gameDrawer->destroy();
		delete gameDrawer;
		gameDrawer = NULL;
	}

	gameDrawer = new GameDrawer(&player[HUMAN]);
	gameDrawer->getCreditsDrawer()->setCreditsOfPlayer();
	logbook("cGameFactory:createNewGameDrawerAndSetCreditsForHuman [END]");
}
Пример #4
0
void cGameFactory::createGameControlsContextsForPlayers() {
	logbook("cGameFactory:createGameControlsContextsForPlayers [BEGIN]");

	for (int i = HUMAN; i < MAX_PLAYERS; i++) {
		cPlayer * thePlayer = &player[i];
		thePlayer->setId(i);

		cGameControlsContext * gameControlsContext = new cGameControlsContext(thePlayer);
		thePlayer->setGameControlsContext(gameControlsContext);
	}

	logbook("cGameFactory:createGameControlsContextsForPlayers [END]");
}
Пример #5
0
int main()
{
    if (install())
        game.run();

    alfont_exit();
    logbook("Allegro FONT library shut down.");

    // Now we are all neatly closed, we exit Allegro and return to OS hell.
    allegro_exit();
    logbook("Allegro shut down.");
    logbook("\nThanks for playing!");
    return 0;
}
void cOrderProcesser::sendFrigate() {
	// iCll = structure start cell (up left), since we must go to the center
	// of the cell:
	cStructureUtils structureUtils;
	int structureId = structureUtils.findStarportToDeployUnit(player);

	if (structureId > -1) {
		// found structure
		structure[structureId]->setAnimating(true);
		int destinationCell = structure[structureId]->getCell();

		int iStartCell = cellCalculator->findCloseMapBorderCellRelativelyToDestinationCel(destinationCell);

		if (iStartCell < 0) {
			logbook("cOrderProcesser::sendFrigate : unable to find start cell to spawn frigate");
			setOrderHasBeenProcessed();
		} else {
			// STEP 2: create frigate
			int unitId = UNIT_CREATE(iStartCell, FRIGATE, player->getId(), true);
			// STEP 3: assign order to frigate (use carryall order function)
			unit[unitId].carryall_order(-1, TRANSFER_NEW_LEAVE, destinationCell, -1);
			unitIdOfFrigateSent = unitId;
			frigateSent = true;
		}
	} else {
		// no starport available
		setOrderHasBeenProcessed();
	}
}
Пример #7
0
/**
 * Scroll list up one item
 */
void cBuildingList::scrollUp() {
	logbook("cBuildingList::scrollUp");
	int offset = getScrollingOffset() - 1;
	if (offset > -1) {
		setScrollingOffset(offset);
	}
}
Пример #8
0
/**
 * Scroll list down one item
 */
void cBuildingList::scrollDown() {
	logbook("cBuildingList::scrollDown");
	int oldOffset = getScrollingOffset();
	int offset = oldOffset + 1;
	int max = maxItems - 4;

	char msg[255];
	sprintf(msg, "old offset is [%d], new offset is [%d], maxItems is [%d] max is [%d].", oldOffset, offset, maxItems, max);
	logbook(msg);

	if (offset <= max) {
		logbook("cBuildingList::scrolling down");
		setScrollingOffset(offset);
	} else {
		logbook("cBuildingList::scrolling down not allowed");
	}
}
/**
	Damage structure by amount of hp. The amount passed to this method
	must be > 0. When it is < 0, it will be wrapped to > 0 anyway and
	an error is written in the log.

	When the hitpoints drop below 1, the structure will die. The actual call
	to the die method will be done by the abstract think function. So it is
	still safe to refer to this structure even if it is declared dead (ie hp < 1).
**/
void cAbstractStructure::damage(int hp) {
	int damage = hp;
	if (damage < 0) {
		logbook("cAbstractStructuredamage() got negative parameter, wrapped");
		damage *= -1; // - * - = +
	}

	iHitPoints -= damage; // do damage

	// do not die here, that is not the responsibility of this method to determine
}
Пример #10
0
void cGameFactory::destroyAll() {
	logbook("cGameFactory:destroyAll [BEGIN]");
	delete mapUtils;
	mapUtils = NULL;
	delete map;
	map = NULL;
	delete mapCamera;
	mapCamera = NULL;

	gameDrawer->destroy();

	delete gameDrawer;
	gameDrawer = NULL;

//	for (int i = HUMAN; i < MAX_PLAYERS; i++) {
//		cPlayer * thePlayer = &player[i];
//		delete thePlayer;
//		thePlayer = NULL;
//	}


	logbook("cGameFactory:destroyAll [END]");
}
cMapCamera::cMapCamera() {
	int widthOfSidebar = 160;
	int heightOfOptions = 42;
	viewportWidth=((game.screen_x-widthOfSidebar)/TILESIZE_WIDTH_PIXELS);
	viewportHeight=((game.screen_y-heightOfOptions)/TILESIZE_HEIGHT_PIXELS)+1;
	x=y=1;
	targetX=targetY=1;
	TIMER_move=0;

	char msg[255];
	sprintf(msg, "Camera initialized. Viewport width is [%d], height [%d]. Position [%d,%d]", viewportWidth, viewportHeight, getX(), getY());
	logbook(msg);
	cellCalculator = new cCellCalculator(&map);
}
Пример #12
0
void cBuildingList::addItemToList(cBuildingListItem * item) {
	assert(item);

	if (isItemInList(item)) {
		logbook("Failed to add icon to cBuildingList, item is already in list.");
		// item is already in list, do not add
		return;
	}

	int slot = getFreeSlot();
	if (slot < 0) {
		logbook("Failed to add icon to cBuildingList, no free slot left in list");
		assert(false);
		return;
	}

	// add
	items[slot] = item;
	item->setSlotId(slot);
	maxItems = slot;
	//	char msg[355];
	//	sprintf(msg, "Icon added with id [%d] added to cBuilding list, put in slot[%d], set maxItems to [%d]", item->getBuildId(), slot, maxItems);
	//	logbook(msg);
}
/**
 * Set HP of structure, caps it at its maximum.
 */
void cAbstractStructure::setHitPoints(int hp) {
	iHitPoints = hp;
	int maxHp = structures[getType()].hp;

	if (iHitPoints > maxHp) {
		char msg[256];
		sprintf(msg, "setHitpoints(%d) while max is %d; capped at max.", hp, maxHp);
		logbook(msg);

		// will fail (uncomment to let it be capped)
		assert(iHitPoints <= maxHp); // may never be more than the maximum of that structure

		iHitPoints = maxHp;
	}

}
Пример #14
0
void cGameFactory::createMapClassAndNewDependenciesForGame(GameState state) {
	logbook("cGameFactory:createMapClassAndNewDependenciesForGame [BEGIN]");
    createMapClasses();
    createNewDependenciesForGame(state);
	logbook("cGameFactory:createMapClassAndNewDependenciesForGame [END]");
}
Пример #15
0
/* Processes timer functions */
void TIME_process()
{
    // fix any super high timers
    if (RUNNING_TIMER_fps > 10)
    {
        logbook("Exeptional high RUNNING_TIMER_FPS, fixed at max 10");
        RUNNING_TIMER_fps = 10;
    }

    if (RUNNING_TIMER_tenth > 40)
    {
        logbook("Exeptional high RUNNING_TIMER_TENTH, fixed at max 40");
        RUNNING_TIMER_tenth = 40;
    }

    // keep up with time cycles
    while (RUNNING_TIMER_fps > 0)
    {

        map.think();

        fps = frame_count;
        frame_count = 0;
        RUNNING_TIMER_fps--; // done!
    }


    // keep up with time cycles
    while (RUNNING_TIMER_tenth > 0)
    {
        // All particles die slowly!
        map.think_particles();
        map.think_clouds();

        // Players think
        for (int i=0; i < MAX_PLAYERS; i++)
            game.players[i].think();


        // Steam powered fading
        game.iSteamFade++;
        if (game.iSteamFade > 511)
            game.iSteamFade=0;

        if (game.iScrollSpeed > 0)
            game.iScrollSpeed--;

        // Scroll speeds up
        if (mouse_x >= 639)
            game.iScrollSpeed+=2;

        if (mouse_x <= 1)
            game.iScrollSpeed+=2;

        // Y
        if (mouse_y >= 479)
            game.iScrollSpeed+=2;

        if (mouse_y <= 1)
            game.iScrollSpeed+=2;

        if (game.iScrollSpeed > 16)
            game.iScrollSpeed = 16;

        RUNNING_TIMER_tenth--;
    }
}
Пример #16
0
// TODO: BECOMES OBSELETE, can be removed
void cGameFactory::createInteractionManagerForHumanPlayer(GameState state) {
	logbook("cGameFactory:createInteractionManagerForHumanPlayer [BEGIN]");
	logbook("cGameFactory:createInteractionManagerForHumanPlayer [END]");
}
Пример #17
0
/***
  Function : install()
  Returns  : TRUE on succes, FALSE on failure
  Purpose  : Will install game variables, sets up the entire game.
***/
bool install()
{
    // Each time we run the game, we clear out the logbook
    FILE *fp;
    fp = fopen("log.txt", "wt");

    if (fp)
    {
        fprintf(fp, "Counter-Strike 2D Logbook\n");
        fprintf(fp, "-------------------------\n\n"); // print head of logbook
        fclose(fp);
    }

    logbook("--------------");
    logbook("Initialization");
    logbook("--------------");

    // init game
    map.init();
    game.init();
    steam.init();

    logbook("Creating entity types.");
    game.install_entities();

    // Logbook notification
    logbook("\n-------");
    logbook("Allegro");
    logbook("-------");


    // ALLEGRO - INIT
    if (allegro_init() != 0)
        return false;

    logbook(allegro_id);
    yield_timeslice();
    logbook("yield_timeslice()");

    int r = install_timer();
    if (r > -1) logbook("install_timer()");
    else
    {
        logbook("FAILED");
        return false;
    }

    alfont_init();
    logbook("alfont_init()");
    install_keyboard();
    logbook("install_keyboard()");
    install_mouse();
    logbook("install_mouse()");

    logbook("setting up timer functions / locking functions & memory");
    /* set up the interrupt routines... */
    LOCK_VARIABLE(RUNNING_TIMER_tenth);
    LOCK_VARIABLE(RUNNING_TIMER_fps);
    LOCK_FUNCTION(timer_tenth);
    LOCK_FUNCTION(fps_proc);

    install_int(timer_tenth, 10);
    install_int(fps_proc, 1000);

    logbook("Timers installed");

    frame_count = fps = 0;


    // set window title
    char title[80];
    sprintf(title, "Counter-Strike 2D");

    // Set window title
    set_window_title(title);
    char window_title[256];
    sprintf(window_title, "Window title set: [%s]", title);
    logbook(window_title);

    set_color_depth(16);      // run in 16 bit mode
    if (game.windowed)
    {
        int r = set_gfx_mode(GFX_AUTODETECT_WINDOWED, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
        if (r > -1)
        {
            // Succes
        }
        else
        {
            // GFX_DIRECTX_ACCEL / GFX_AUTODETECT
            r = set_gfx_mode(GFX_DIRECTX_ACCEL, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
            if (r > -1)
            {
                game.windowed = false;
                logbook("Could not enter windowed-mode; settings.d3 adjusted");
            }
            else
            {
                logbook("ERROR - !");
                return false;
            }
        }
    }
    else
    {
        int r = set_gfx_mode(GFX_AUTODETECT, game.screen_x, game.screen_y, game.screen_x, game.screen_y);

        // succes
        if (r > -1)
        {

        }
        else
        {
            logbook("ERROR - !!");
            return false;
        }

    }


    text_mode(0);

    logbook("Loading font data");
    // loading font

    game_font = alfont_load_font("gfx\\font\\tahoma.ttf");

    if (game_font != NULL)
    {
        alfont_set_font_size(game_font, 20); // set size
    }
    else
        allegro_message("Error loading tahoma.ttf!");

    // CS Font
    cs_font = alfont_load_font("gfx\\font\\cs.ttf");

    if (cs_font != NULL)
    {
        alfont_set_font_size(cs_font, 20); // set size
    }
    else
        allegro_message("Error loading cs.ttf");

    alfont_text_mode(-1);

    if (set_display_switch_mode(SWITCH_BACKGROUND) < 0)
    {
        set_display_switch_mode(SWITCH_PAUSE);
        logbook("Display 'switch and pause' mode set");
    }
    else
        logbook("Display 'switch to background' mode set");

    // sound
    logbook("Initializing sound");
    int s = install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);

    /***
     Bitmap Creation
     ***/

    bmp_screen = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_screen == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_screen");
        return false;
    }
    else
        logbook("Bitmap created: bmp_screen");

    bmp_collide = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_collide == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_collide");
        return false;
    }
    else
        logbook("Bitmap created: bmp_collide");

    /*** End of Bitmap Creation ***/

    // load datafiles
    graphics = load_datafile("graphics.dat");
    if (graphics == NULL)
    {
        logbook("ERROR: Could not load datafile: graphics.dat");
        return false;
    }
    else
        logbook("Datafile loaded: graphics.dat");

    // Shadows
    shadows = load_datafile("shadows.dat");
    if (shadows == NULL)
    {
        logbook("ERROR: Could not load datafile: shadows.dat");
        return false;
    }
    else
        logbook("Datafile loaded: shadows.dat");

    // HUD
    hud = load_datafile("hud.dat");
    if (hud == NULL)
    {
        logbook("ERROR: Could not load datafile: hud.dat");
        return false;
    }
    else
        logbook("Datafile loaded: hud.dat");

    //set_color_conversion(COLORCONV_NONE);
    set_color_conversion(COLORCONV_MOST);
    logbook("Color conversion method set");

    // setup mouse speed
    set_mouse_speed(2,2);

    logbook("Mouse speed set");

    logbook("");
    logbook("----");
    logbook("GAME ");
    logbook("----");

    game.LOAD_TexturesFromDataFile("data//de_aztec.dat");
//  DATA_Init();

    // randomize timer
    srand( (unsigned)time( NULL ) );

    //srand(time(NULL));

    // normal sounds are loud, the music is lower (its background music, so it should not be disturbing)
    set_volume(255, 200);

    set_trans_blender(128, 128, 128, 128);

    logbook("");
    logbook("--------------");
    logbook("BATTLE CONTROL");
    logbook("--------------");
    logbook("\n3...2...1... GO!\n");
    return true;
}
// this structure dies
void cAbstractStructure::die()
{
    // find myself and set to zero
    int iIndex=-1;
	for (int i=0; i < MAX_STRUCTURES; i++) {
        if (structure[i] == this)
        {
            iIndex=i;
            break;
        }
	}

    if (iIndex < 0) {
        logbook("cAbstractStructure(): Could not die");
        return;
    }

    // selected structure
    if (game.selected_structure == iIndex) {
        game.selected_structure = -1;
    }

	// remove from array
    structure[iIndex]=NULL;

    // Destroy structure, take stuff in effect for the player
    player[iPlayer].iStructures[getType()]--; // remove from player building indexes

    // fix up power usage
    player[iPlayer].use_power -= structures[getType()].power_drain;

    // less power
    player[iPlayer].has_power -= structures[getType()].power_give;

	if (getType() == SILO) {
		player[iPlayer].max_credits -= 1000;
	}

	if (getType() == REFINERY) {
		player[iPlayer].max_credits -= 1500;
	}

    // UnitID > -1, means the unit inside will die too
    if (iUnitID > -1) {
        unit[iUnitID].init(iUnitID); // die here... softly
    }

	int iCll=iCell;
	int iCX=iCellGiveX(iCll);
	int iCY=iCellGiveY(iCll);

    // create destroy particles
    for (int w=0; w < iWidth; w++)
    {
        for (int h=0; h < iHeight; h++)
        {
			iCll=iCellMake(iCX+w, iCY+h);

			map.cell[iCll].type = TERRAIN_ROCK;
			mapEditor.smoothAroundCell(iCll);

			PARTICLE_CREATE(iDrawX() + (mapCamera->getX()*32) + (w*32) + 16,
				iDrawY() + (mapCamera->getY()*32) + (h*32) + 16, OBJECT_BOOM01, -1, -1);


            for (int i=0; i < 3; i++)
            {
				map.smudge_increase(SMUDGE_ROCK, iCll);

                // create particle
                PARTICLE_CREATE(iDrawX() + (mapCamera->getX()*32) + (w*32) + 16 + (-8 + rnd(16)),
                                iDrawY() + (mapCamera->getY()*32) + (h*32) + 16 + (-8 + rnd(16)), EXPLOSION_STRUCTURE01 + rnd(2), -1, -1);

                // create smoke
                if (rnd(100) < 7)
                    PARTICLE_CREATE(iDrawX() + (mapCamera->getX()*32) + (w*32) + 16 + (-8 + rnd(16)),
                                    iDrawY() + (mapCamera->getY()*32) + (h*32) + 16 + (-8 + rnd(16)), OBJECT_SMOKE, -1, -1);

                // create fire
                if (rnd(100) < 5)
                    PARTICLE_CREATE(iDrawX() + (mapCamera->getX()*32) + (w*32) + 16 + (-8 + rnd(16)),
                                    iDrawY() + (mapCamera->getY()*32) + (h*32) + 16 + (-8 + rnd(16)), EXPLOSION_FIRE, -1, -1);

            }
        }
    }

    // play sound
    play_sound_id(SOUND_CRUMBLE01 + rnd(2), iCellOnScreen(iCell));

    // remove from the playground
    map.remove_id(iIndex, MAPID_STRUCTURES);

    // screen shaking
    game.TIMER_shake = (iWidth * iHeight) * 20;

    // eventually die
    cStructureFactory::getInstance()->deleteStructureInstance(this);
}
void cRepairFacility::think()
{

    // Repair unit here (if any)
    if (iUnitID > -1)
    {
        // must repair...
        if (unit[iUnitID].iTempHitPoints < units[unit[iUnitID].iType].hp)
        {
            TIMER_repairunit++;

            if (TIMER_repairunit > 15)
            {
                TIMER_repairunit=0;

                if (player[getOwner()].credits > 2)
                {
                    unit[iUnitID].iTempHitPoints+=3;
                    player[getOwner()].credits--;

                    if (unit[iUnitID].iTempHitPoints >= units[unit[iUnitID].iType].hp)
                    {
                        unit[iUnitID].iHitPoints = units[unit[iUnitID].iType].hp;

                        // dump unit, get rid of it
                        int iNewCell = iFreeAround();

                        if (iNewCell > -1)
                        {
                            unit[iUnitID].iCell = iNewCell;
                        }
                        else
                            logbook("Could not find space for this unit");

                        // done & restore unit
                        unit[iUnitID].iStructureID = -1;

                        unit[iUnitID].iTempHitPoints = -1;

                        unit[iUnitID].iGoalCell = unit[iUnitID].iCell;
                        unit[iUnitID].iPathIndex = -1;

                        unit[iUnitID].TIMER_movewait = 0;
                        unit[iUnitID].TIMER_thinkwait = 0;

                        if (getRallyPoint() > -1)
                            unit[iUnitID].move_to(getRallyPoint(), -1, -1);

                        if (DEBUGGING)
                            assert(iUnitID > -1);

                        map.cell[unit[iUnitID].iCell].id[MAPID_UNITS] = iUnitID;


                        iUnitID=-1;


                    }
                }
            }
        }
    }

	// think like base class
	cAbstractStructure::think();

}