Esempio n. 1
0
void do_pod(shiptype *ship)
{
    reg int i;

    if(ship->whatorbits==LEVEL_STAR) {
        if (ship->special.pod.temperature >= POD_THRESHOLD) {
            i = int_rand(0,(int)Stars[ship->storbits]->numplanets - 1);
            sprintf(telegram_buf, "%s has warmed and exploded at %s\n",
                    Ship(ship), prin_ship_orbits(ship));
            if(infect_planet((int)ship->owner, (int)ship->storbits, i)) {
                sprintf(buf,"\tmeta-colony established on %s.",
                        Stars[ship->storbits]->pnames[i]);
            } else
                sprintf(buf,"\tno spores have survived.");
            strcat(telegram_buf, buf);
            push_telegram((int)(ship->owner), (int)ship->governor, telegram_buf);
            kill_ship((int)(ship->owner), ship);
        } else
            ship->special.pod.temperature +=
                round_rand((double)Stars[ship->storbits]->temperature/
                           (double)segments);
    } else if(ship->whatorbits==LEVEL_PLAN) {
        if(ship->special.pod.decay >= POD_DECAY) {
            sprintf(telegram_buf, "%s has decayed at %s\n", Ship(ship),
                    prin_ship_orbits(ship));
            push_telegram((int)ship->owner, (int)ship->governor, telegram_buf);
            kill_ship((int)ship->owner, ship);
        } else {
            ship->special.pod.decay += round_rand(1.0/(double)segments);
        }
    }
}
int main()
{
    
    Ship pirate_ship = Ship(0, 0, 0, Ship_Type::Pirate);
    Ship cargo_ship = Ship(0, 0, 1, Ship_Type::Cargo);
    Ship captured_ship = Ship(0, 0, 2, Ship_Type::Captured);
    Ship escort_ship = Ship(0, 0, 3, Ship_Type::Escort);
    Ship ship = Ship(10, 10, 1, Ship_Type::Pirate);

    int x = pirate_ship.Xpos();
    int y = pirate_ship.Ypos();

    std::cout << "Pirate Ship X pos: "<< x << "\n";
    std::cout << "Pirate Ship Y pos: "<< y << "\n";

    pirate_ship.Move();

    x = pirate_ship.Xpos();
    y = pirate_ship.Ypos();
    
    bool pred = ship < pirate_ship;

    std::cout << "Pirate Ship X pos: "<< x << "\n";
    std::cout << "Pirate Ship Y pos: "<< y << "\n";
    std::cout << "Return (0, 0) < (10, 10): "<<pred<< std::endl;
}
Esempio n. 3
0
void GameStateMachine::initialize(char key)
{
	_size = 10;

	_player = new HumanPlayer(1, _size);
	_root->addChild(_player->getOSGRoot());

	_shipList.push_back(Ship(CARRIER, 'c'));
	_shipList.push_back(Ship(DESTROYER, 'd'));

	_index = 0;

	_state = PLACESHIP;
}
Esempio n. 4
0
bool BaseAI::startTurn()
{
  static bool initialized = false;
  int count = 0;
  count = getShipTypeCount(c);
  shipTypes.clear();
  shipTypes.resize(count);
  for(int i = 0; i < count; i++)
  {
    shipTypes[i] = ShipType(getShipType(c, i));
  }

  count = getPlayerCount(c);
  players.clear();
  players.resize(count);
  for(int i = 0; i < count; i++)
  {
    players[i] = Player(getPlayer(c, i));
  }

  count = getShipCount(c);
  ships.clear();
  ships.resize(count);
  for(int i = 0; i < count; i++)
  {
    ships[i] = Ship(getShip(c, i));
  }

  if(!initialized)
  {
    initialized = true;
    init();
  }
  return run();
}
Esempio n. 5
0
Board::Board(const string &filename) // loads board from file 'filename'
{
	string leitura;
	char temp;

	ifstream fich(filename);
	
	fich >> numLines >> temp >> numColumns;

	while (!fich.eof())
	{
		char symbol, orientation;
		Position<char> position;  
		unsigned int size, color; 
		
		fich >> symbol >> size >> position.lin >> position.col >> orientation >> color;

		ships.push_back(Ship(symbol, position, orientation, size, color));
	}
	fich.close();
	
	for (int i = 0; i < numLines; i++)
	{
		vector<int> temp (numColumns, -1);
		board.push_back(temp);
	}
	
}
Esempio n. 6
0
void GameWidget::initLevel(int level)
{
    int salt = 0;
    m_ships.clear();

    int startY = qMin(20 + (level - 1) * 20, sizeY - 150 - 4 * 70);
    for (int row = 0; row < 4; ++row)
    {
        for(int col = 0; col < 10; ++col)
        {
            int def = (((level - 1) % 5) * 6) + ((row+col*level))%6;
            int pic = (row*col+salt)%6;
            m_ships.push_back(Ship(col * 75, startY + row * 70, row, col, &PicBucket::instance().getPic(def, pic).pixmap));
            salt += (rand() % 4);
        }
    }
    m_shots.clear();
    update(); // invalidate the whole screen

    m_shipTimeInt = 200;
    m_shipXHeading = 1;
    m_shipYheading = 0;
    m_gunY = sizeY - 65;
    m_bInteract = true;
    m_bSoserEnabled = true;
    stopSoser();

    emit levelChanged(level);
}
/*************************************************************************
* Function name: placeShip
* The Input: ship type
* The output: -
* The Function operation: places a ship of the spec. type on the player's board
*************************************************************************/
void ComputerPlayer::placeShip(int shipType) {
	// Generate random coordinates and try to create a ship there
	int x = rand() % 10;
	int y = rand() % 10;
	Coordinates * coords = new Coordinates(x, y);
	Ship ship = Ship(shipType, *coords);

	// Try again until we find a suitable place on the board
	while (!canPlaceShip(ship)) {
		coords->setX(rand() % 10);
		coords->setY(rand() % 10);
		ship = Ship(shipType, *coords);
	}

	// Add the ship to the board
	board->addShip(shipType, coords);
}
Esempio n. 8
0
void GameWindow::paintEvent(QPaintEvent *){

        QPainter painter(this);
        QPen pen;
        // Label home territory
        pen.setColor(Qt::blue);
        pen.setWidth(2);
        painter.setPen(pen);
        painter.setFont(QFont("Arial", 16));
        painter.drawText( homeX+150, 40, "Allied Waters");
        // Label enemy territory
        pen.setColor(Qt::red);
        pen.setWidth(2);
        painter.setPen(pen);
        painter.drawText( enemyX+150, 40, "Enemy Waters");
        // Draw the seas
        pen.setColor(Qt::blue);
        QBrush brush;
        brush.setColor(Qt::cyan);
        brush.setStyle(Qt::Dense4Pattern);
        painter.setBrush(brush);
        painter.setPen(pen);
        painter.drawRect( homeX, homeY, 400, 400);
        painter.drawRect( enemyX, enemyY, 400, 400);
        brush.setStyle(Qt::NoBrush);
        painter.setBrush(brush);
        // Draw webs on the seas
        drawWeb( painter, homeX, homeY, 80, 5);
        drawWeb( painter, enemyX, enemyY, 80, 5);
        drawFire( fireX, fireY);

        // Draw ships
        if( isServer ){
            Ship s = Ship( homeX, homeY, 3);
            s.blocks[1]=KILLED;
            drawShip(s);

        } else {
            Ship s = Ship( homeX, homeY, 3);
            drawShip(s);
        }

}
Esempio n. 9
0
void Fleet::changeShip(ShipPrototype& newship, int index)
{
    if (index < 0 || index > 4)
        throw std::out_of_range("Ship index out of range: must be [0, 4]");
    if (ships.find(index) == ships.end())
    {
        ships[index] = Ship(newship);
    }
    else
        ships[index].changeShip(newship);
}
Esempio n. 10
0
// обработка события OnTimer
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    // стереть кораблик - закрасить цветом, совпадающим
    // с цветом фона (формы)
    Canvas->Brush->Color = Form1->Color;
    Canvas->FillRect(Rect(x-1,y+1,x+68,y-40));

    // вычислить координаты базовой точки
    x+=3;
    if (x > ClientWidth) {
        // кораблик уплыл за правую границу формы
        x= -70; // чтобы кораблик "выплывал" из-за левой границы формы
        y=random(Form1->ClientHeight);
    }
    // нарисовать кораблик на новом месте
    Ship(x,y);
}
Esempio n. 11
0
Trader::Trader(SelectListener* a_pSelectListener)
:	Name(GetTraderName())
,	Money(1000)
,	MyShip(Ship())
	//
