void UnitInterface::spawnPlayerUnits(const iXY &location,
                                     Uint16 player_id,
                                     const PlayerUnitConfig &unit_config)
{
    iXY next_loc;
    UnitBase *unit;
    unsigned long unit_type_index;
    unsigned long unit_spawn_count;
    unsigned long unit_spawn_index;

    NetMessageEncoder encoder;

    unit_placement_matrix.reset( location );

    for ( unit_type_index = 0; unit_type_index < UnitProfileInterface::getNumUnitTypes(); unit_type_index++ ) {

        unit_spawn_count = unit_config.getSpawnUnitCount( unit_type_index );
        for ( unit_spawn_index = 0; unit_spawn_index < unit_spawn_count; unit_spawn_index++ ) {
            unit_placement_matrix.getNextEmptyLoc( &next_loc );
            unit = createUnit(unit_type_index, next_loc, player_id);

            assert(unit != 0);
            UnitRemoteCreate create_mesg(unit->player->getID(), unit->id,
                    next_loc.x, next_loc.y, unit->unit_state.unit_type);
            encoder.encodeMessage(&create_mesg, sizeof(create_mesg));
        } // ** for unit_spawn_index
    } // ** for unit_type_index

    encoder.sendEncodedMessage();
}
Exemplo n.º 2
0
void            s_hello(SOCKET *sock, char *name, int put)
{
  char          *msg;
  char          buffer[SIZE_BUFFER];

  msg = malloc(100);
  create_mesg(msg, HELLO, name, NULL);
  x_send(*sock, msg);
  x_recv(*sock, buffer);
  if (put) {
    my_putstr(buffer);
  }
}
void BonusUnitPowerUp::onHit( UnitID unit_id )
{
    PlacementMatrix placement_matrix;
    iXY map_pos;

    sound->playPowerUpSound();

    UnitBase* unit = UnitInterface::getUnit(unit_id);

    MapInterface::pointXYtoMapXY( unit->unit_state.location, &map_pos );

    placement_matrix.reset( map_pos );


    for( int i = 0; i < 9; i++ )
    {
        UnitBase *new_unit;
        iXY spawn_loc;

        placement_matrix.getNextEmptyLoc( &spawn_loc );

        new_unit = UnitInterface::createUnit(bonus_unit_type,
                                             spawn_loc,
                                             unit->player->getID() );

        if ( new_unit != 0 )
        {
            UnitRemoteCreate create_mesg(new_unit->player->getID(),
                    new_unit->id, spawn_loc.x, spawn_loc.y, bonus_unit_type);
            SERVER->broadcastMessage( &create_mesg, sizeof( UnitRemoteCreate ));
        }

    }

    PowerUpHitMesg hit_mesg;
    hit_mesg.set( ID, unit->player->getID() );
    SERVER->broadcastMessage( &hit_mesg, sizeof( PowerUpHitMesg ));

    life_cycle_state = _power_up_lifecycle_state_inactive;

    if(unit->player == PlayerInterface::getLocalPlayer())
    {
        ConsoleInterface::postMessage(Color::unitAqua, false, 0, "YOU GOT A BONUS UNITS POWERUP" );
    }
}
void UnitInterface::spawnPlayerUnits(const iXY &location,
                                     PlayerID player_id,
                                     const PlayerUnitConfig &unit_config)
{
    iXY next_loc;
    UnitBase *unit;
    unsigned long unit_type_index;
    unsigned long unit_spawn_count;
    unsigned long unit_spawn_index;

    NetMessageEncoder encoder;

    unit_placement_matrix.reset( location );

    for ( unit_type_index = 0; unit_type_index < UnitProfileInterface::getNumUnitTypes(); unit_type_index++ )
    {

        unit_spawn_count = unit_config.getSpawnUnitCount( unit_type_index );
        for ( unit_spawn_index = 0; unit_spawn_index < unit_spawn_count; unit_spawn_index++ )
        {
            unit_placement_matrix.getNextEmptyLoc( &next_loc );
            unit = createUnit(unit_type_index, next_loc, player_id);
            UnitRemoteCreate create_mesg(unit->player->getID(), unit->id,
                    next_loc.x, next_loc.y, unit->unit_state.unit_type);

            if ( !encoder.encodeMessage(&create_mesg, sizeof(create_mesg)) )
            {
                LOGGER.info("UnitInterface encoder full, sending and resetting");
                SERVER->broadcastMessage(encoder.getEncodedMessage(),
                                         encoder.getEncodedLen());
                encoder.resetEncoder();
                encoder.encodeMessage(&create_mesg, sizeof(create_mesg));
            }
        } // ** for unit_spawn_index
    } // ** for unit_type_index

    if ( ! encoder.isEmpty() )
    {
        LOGGER.info("UnitInterface sending remaining");
        SERVER->broadcastMessage(encoder.getEncodedMessage(),
                                 encoder.getEncodedLen());
    }
}
Exemplo n.º 5
0
void
Objective::generateUnits()
{   // XXX CHECK
    if ( occupying_player && unit_generation_on_flag == true )
    {
        if( unit_generation_timer.count() == true )
        {
            UnitBase *unit;
            iXY gen_loc;
            gen_loc = outpost_map_loc + unit_generation_loc;

            unit = UnitInterface::createUnit(unit_generation_type,
                    gen_loc, occupying_player->getID());

            if ( unit != 0 )
            {
                UnitRemoteCreate create_mesg(unit->player->getID(),
                        unit->id, gen_loc.x, gen_loc.y,
                        unit_generation_type);
                SERVER->broadcastMessage(&create_mesg, sizeof(UnitRemoteCreate));

                UMesgAICommand ai_command;
                PlacementMatrix placement_matrix;
                iXY collection_loc, loc;

                collection_loc = /*outpost_map_loc +*/ unit_collection_loc;

                placement_matrix.reset( collection_loc );
                placement_matrix.getNextEmptyLoc( &loc );

                ai_command.setHeader( unit->id, _umesg_flag_unique );
                ai_command.setMoveToLoc( loc );
                UnitInterface::sendMessage( &ai_command );
            }
        } // ** if
    } // ** if
}