Beispiel #1
0
ship_t *shCreateShip(char *name, pos_t *pos, int team, int netid, float time) {
	ship_t *newship;

	printf("create new ship[%s], id %d\n", name, netid);

	newship = malloc(sizeof(ship_t));
	memset(newship, 0, sizeof(ship_t));
	newship->t = cfGetShip(name);
	newship->traj.base = *pos;
	newship->pos = *pos;
	newship->traj.type = t_linear;
	newship->traj.basetime = time;
	newship->team = team;
	newship->health = newship->t->maxhealth;
	newship->netid = netid;
	newship->thrusttime = time;

	if (newship->t->numturret)
		tuAddTurret(newship);

	if (newship->t->numparts) {
		int i;

		newship->part = malloc(sizeof(part_t) * newship->t->numparts);
		memset(newship->part, 0, sizeof(part_t) * newship->t->numparts);
		for (i = 0; i < newship->t->numparts; i++)
			newship->part[i].health = newship->t->part->part->maxhealth;
	}
	addShip(newship);
	return newship;
}
ShipHull* GameControl::createShip(Grid3D* grid, std::vector<size_t> coords, std::string type)
{
	//
	auto player = getActivePlayer();
	auto ship_index = mListSelections[player];
	if (mShipNumbers[ship_index] == 0 && type == "")
		return NULL;
	if (type == "")
		mShipNumbers[ship_index]--;
	// Get which type need to be made
	if (type == "")
		type = mShipyard.getNameOfShipType(ship_index);
	auto ship = mShipyard.createShip(type, grid);
	if (ship)
	{
		// Model
		if (getGamePhase() == GP_SET)
		{
			auto result = AstrOWar::GameModelSingleton.addShipToModel(type, coords[0], coords[1], coords[2]);
			addShip(result.resume, ship);
			cout << "Add Ship ErrCode: " << result.errorCode << endl;
		}
		moveShipTo(ship, coords);
		onShipCreated();
	}
	return ship;
}
void Player::purchaseShip()
{
    if(darkResources < SHIP_COST)
        return;
    if(addShip(home))
        darkResources-=SHIP_COST;
}
Beispiel #4
0
bool HelloWorld::init()
{
    if ( !CCLayer::init()){
        return false;
    }

    //init ECS
    initEntitySystem();
    Size size=CCDirector::getInstance()->getVisibleSize();
    LayerColor* colorLayer=LayerColor::create(Color4B(255,255,255,255),size.width,size.height);
    addChild(colorLayer,-1);    
    //船    
	addShip();
	addHelp(Point(_ship->getPositionX()+200,_ship->getPositionY()));
    //addHelp(Point(_ship->getPositionX()-200,_ship->getPositionY()));
    //addHelp(Point(_ship->getPositionX(),_ship->getPositionY()-200));

    
    // 监听鼠标点击
    auto listener=EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE);
    listener->setSwallowTouches(true);
    listener->onTouchBegan=CC_CALLBACK_2(HelloWorld::onTouchBegin,this);
    listener->onTouchEnded= CC_CALLBACK_2(HelloWorld::onTouchEnded,this);
    EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, -10);
    
    //监听子弹事件
    auto listener1=EventListenerCustom::create(GunEvent::GUN_EVENT_TYPE, CC_CALLBACK_1(HelloWorld::addbullet,this));
    EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener1, 1);
    
	//显式
	Label* lblTime = Label::createWithTTF("", "fonts/Marker Felt.ttf", 40);
    lblTime->setColor(Color3B::RED);
    addChild(lblTime);
    lblTime->setPosition(Point(size.width-100,size.height-100));
    
    //游戏结束
    Entity* gameOver = _entityManager->createEntity();
    _entityManager->addComponentToEntity(GameOverComponent::create(100,lblTime), gameOver);
    _entityManager->addComponentToEntity(RenderComponent::create(this), gameOver);
    
    scheduleUpdate();
    
    return true;
}
Beispiel #5
0
// Ship tick format:  (5)
// x * 10 | y * 10 | thruster angle * 100 | force * 100 | energy * 10
void ReplayBuilder::addShipStates(Ship **ships, int time) {
  for (int x = 0; x < numShips_; x++) {
    Ship *ship = ships[x];
    if (shipsAlive_[x] != ship->alive) {
      if (ship->alive) {
        addShip(ship->index, time);
      } else {
        removeShip(ship->index, time);
      }
      shipsAlive_[x] = ship->alive;
    }
    if (shipsShowName_[x] != ship->showName) {
      if (ship->showName) {
        addShipShowName(ship->index, time);
      } else {
        addShipHideName(ship->index, time);
      }
      shipsShowName_[x] = ship->showName;
    }
    if (shipsShowEnergy_[x] != ship->energyEnabled) {
      if (ship->energyEnabled) {
        addShipShowEnergy(ship->index, time);
      } else {
        addShipHideEnergy(ship->index, time);
      }
      shipsShowEnergy_[x] = ship->energyEnabled;
    }
  }

  for (int x = 0; x < numShips_; x++) {
    Ship *ship = ships[x];
    if (ship->alive) {
      shipTickData_->addInt(round(ship->x * 10));
      shipTickData_->addInt(round(ship->y * 10));
      shipTickData_->addInt(
          round(normalAbsoluteAngle(ship->thrusterAngle) * 100));
      shipTickData_->addInt(round(limit(0, ship->thrusterForce, 1) * 100));
      shipTickData_->addInt(round(std::max(0., ship->energy) * 10));
    }
  }
}
Beispiel #6
0
DataClass::DataClass()
{
m_ActiveShip = new ShipData(QString());
// m_ActiveShip->init();
m_ActiveCity = 0;
m_ActiveKontor = new KontorData();
m_ActiveChar = new Person();

m_CurrentMap = new Map();

addShip(*m_ActiveShip);
delete m_ActiveShip;
m_ActiveShip = &m_ShipList.first();

m_landingprocess.setStatus(Landing::NotActive);
connect(&calc_data_timer, SIGNAL(timeout()), this, SLOT(calcData()));
// singleplayer = true;
m_anbord = true;


}
Beispiel #7
0
/////////////////////////////////////////////////////////////////////////////
// add a new item to the tree
/////////////////////////////////////////////////////////////////////////////
void CUndoDialog::addItem(int iAction, CUndo *pUndo)
{
	switch(iAction)
	{
	case UNDO_SETTLE_PLACE: addPlacement(TRUE);	break;
	case UNDO_THIRD_ROAD_PLACE:
	case UNDO_ROAD_PLACE: addPlacement(FALSE); break;
	case UNDO_SHIP_PLACE: addPlacement(FALSE, TRUE); break;
	case UNDO_FIRST_ROLL: addRoll(TRUE, ((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_ROLL:	addRoll(FALSE, ((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_ACTION_START:	addActionStart(); break;
	case UNDO_ACTION: addAction(); break;
	case UNDO_ROAD:	addRoad(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_SHIP: addShip(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_CITY:	addCity(); break;
	case UNDO_MOVE_SHIP: addMoveShip(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_SETTLEMENT: addSettle(); break;
	case UNDO_BUY_DEVCARD: addDevcard(); break;
	case UNDO_ROBBER_PLACE:	addRobber(); break;
	case UNDO_PIRATE_PLACE: addPirate(); break;
	case UNDO_PLAY_VICTORY:	addVictory(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_PLAY_MONOPOLY: addMonopoly((CUndoMonopoly *) pUndo); break;
	case UNDO_PLAY_ROAD: addRoadBuild(); break;
	case UNDO_PLAY_YEAR: addYearPlenty(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_PLAY_SOLDIER:	addSoldier(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_TRADE: addTrade((CUndoTrade *) pUndo); break;
	case UNDO_STEAL: addSteal(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_LOSECARDS: addLoseCards((CUndoTrade *) pUndo); break;
	case UNDO_ACTION_END: endTurn(); break;
	case UNDO_WIN: addWin(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_WASTE: addWaste(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_GOLD: addGold((CUndoGold *) pUndo); break;
	case UNDO_CHITLESS: addChitless(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_VOLCANO: addVolcano(); break;
	case UNDO_TRADE_JUNGLE: addJungle((CUndoTrade *) pUndo); break;
	case UNDO_SPECIAL_BUILD: addSpecialBuild(((CUndoOne *) pUndo)->m_iOne); break;
	case UNDO_SPECIAL_BUILD_END: addSpecialBuildEnd(); break;
	default: break;
	}
}
Beispiel #8
0
void adventure(eventList* pEvent, pirateTree*& aTree)
{
	int eventCode, backEvent = 0;
	eventList *backup = pEvent;
	myTree = aTree;
	eventNum = 0;
	prev11 = 0;
	while (pEvent != NULL)
	{
		eventCode = (pEvent->nEventCode > 0)? pEvent->nEventCode: (pEvent->nEventCode * -1);
		eventNum++;
		switch (extractEvent(pEvent->nEventCode))
		{
		case 1:
			if (!isSoulLand && !isRiverCrossed) addShip(eventCode);
			break;
		case 2:
			if (!isPosiden && !isRiverCrossed) monsterAttack(eventCode);
			break;
		case 3:
			if (!isSoulLand && !isRiverCrossed &&
				((!isBermuda && !isPosiden) || (isPosiden && isSteeled))) Bermuda();
			break;
		case 4:
			if (!isSteeled && !isRiverCrossed) Poseiden();
			break;
		case 5:
			if (isSteeled && !isRiverCrossed && !isSoulLand) monsterAttack2(eventCode);
			break;
		case 6:
			if (isSoulLand || isRiverCrossed) break;
			if (isSteeled) soulLand(); else deleteMyTree(myTree->root);
			break;
		case 7:
			if (isSoulLand && isJack) deadManNoTell();
			break;
		case 8:
			if (isSoulLand) strangeWedding();
			break;
		case 9:
			if (isS9 && !isRiverCrossed) driverGuy(eventCode);
			break;
		case 10:
			if (!isJack && isRiverCrossed && prev11 == 0)
			{
				Hades();
				prev11 = eventNum;
			}
			break;
		case 11:
			if (isJack && prev11 > 0)
			{
				backEvent = (999 % prev11) + 1;
				isS12 = 1;
				eventNum = 0;
				pEvent = backup;
				isAVL = 0; isS9 = 0; isRiverCrossed = 0;
				isSoulLand = 0; isPosiden = 0; isBermuda = 0; isSteeled = 0;
				isBlackBeard = 1;
				prev11 = 0;
				deleteMyTree(myTree->root);
				continue;
			}
			break;
		}
		if (myTree->root == NULL) break;
		if (isHalt) break;

		if (isS12 && eventNum == backEvent)
		{
			if (!isJack)
			{
				deleteMyTree(myTree->root);
			}
			break;
		}

		pEvent = pEvent->pNext;
	}
}