,	Decisiveness(rand()%100)
,	Restlessness(rand()%100)
,	Pride(rand()%100)
,	Caution(rand()%100)
,	Ambition(rand()%100)
,	RiskTaker(rand()%100)
	//
,	pSelectListener(a_pSelectListener)
{
	static int curId = 0;
	TraderUID = curId++;
	LocationUID = 0;
	DestinationUID = 0;
}
Esempio n. 12
0
void scrap(int playernum, int governor, int apcount)
{
    planettype *planet;
    sectortype *sect;
    shiptype *s;
    shiptype *s2;
    int shipno;
    int nextshipno;
    int scrapval = 0;
    int destval = 0;
    int crewval = 0;
    int max_crew = 0;
    int xtalval = 0;
    int troopval = 0;
    int max_resource = 0;
    int max_mil = 0;
    int max_fuel = 0;
    int max_destruct = 0;
    int cost = 0;
    double fuelval = 0.0;
    racetype *race;

    if (argn < 2) {
        notify(playernum, governor, "Scrap what?\n");

        return;
    }

    nextshipno = start_shiplist(playernum, governor, args[1]);
    race = races[playernum - 1];

    if (race->Guest) {
        notify(playernum, governor, "Guest races cannot scrap ships\n");

        return;
    }

    shipno = do_shiplist(&s, &nextshipno);

    while (shipno) {
        if (in_list(playernum, args[1], s, &nextshipno)) {
#ifdef USE_VN
            if ((s->type == OTYPE_VN) || (s->type == OTYPE_BERS)) {
                notify(playernum, governor, "VNs will not scrap themselves.\n");
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }
#endif

            if (s->max_crew && !s->popn) {
                notify(playernum,
                       governor,
                       "Can't scrap that ship - no crew.\n");

                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            if (s->whatorbits == LEVEL_UNIV) {
                /*
                 * Used to not allow scrapping at the UNIV level for
                 * anything. However, I'm going to permit pods. This is so pod
                 * races can clean up their messes. I'm not going to charge APs
                 * at the UNIV scope either. -mfw
                 */
                if (s->type) {
                    apcount = 0;
                } else {
                    notify(playernum,
                           governor,
                           "Can't scrap at the ship's scope.\n");

                    free(s);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }
            } else if (!enufAP(playernum, governor, Stars[s->storbits]->AP[playernum - 1], apcount)) {
                notify(playernum, governor, "Not enough APs to scrap.\n");
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            /* HUTm (kse) wc's can't be scrapped inside of ship anymore */
            if (inship(s) && (s->type == OTYPE_TOXIC)) {
                sprintf(buf,
                        "Can't scrap waste canisters inside of other ship.\n");

                notify(playernum, governor, buf);
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            /* Ships that have other ships in the hangar can't scrap *mfw */
            if (s->ships) {
                sprintf(buf,
                        "There are other ships in the hangar; scrap those first.\n");

                notify(playernum, governor, buf);
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            if ((s->whatorbits == LEVEL_PLAN) && (s->type == OTYPE_TOXIC)) {
                sprintf(buf,
                        "WARNING: This releases %d toxin points back into the atmosphere!!!\n",
                        s->special.waste.toxic);

                notify(playernum, governor, buf);
            }

            if (!s->docked) {
                sprintf(buf,
                        "%s is not landed or docked.\nNo resources can be reclaimed.\n",
                        Ship(s));

                notify(playernum, governor, buf);
            }

            if (s->whatorbits == LEVEL_PLAN) {
                /* wc's release poison */
                getplanet(&planet, (int)s->storbits, (int)s->pnumorbits);

                if (landed(s)) {
                    if (!getsector(&sect, planet, (int)s->land_x, (int)s->land_y)) {
                        notify(playernum,
                               governor,
                               "Error in sector database, notify deity.\n");

                        free(s);

                        return;
                    }
                }
            }

            if (docked(s) || inship(s)) {
                if (!getship(&s2, (int)s->destshipno)) {
                    free(s);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }

                if ((!s2->docked || (s2->destshipno != s->number))
                    && (!s->whatorbits == LEVEL_SHIP)) {
                    sprintf(buf, "Warning, other ship not docked...\n");
                    notify(playernum, governor, buf);
                    free(s);
                    free(s2);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }
            }

            if (s->type == OTYPE_FACTORY) {
                cost = (2 * s->build_code * s->on) + Shipdata[s->type][ABIL_COST];
            } else {
                cost = s->build_cost;
            }

            scrapval = (cost / 2) + s->resource;

            if (s->docked) {
                sprintf(buf, "%s: original cost: %ld\n", Ship(s), cost);
                notify(playernum, governor, buf);

                sprintf(buf,
                        "         scrap value%s: %d rp's.\n",
                        s->resource ? "(with stockpile) " : "",
                        scrapval);

                notify(playernum, governor, buf);

                /* New code by Kharush. check for STYPE_DHUTTLE added. */
                /* I've removed it, Dhuttle was silly -mfw */

                if (s2->type == OTYPE_FACTORY) {
                    max_resource = Shipdata[s2->type][ABIL_CARGO];
                    max_fuel = Shipdata[s2->type][ABIL_FUELCAP];
                    max_destruct = Shipdata[s2->type][DESTCAP];
                } else {
                    max_resource = s2->max_resource;
                    max_fuel = s2->max_fuel;
                    max_destruct = s2->max_destruct;
                }

                if ((s->whatdest == LEVEL_SHIP)
                    && ((s2->resource + scrapval) > max_resource)
                    && (s2->type != STYPE_SHUTTLE)) {
                    scrapval = max_resource - s2->resource;
                    sprintf(buf,
                            "(There is only room for %d resources.)\n",
                            scrapval);

                    notify(playernum, governor, buf);
                }

                if (s->fuel) {
                    sprintf(buf, "Fuel recover: %.0f.\n", s->fuel);
                    notify(playernum, governor, buf);
                    fuelval = s->fuel;

                    if ((s->whatdest == LEVEL_SHIP)
                        && ((s2->fuel + fuelval) > max_fuel)) {
                        fuelval = max_fuel - s2->fuel;
                        sprintf(buf,
                                "(There is only room for %.2f fuel.)\n",
                                fuelval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    fuelval = 0.0;
                }

                if (s->destruct) {
                    sprintf(buf, "Armament recovery: %d.\n", s->destruct);
                    notify(playernum, governor, buf);
                    destval = s->destruct;

                    if ((s->whatdest == LEVEL_SHIP)
                        && ((s2->destruct + destval) > max_destruct)) {
                        destval = max_destruct - s2->destruct;
                        sprintf(buf,
                                "(There is only room for %d destruct.)\n",
                                destval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    destval = 0;
                }

                if (s->popn + s->troops) {
                    if ((s->whatdest == LEVEL_PLAN)
                        && (sect->owner > 0)
                        && (sect->owner != playernum)) {
                        sprintf(buf,
                                "You don't own this sector; no crew can be recovered.\n");

                        notify(playernum, governor, buf);
                    } else {
                        troopval = s->troops;

                        if (s2->type == OTYPE_FACTORY) {
                            max_mil = Shipdata[s2->type][ABIL_MAXCREW] - s->popn;
                        } else {
                            max_mil = s2->max_crew - s2->popn;
                        }

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->troops + troopval) > max_mil)) {
                            troopval = max_mil - s2->troops;
                            sprintf(buf,
                                    "(There is only room for %d troops.)\n",
                                    troopval);

                            notify(playernum, governor, buf);
                        }

                        crewval = s->popn;

                        if (s2->type == OTYPE_FACTORY) {
                            max_crew = Shipdata[s2->type][ABIL_MAXCREW] - s2->troops;
                        } else {
                            max_crew = s2->max_crew - s2->troops;
                        }

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->popn + crewval) > max_crew)) {
                            crewval = max_crew - s2->popn;
                            sprintf(buf,
                                    "(There is only room for %d crew.)\n",
                                    crewval);

                            notify(playernum, governor, buf);
                        }

                        sprintf(buf,
                                "Population/Troops recover: %d/%d.\n",
                                crewval,
                                troopval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    crewval = 0;
                    troopval = 0;
                }

                if (s->crystals + s->mounted) {
                    if ((s->whatdest == LEVEL_PLAN)
                        && (sect->owner > 0)
                        && (sect->owner != playernum)) {
                        sprintf(buf,
                                "You don't own this sector; no crystals can be recovered.\n");

                        notify(playernum, governor, buf);
                    } else {
                        xtalval = s->crystals + s->mounted;

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->crystals + xtalval) > 127)) {
                            xtalval = 127 - s2->crystals;
                            sprintf(buf,
                                    "(There is only room for %d crystals.)\n",
                                    xtalval);

                            notify(playernum, governor, buf);
                        }

                        sprintf(buf, "Crystal recover: %d.\n", xtalval);
                        notify(playernum, governor, buf);
                    }
                } else {
                    xtalval = 0;
                }
            }

            /* More adjustments needed here for hangar. Maarten */
            if (s->whatorbits == LEVEL_SHIP) {
                s2->hangar -= (unsigned short)s->size;
            }

            if (s->whatorbits == LEVEL_UNIV) {
                deductAPs(playernum, governor, apcount, 0, 1);
            } else {
                deductAPs(playernum, governor, apcount, (int)s->storbits, 0);
            }

            if (docked(s) || inship(s)) {
                s2->crystals += xtalval;
                rcv_fuel(s2, (double)fuelval);
                rcv_destruct(s2, destval);
                rcv_resource(s2, scrapval);
                rcv_troops(s2, troopval, race->mass);
                rcv_popn(s2, crewval, race->mass);

                /*
                 * Check for docking status in case scrapped ship is
                 * landed. Maarten
                 */
                if (s->whatorbits != LEVEL_SHIP) {
                    s2->docked = 0; /* Undock the surviving ship */
                    s2->whatdest = LEVEL_UNIV;
                    s2->destshipno = 0;
                }

                putship(s2);
                free(s2);
            }

            if (s->whatorbits == LEVEL_PLAN) {
                free(planet); /* this has already been allocated */
                getplanet(&planet, (int)s->storbits, (int)s->pnumorbits);

                if (landed(s) || inship(s)) {
                    /*
                     * If colonizing the sector, set sector owner and give a
                     * message it's also nice to check if there is anyone to
                     * colonize
                     */
                    if ((sect->owner == 0)
                        && ((troopval > 0) || (crewval > 0))) {
                        sect->owner = playernum;
                        ++planet->info[playernum - 1].numsectsowned;
                        sprintf(buf,
                                "Sector %d,%d Colonized.\n",
                                s->land_x,
                                s->land_y);

                        notify(playernum, governor, buf);
                    }

                    /* Increase sector's crew and troop count */
                    sect->troops += troopval;
                    sect->popn += crewval;

                    /*
                     * Increase planet's crew, troop, res, tec. count for this
                     * player
                     */
                    planet->info[playernum - 1].popn += crewval;
                    planet->info[playernum - 1].troops += troopval;

                    /*
                     * New code by Kharush. Scrapping does not anymore overflow
                     * stockpiles.
                     */
                    if ((planet->info[playernum - 1].resource + scrapval) <= USHRT_MAX) {
                        planet->info[playernum - 1].resource += scrapval;
                    } else {
                        planet->info[playernum - 1].resource = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d resources.\n",
                                USHRT_MAX - planet->info[playernum - 1].resource);

                        notify(playernum, governor, buf);
                    }

                    if ((playernum->info[playernum - 1].fuel + fuelval) <= USHRT_MAX) {
                        planet->info[playernum - 1].fuel += fuelval;
                    } else {
                        planet->info[playernum - 1].fuel = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d fuel.\n",
                                USHRT_MAX - planet->info[playernum - 1].fuel);

                        notify(playernum, governor, buf);
                    }

                    if ((planet->info[playernum - 1].destruct + destval) <= USHRT_MAX) {
                        planet->info[playernum - 1].destruct += destval;
                    } else {
                        planet->info[playernum - 1].destruct = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d destruct.\n",
                                USHRT_MAX - planet->info[playernum - 1].destruct);

                        notify(playernum, governor, buf);
                    }

                    /*
                     * Old code
                     *
                     * planet->info[playernum - 1].resource += scrapval;
                     * planet->info[playernum - 1].destruct += destval;
                     * planet->info[playernum - 1].fuel += (int)fuelval;
                     */

                    plant->popn += crewval;
                    planet->info[playernum - 1].crystals += (int)xtalval;
                    putsector(sect, planet, (int)s->land_x, (int)s->land_y);
                    free(sect);
                }

                putplanet(planet, (int)s->storbits, (int)s->pnumorbits);
            }

            kill_ship(playernum, s);
            putship(s);
            free(s);

            if (landed(s)) {
                sprintf(buf, "\nScrapped.\n");
            } else {
                sprintf(buf, "\nDestroyed.\n");
            }

            notify(playernum, governor, buf);
        } else {
            free(s);
        }

        shipno = do_shiplist(&s, &nextshipno);
    }
}
Esempio n. 13
0
int GestionBateau::creerBateau(int tour,int dif)
{
    int nombre_bateau;
    switch(tour)//Le nombre de bateau dépend de la difficulté et du tour
    {
        case 1://tour 1
            switch(dif)
            {
                case 1://facile
                    nombre_bateau = 4;
                    break;
                case 2://moyen
                    nombre_bateau = 5;
                    break;
                case 3://difficile
                    nombre_bateau = 7;
                    break;
            }
            break;
        case 2:
        switch(dif)
            {
                case 1:
                    nombre_bateau = 6;
                    break;
                case 2:
                    nombre_bateau = 8;
                    break;
                case 3:
                    nombre_bateau = 10;
                    break;
            }
            break;
        case 3:
            switch(dif)
            {
                case 1:
                    nombre_bateau = 9;
                    break;
                case 2:
                    nombre_bateau = 11;
                    break;
                case 3:
                    nombre_bateau = 13;
                    break;
            }
            break;
        case 4:
            switch(dif)
            {
                case 1:
                    nombre_bateau = 11;
                    break;
                case 2:
                    nombre_bateau = 13;
                    break;
                case 3:
                    nombre_bateau = 16;
                    break;
            }
            break;
        default://tour >4
            switch(dif)
            {
                case 1:
                    nombre_bateau = 12;
                    break;
                case 2:
                    nombre_bateau = 16;
                    break;
                case 3:
                    nombre_bateau = 20;
                    break;
            }
            break;
    }

    for(int i=0;i<nombre_bateau;i++)
    {//Creation des bateaux
        CollisionManager colManager = CollisionManager(sf::Vector2f(800,600));
        //On prend une case d'eau au hasard
        int nbWaterCase = Map::Inst().getNbWaterCases();
        int nb_rand = rand()%nbWaterCase;
        sf::Vector2f vectorxy = Map::Inst().getRandomWaterCase(nb_rand);

        bool bool_ok = true;
        bool bool_col = false;
        //on cree un bateau temporaire a placer correctement
        Ship ship_temp = Ship(vectorxy,30,25,VITESSE_BATEAU);

        while(bool_ok)//Tant que la position de départ du bateau n'est pas valide
        {
            bool_ok=false;
            //On vérifie que le bateau n'entre pas en collision avec les frontieres
            if(colManager.testCollisionXShip(ship_temp) or colManager.testCollisionYShip(ship_temp))
            {
                bool_ok = true;
            }
            //On verifie que la position initiale n'entre en collision avec aucun autre bateau
            int i=0;
            while(i<tab_ship.size())
            {
                bool_col = colManager.testCollision(ship_temp,tab_ship[i]);
                if(bool_col)
                {
                    bool_ok=true;
                }
                i++;
            }

            if(bool_ok)//si le placement est invalide on en trouve un nouveau alétoirement
            {
                int nb_rand = rand()%nbWaterCase;
                sf::Vector2f vectorxy = Map::Inst().getRandomWaterCase(nb_rand);
                ship_temp.setPos(vectorxy);
            }
        }
        //Quand le bateau est bien placé , on l'ajoute au tableau
        tab_ship.push_back(ship_temp);

    }
    return 1;
}
Esempio n. 14
0
File: main.cpp Progetto: gigak/game
int main()
	{
		RenderWindow window (VideoMode (1200, 600), "SpiceCrip"); 


		Texture HeroShip;
		HeroShip.loadFromFile("ships.png"); 

		AnimationManager anim;
		//anim.create("fire", HeroShip, 195, 100, 71, 35, 1, 0.004, 35);

		anim.create("fly", HeroShip, 35, 42, 81, 80, 1, 0.004, 80);

		Texture Cosmos;
		Cosmos.loadFromFile("front.jpg");

		Texture CosmosTwo;
		CosmosTwo.loadFromFile("front.jpg");

		Texture Stars;
		Stars.loadFromFile("stars.png");

		

		PLAYER Ship(HeroShip);


		std::list<Bullet*> bullets; // список указателей пулей
		std::list<Bullet*>::iterator it;


		pBack fBack(Cosmos);
		//pBack sBack(Stars);
		pBack secondBack(CosmosTwo);
		fBack.pSprite.setPosition(0, 0);
		secondBack.pSprite.setPosition(0, -598);
		//sBack.pSprite.setRotation(20);
		//sBack.pSprite.setPosition(300,10);
		Clock clock;
		while (window.isOpen())
			{

				float time = clock.getElapsedTime().asMicroseconds();
				clock.restart();
				time = time/600;
				Event event;

				while (window.pollEvent(event))
					{ 
						if (event.type == Event::Closed)
						window.close();

						if(event.type == Event::KeyPressed)
							if (event.key.code==Keyboard::Space)
								   	bullets.push_back(new Bullet(Ship.sprite.getPosition().x - 73,Ship.sprite.getPosition().y - 30, 1,5) );	
				

					}

				
			
			

				if ((Keyboard::isKeyPressed(Keyboard::Left) || Keyboard::isKeyPressed(Keyboard::A)) & !(Ship.sprite.getPosition().x < 1)){
					Ship.sprite.move(-0.8*time,0);

				}

				if ((Keyboard::isKeyPressed(Keyboard::Right) || Keyboard::isKeyPressed(Keyboard::D)) & !(Ship.sprite.getPosition().x > 1070)){
					
					Ship.sprite.move(0.8*time,0);
					
				}

				if ((Keyboard::isKeyPressed(Keyboard::Down)  || Keyboard::isKeyPressed(Keyboard::S))  & !(Ship.sprite.getPosition().y > 540)){
					
					Ship.sprite.move(0,0.8*time);				
				}

				if ((Keyboard::isKeyPressed(Keyboard::Up)  || Keyboard::isKeyPressed(Keyboard::W))  & !(Ship.sprite.getPosition().y < 1) ){Ship.sprite.move(0,-0.8*time);}

					if ( fBack.pSprite.getPosition().y >= 598.f )
						fBack.pSprite.setPosition( 0.f, -598.f );
					if ( secondBack.pSprite.getPosition().y >= 598.f )
						secondBack.pSprite.setPosition( 0.f, -598.f );
				
	


			


				anim.tick(time);
				//Ship.update(time);
				window.clear();
				fBack.MoveBack();
				secondBack.MoveBack();

				//window.clear(Color::Black);
				window.draw(secondBack.pSprite);
				window.draw(fBack.pSprite);
			//	window.draw(sBack.pSprite);
				window.draw(Ship.sprite);


				for( it = bullets.begin(); it != bullets.end();  )
		        {
				   // ll whatsup = ( *it )->whatsup( enemys, score, time );
			        if( Ship.sprite.getPosition().y < 1 )
					{
						Bullet *deadBullet = *it;
						it = bullets.erase( it );
						delete deadBullet;
					}
			        else
			       {
				        ( *it )->draw( window, time );
				        ++it;
						
			        }
				}




				window.display();

			
   }

   return 0;
}
Esempio n. 15
0
void do_pod(shiptype *ship)
{
    int starsys;
    int planetno;

    memset((char *)buf, 0, sizeof(buf));

    if (ship->popn != 0) {
        if (ship->whatorbits == LEVEL_STAR) {
            if (ship->special.pod.temperature >= POD_THRESHOLD) {
                starsys = ship->storbits;
                planetno = int_rand(0, (int)Stars[starsys]->numplanets - 1);
                sprintf(telegram_buf,
                        "%s has warmed and exploded at %\n",
                        Ship(ship),
                        prin_ship_orbits(ship));

                /* Seed passes through wormhole */
                if (Stars[starsys]->wh_has_wormhole
                    && (planetno == (Stars[starsys]->numplanets - 1))) {
                    planets[starsys][planetno]->info[ship->owner - 1].explored = 1;
                    starsys = Stars[starsys]->wh_dest_starnum;
                    planetno = int_rand(0, (int)Stars[starsys]->numplanets - 2);
                    sprintf(buf,
                            "                          The spores traversed a wormhole to %s.\n",
                            Stars[starsys]->name);

                    strcat(telegram_buf, buf);
                }

                if (infect_planet((int)ship->type, (int)ship->owner, starsys, planetno)) {
                    sprintf(buf,
                            "                          Meta-colony established on %s.",
                            Stars[starsys]->pnames[planetno]);
                } else {
                    sprintf(buf, "                          No spores have survived.");
                }

                strcat(telegram_buf, buf);
                push_telegram((int)ship->owner,
                              (int)ship->governor,
                              telegram_buf);

                kill_ship((int)ship->owner, ship);
            } else {
                /* pod.temp >= POD_THRESHOLD */
                ship->special.pod.temperature += round_rand((double)Stars[ship->storbits]->temperature / (double)segments);
            }
        } else if (ship->whatorbits == LEVEL_PLAN) {
            if (ship->special.pod.decay >= POD_DECAY) {
                starsys = ship->storbits;
                planetno = ship->pnumorbits;
                sprintf(telegram_buf,
                        "%s has decayed at %s\n",
                        Ship(ship),
                        prin_ship_orbits(ship));

                /* Seed passes through wormhole */
                if (Stars[starsys]->wh_has_wormhole
                    && (planetno == (Stars[starsys]->numplanets - 1))) {
                    starsys = Stars[starsys]->wh_dest_starnum;
                    planetno = int_rand(0, (int)Stars[starsys]->numplanets - 2);
                    sprintf(buf,
                            "                          The spores traversed a wormhole to %s.\n",
                            Stars[starsys]->name);

                    strcat(telegram_buf, buf);
                }

                if (infect_planet((int)ship->type, (int)ship->owner, starsys, planetno)) {
                    sprintf(buf,
                            "                          Meta-colony established on %s.",
                            Stars[starsys]->pnames[planetno]);
                } else {
                    sprintf(buf, "                          No spores have survived.");
                }

                strcat(telegram_buf, buf);
                push_telegram((int)ship->owner,
                              (int)ship->governor,
                              telegram_buf);

                kill_ship((int)ship->owner, ship);
            } else {
                /* decay > POD_DECAY */
                ship->special.pod.decay += round_rand(1.0 / (double) segments);
            }
        }
    } else {
        /* If no population on board, don't infect! --jpd-- */
        /* Don't decay if military on board. */
        if (!ship->troops) {
            sprintf(telegram_buf,
                    "%s has no population and has decayed at %s\n",
                    Ship(ship),
                    prin_ship_orbits(ship));

            push_telegram((int)ship->owner, (int)ship->governor, telegram_buf);
            kill_ship((int)ship->owner, ship);
        }
    } /* If ship->popn != 0 --jpd -- */
}
Esempio n. 16
0
void do_mirror(shiptype *ship)
{
    switch (ship->special.aimed_at.level) {
    case LEVEL_SHIP: /* ship aimed at is a legal ship now */
        /* if in the same system */
        if ( (ship->whatorbits==LEVEL_STAR || ship->whatorbits==LEVEL_PLAN)
                && (ships[ship->special.aimed_at.shipno]!=NULL)
                && (ships[ship->special.aimed_at.shipno]->whatorbits==LEVEL_STAR ||
                    ships[ship->special.aimed_at.shipno]->whatorbits==LEVEL_PLAN)
                && ship->storbits == ships[ship->special.aimed_at.shipno]->storbits
                && ships[ship->special.aimed_at.shipno]->alive ) {
            shiptype *s;
            reg int i;
            double range;
            s = ships[ship->special.aimed_at.shipno];
            range = sqrt(Distsq(ship->xpos, ship->ypos,s->xpos,s->ypos));
            i = int_rand(0,round_rand((2./((double)(Body(s))))
                                      *(double)(ship->special.aimed_at.intensity)/(range/PLORBITSIZE+1.0)));
            sprintf(telegram_buf, "%s aimed at %s\n", Ship(ship), Ship(s));
            s->damage += i;
            if(i) {
                sprintf(buf, "%d%% damage done.\n",i);
                strcat(telegram_buf, buf);
            }
            if (s->damage >= 100) {
                sprintf(buf, "%s DESTROYED!!!\n",Ship(s));
                strcat(telegram_buf, buf);
                kill_ship((int)(ship->owner), s);
            }
            push_telegram((int)s->owner, (int)s->governor, telegram_buf);
            push_telegram((int)ship->owner, (int)ship->governor, telegram_buf);
        }
        break;
    case LEVEL_PLAN: {
        reg int i;
        double range;
        range = sqrt(Distsq(ship->xpos, ship->ypos,
                            Stars[ship->storbits]->xpos
                            +planets[ship->storbits][ship->pnumorbits]->xpos,
                            Stars[ship->storbits]->ypos
                            +planets[ship->storbits][ship->pnumorbits]->ypos));
        if ( range > PLORBITSIZE )
            i = PLORBITSIZE * ship->special.aimed_at.intensity/range;
        else
            i = ship->special.aimed_at.intensity;

        i = round_rand(.01*(100.0-(double)(ship->damage))*(double)i);
        Stinfo[ship->storbits][ship->special.aimed_at.pnum].temp_add += i;
    }
    break;
    case LEVEL_STAR: {
        /* have to be in the same system as the star; otherwise
           it's not too fair.. */
        if (ship->special.aimed_at.snum>0 && ship->special.aimed_at.snum < Sdata.numstars &&
                ship->whatorbits > LEVEL_UNIV &&
                ship->special.aimed_at.snum == ship->storbits)
            Stars[ship->special.aimed_at.snum]->stability += random()&01;
    }
    break;
    case LEVEL_UNIV:
        break;
    }
}
Esempio n. 17
0
void domissile(shiptype *ship)
{
    int sh2;
    int bombx, bomby, numdest, pdn, i;
    planettype *p;
    double dist;
    placetype where;

    if(!ship->alive || !ship->owner)  return;
    if(!ship->on || ship->docked) return;

    /* check to see if it has arrived at it's destination */
    if(ship->whatdest==LEVEL_PLAN && ship->whatorbits==LEVEL_PLAN &&
            ship->destpnum==ship->pnumorbits) {
        p=planets[ship->storbits][ship->pnumorbits];
        /* check to see if PDNs are present */
        pdn = 0;
        sh2 = p->ships;
        while(sh2 && !pdn) {
            if(ships[sh2]->alive && ships[sh2]->type==OTYPE_PLANDEF) {
                /* attack the PDN instead */
                ship->whatdest=LEVEL_SHIP;	/* move missile to PDN for attack */
                ship->xpos=ships[sh2]->xpos;
                ship->ypos=ships[sh2]->ypos;
                ship->destshipno = sh2;
                pdn = sh2;
            }
            sh2 = ships[sh2]->nextship;
        }
        if(!pdn) {
            if(ship->special.impact.scatter) {
                bombx = int_rand(1,(int)p->Maxx)-1;
                bomby = int_rand(1,(int)p->Maxy)-1;
            } else {
                bombx = ship->special.impact.x % p->Maxx;
                bomby = ship->special.impact.y % p->Maxy;
            }
            sprintf(buf, "%s dropped on sector %d,%d at planet %s.\n",
                    Ship(ship), bombx, bomby, prin_ship_orbits(ship));
            where.level = LEVEL_PLAN;
            where.snum = ship->storbits;
            where.pnum = ship->pnumorbits;

            numdest = shoot_ship_to_planet(ship, p, (int)ship->destruct,
                                           bombx, bomby, 1, 0, HEAVY,
                                           long_buf, short_buf);
            push_telegram((int)ship->owner, (int)ship->governor, long_buf);
            kill_ship((int)ship->owner, ship);
            sprintf(buf, "%s dropped on %s.\n\t%d sectors destroyed.\n",
                    Ship(ship), prin_ship_orbits(ship), numdest);
            for (i=1; i<=Num_races; i++)
                if(p->info[i-1].numsectsowned && i!=ship->owner)
                    push_telegram(i, Stars[ship->storbits]->governor[i-1], buf);
            if(numdest) {
                sprintf(buf, "%s dropped on %s.\n", Ship(ship),
                        prin_ship_orbits(ship));
                post(buf, COMBAT);
            }
        }
    } else if(ship->whatdest==LEVEL_SHIP) {
        sh2=ship->destshipno;
        dist=sqrt(Distsq(ship->xpos, ship->ypos,
                         ships[sh2]->xpos, ships[sh2]->ypos));
        if(dist<=((double)ship->speed*STRIKE_DISTANCE_FACTOR
                  *(100.0-(double)ship->damage)/100.0)) {
            /* do the attack */
            (void)shoot_ship_to_ship(ship, ships[sh2], (int)ship->destruct, 0, 0,
                                     long_buf, short_buf);
            push_telegram((int)ship->owner, (int)ship->governor, long_buf);
            push_telegram((int)ships[sh2]->owner, (int)ships[sh2]->governor,
                          long_buf);
            kill_ship((int)ship->owner, ship);
            post(short_buf, COMBAT);
        }
    }
}
Esempio n. 18
0
void domine(int shipno, int detonate)
{
    int sh,sh2,i;
    shiptype *s, *ship;
    planettype *planet;
    racetype *r;

    (void)getship(&ship, shipno);

    if(ship->type!=STYPE_MINE || !ship->alive || !ship->owner) {
        free(ship);
        return;
    }
    /* check around and see if we should explode. */
    if (ship->on || detonate) {
        int rad=0;
        double xd,yd,range;

        switch(ship->whatorbits) {
        case LEVEL_STAR:
            sh = Stars[ship->storbits]->ships;
            break;
        case LEVEL_PLAN:
            getplanet(&planet, (int)ship->storbits, (int)ship->pnumorbits);
            sh=planet->ships;
            free(planet);
            break;
        default:
            free(ship);
            return;
        }
        sh2 = sh;
        /* traverse the list, look for ships that
        are closer than the trigger radius... */
        rad = 0;
        if(!detonate) {
            r = races[ship->owner-1];
            while (sh && !rad) {
                (void)getship(&s, sh);
                xd = s->xpos - ship->xpos;
                yd = s->ypos - ship->ypos;
                range = sqrt(xd*xd + yd*yd);
                if( !isset(r->allied, s->owner) && (s->owner != ship->owner) &&
                        ( (int)range <= ship->special.trigger.radius) )
                    rad = 1;
                else
                    sh = s->nextship;
                free(s);
            }
        } else
            rad = 1;

        if (rad) {
            sprintf(buf, "%s detonated at %s\n",
                    Ship(ship), prin_ship_orbits(ship));
            post(buf, COMBAT);
            notify_star((int)ship->owner, (int)ship->governor, 0,
                        (int)ship->storbits, buf);
            sh = sh2 ;
            while (sh) {
                (void)getship(&s, sh);
                if (sh != shipno && s->alive &&
                        (s->type != OTYPE_CANIST) && (s->type!=OTYPE_GREEN)) {
                    rad = shoot_ship_to_ship(ship, s, (int)(ship->destruct), 0, 0,
                                             long_buf, short_buf);
                    if(rad>0) {
                        post(short_buf, COMBAT);
                        warn((int)s->owner, (int)s->governor, long_buf);
                        putship(s);
                    }
                }
                sh = s->nextship;
                free(s);
            }

            /* if the mine is in orbit around a planet, nuke the planet too! */
            if(ship->whatorbits==LEVEL_PLAN) {
                /* pick a random sector to nuke */
                reg int x,y,numdest;
                getplanet(&planet, (int)ship->storbits, (int)ship->pnumorbits);
                if(landed(ship)) {
                    x = ship->land_x;
                    y = ship->land_y;
                } else {
                    x=int_rand(0, (int)planet->Maxx-1);
                    y=int_rand(0, (int)planet->Maxy-1);
                }
                numdest=shoot_ship_to_planet(ship, planet,
                                             (int)(ship->destruct), x, y, 1, 0, LIGHT,
                                             long_buf, short_buf);
                putplanet(planet, (int)ship->storbits, (int)ship->pnumorbits);

                sprintf(telegram_buf, "%s", buf);
                if(numdest>0) {
                    sprintf(buf, " - %d sectors destroyed.",numdest);
                    strcat(telegram_buf, buf);
                }
                strcat(telegram_buf, "\n");
                for(i=1; i<=Num_races; i++)
                    if(Nuked[i-1])
                        warn(i, (int)Stars[ship->storbits]->governor[i-1],
                             telegram_buf);
                notify((int)(ship->owner), (int)ship->governor, telegram_buf);
                free(planet);
            }
            kill_ship((int)(ship->owner), ship);
        }
        putship(ship);
    }
    free(ship);
}
Esempio n. 19
0
/*************************************************************************
* Function name: addShip
* The Input: ship's type and first block's coordinates
* The output: -
* The Function operation: adds the specified ship
*************************************************************************/
void Board::addShip(const int shipType, const Coordinates* coords) {
	ships.push_back(Ship(shipType, *coords));
	delete coords;
}
Esempio n. 20
0
void ShipFactory::CreateShip(const std::string& alias, const std::string& name, int metal, int crystal, int deuterium)
{
  std::pair<const std::string, Ship> m_pair(alias, Ship(name, metal, crystal, deuterium));
  m_ships.insert(m_pair);
}
Esempio n. 21
0
/* Ship #shipno bombards planet, then alert whom it may concern. */
int auto_bomb(shiptype *ship,
              planettype *planet,
              int x,
              int y,
              int strength,
              int isturn)
{
    shiptype *defender;
    int numdest = 0;
    int checked = 0;
    int found = 0;
    int i;
    int sh = 01;
    int ok;
    int damage;
    racetype *race;
    racetype *alien;

#ifdef USE_VN
    shiptype pdn;
    int amount_to_shoot;
    int rez;
    int retal;
#endif

#ifdef USE_WORMHOLE
    if (planet->type == TYPE_WORMHOLE) {
        return -1;
    }
#endif

    race = races[ship->owner - 1];

    /* Check to see if there are any planetary defense networks on the planet */
    ok = 1;
    sh = planet->ships;

    while (sh && ok) {
        if (isturn) {
            defender = ships[sh];
        } else {
            getship(&defender, sh);
        }

        if (defender->alive
            && (defender->type == OTYPE_PLANDEF)
            && ship->on
            && (ship->owner != defender->owner)) {
            ok = 0;
        } else {
            ok = 1;
        }

#ifdef USE_VN
        /* CWL berserker take a pot shot at PDNs */
        if (!ok && (type->type == OTYPE_BERS)) {
            rez = 1;

            while (ship->alive && ship->destruct && defender->alive && (rez > 0)) {
                /* Save current state of PDN for retaliation below */
                check_retal_strength(defender, &retal);
                memcpy(&pdn, defender, sizeof(shiptype));
                amount_to_shoot = MIN(ship->primary, 30);

                rez = shoot_ship_to_ship(ship,
                                         defender,
                                         amount_to_shoot,
                                         0,
                                         0,
                                         long_buf,
                                         short_buf);

                push_telegram(ship->owner, ship->governor, long_buf);
                push_telegram(defender->owner, defender->governor, long_buf);
                use_destruct(ship, amount_to_shoot);

                if (!defender->alive) {
                    post(short_buf, COMBAT);
                }

                /* PDN gets a turn to retaliate */
                if (retal && rez && defender->protect.self) {
                    shoot_ship_to_ship(&pdn,
                                       ship,
                                       retal,
                                       0,
                                       1,
                                       long_buf,
                                       short_buf);

                    push_telegram(defender->owner,
                                  defender->governor,
                                  long_buf);

                    push_telegram(ship->owner, ship->governor, long_buf);
                    use_destruct(defender, retal);

                    if (!ship->alive) {
                        post(short_buf, COMBAT);
                    }
                }
            }

            ok = 1;

            if (!isturn) {
                putship(defender);
            }
        }
        /* End CWL */
#endif

        sh = nextship(defender);

        if (!isturn) {
            free(defender);
        }

#ifdef USE_VN
        /* Berserker was killed or out of ammo, let's return */
        if (!ship->alive || !ship->destruct) {
            return 0;
        }
#endif
    }

    if (!ok && !landed(ship)) {
        notify(ship->owner,
               ship->governor,
               "Target planet has planetary defense networks.\nThese have to be eliminated before you can attack sectors.\n");

        return 0;
    }

    if ((x < 0) || (y < 0)) {
        x = 0;
        y = ;

        /* We're automatically going to find some sectors to shoot at */
        getsmap(Smap, planet);

        /* Look for someone to bombard - check for war */
        Getxysect(planet, 0, 0, 1); /* Reset */

        while (!found && Getxysect(planet, &x, &y, 0)) {
            if (Sector(*planet, x, y).owner
                && (Sector(*planet, x, y).owner != ship->owner)
                && (Sector(*planet, x, y).condition != WASTED)) {
                checked = 1;

                if (isset(Race->atwar, Sector(*planet, x, y).owner)) {
                    found = 1;
                }

#ifdef USE_VN
                if ((ship->type == OTYPE_BERS)
                    && (Sector(*planet, x, y).owner == ship->special.mind.target)) {
                    found = 1;
                }
#endif
            }
        }

        if (checked && !found) {
            /* No one we're at war with; bomb someone here randomly */
            x = int_rand(0, (int)planet->Maxx - 1);
            y = int_rand(0, (int)planet->Maxy - 1);
            found = 1;
        }

        if (!checked) {
            /* There were no sectors worth bombing */
            if (!ship->notified) {
                ship->notified = 1;

                sprintf(buf,
                        "%s reports /%s/%s has already been saturation bombed.\n",
                        Ship(ship),
                        Stars[ship->storbits]->name,
                        Stars[ship->storbits].->pnames[ship->pnumorbits]);

                notify(ship->owner, ship->governor, buf);

                return 01;
            }
        }
Esempio n. 22
0
File: name.c Progetto: phreddrick/GB
void give(int Playernum, int Governor, int APcount)
{
  int who, sh;
  shiptype *ship;
  planettype *planet;
  racetype *Race, *alien;

  if(!(who=GetPlayer(args[1]))) {
    sprintf(buf,"No such player.\n");
    notify(Playernum, Governor, buf);
    return;
  }
  if(Governor) {
      notify(Playernum, Governor, "You are not authorized to do that.\n");
      return;
  }
  alien = races[who-1];
  Race = races[Playernum-1];
  if(alien->Guest && !Race->God) {
      notify(Playernum, Governor, "You can't give this player anything.\n");
      return;
  }
  if(Race->Guest) {
      notify(Playernum, Governor, "You can't give anyone anything.\n");
      return;
  }
  /* check to see if both players are mutually allied */
  if(!Race->God &&
     !(isset(Race->allied, who) && isset(alien->allied, Playernum))) {
    notify(Playernum, Governor, "You two are not mutually allied.\n");
    return;
  }
  sscanf(args[2]+(args[2][0]=='#'), "%d", &sh);

  if(!getship(&ship, sh)) {
    notify(Playernum, Governor, "Illegal ship number.\n");
    return;
  }

  if(ship->owner != Playernum || !ship->alive) {
    DontOwnErr(Playernum, Governor, sh);
    free(ship);
    return;
  }
  if(ship->type == STYPE_POD) {
    notify(Playernum, Governor, "You cannot change the ownership of spore pods.\n");
    free(ship);
    return;
  }

  if((ship->popn+ship->troops) && !Race->God) {
    notify(Playernum, Governor, "You can't give this ship away while it has crew/mil on board.\n");
    free(ship);
    return;
  }
  if(ship->ships && !Race->God) {
      notify(Playernum, Governor, "You can't give away this ship, it has other ships loaded on it.\n");
      free(ship);
      return;
  }
  switch(ship->whatorbits) {
  case LEVEL_UNIV:
    if(!enufAP(Playernum,Governor, Sdata.AP[Playernum-1], APcount)) {
      free(ship);
      return;
    }
    break;
  default:
    if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) {
      free(ship);
      return;
    }
    break;
  }

  ship->owner = who;
  ship->governor = 0;	/* give to the leader */
  capture_stuff(ship);

  putship(ship);

  /* set inhabited/explored bits */
  switch(ship->whatorbits) {
    case LEVEL_UNIV:
      break;
    case LEVEL_STAR:
      getstar(&(Stars[ship->storbits]), (int)ship->storbits);
      setbit(Stars[ship->storbits]->explored, who);
      putstar(Stars[ship->storbits], (int)ship->storbits);
      break;
    case LEVEL_PLAN:
      getstar(&(Stars[ship->storbits]), (int)ship->storbits);
      setbit(Stars[ship->storbits]->explored, who);
      putstar(Stars[ship->storbits], (int)ship->storbits);

      getplanet(&planet, (int)ship->storbits,(int)ship->pnumorbits);
      planet->info[who-1].explored = 1;
      putplanet(planet, (int)ship->storbits,(int)ship->pnumorbits);
      free(planet);

      break;
    default:
      notify(Playernum, Governor, "Something wrong with this ship's scope.\n");
      free(ship);
      return;
      break;
  }

  switch(ship->whatorbits) {
    case LEVEL_UNIV:
      deductAPs(Playernum, Governor,  APcount, 0, 1);
      free(ship);
      return;
      break;
    default:
      deductAPs(Playernum, Governor, APcount, Dir[Playernum-1][Governor].snum, 0);
      break;
  }
  notify(Playernum, Governor, "Owner changed.\n");
  sprintf(buf, "%s [%d] gave you %s at %s.\n", Race->name, Playernum,
	  Ship(ship), prin_ship_orbits(ship));
  warn(who, 0, buf);

if (!Race->God) {
  sprintf(buf, "%s [%d] gives %s [%d] a ship.\n", Race->name,
	  Playernum, alien->name, who);
  post(buf, TRANSFER);
  free(ship);
}
}