int SquadronClass::GetUnitSupplyNeed (int have) { if(g_bEnableABRelocation) { // OW AB Relocation fix MoveUnit(0);//me123 relocate test } int want=0,got=0,i; UnitClassDataType* uc; // Squadrons need supply based on their munitions uc = GetUnitClassData(); if (!uc) return 0; for (i=0; i<MAXIMUM_WEAPTYPES; i++) { want += SquadronStoresDataTable[uc->SpecialIndex].Stores[i]; got += GetUnitStores(i); } if (have) return got / SQUADRON_PT_SUPPLY; return (want - got) / SQUADRON_PT_SUPPLY; }
void UNIT::Goto(INTPOINT mp) { if(m_pTerrain == NULL)return; //Clear old path m_path.clear(); m_activeWP = 0; if(m_moving) //If unit is currently moving { //Finish the active waypoint m_path.push_back(m_mappos); std::vector<INTPOINT> tmpPath = m_pTerrain->GetPath(m_mappos, mp); //add new path for(int i=0;i<(int)tmpPath.size();i++) m_path.push_back(tmpPath[i]); } else //Create new path from scratch... { m_path = m_pTerrain->GetPath(m_mappos, mp); if(m_path.size() > 0) //if a path was found { m_moving = true; //Check that the next tile is free if(!CheckCollision(m_path[m_activeWP])) { MoveUnit(m_path[m_activeWP]); SetAnimation("Run"); } } } }
void UNIT::Update(float deltaTime) { //update unit animation time m_time += deltaTime * 0.8f * m_speed; //if the unit is moving... if(m_moving) { if(m_movePrc < 1.0f)m_movePrc += deltaTime * m_speed; if(m_movePrc > 1.0f)m_movePrc = 1.0f; //waypoint reached if(m_movePrc == 1.0f) { if(m_activeWP + 1 >= (int)m_path.size()) //goal reached { m_moving = false; SetAnimation("Still"); } else if(!CheckCollision(m_path[m_activeWP + 1])) //Next Waypoint { m_activeWP++; SetAnimation("Run"); MoveUnit(m_path[m_activeWP]); } } //Interpolate position between m_lastWP and m_nextWP m_position = m_lastWP * (1.0f - m_movePrc) + m_nextWP * m_movePrc; } }
void CampaignPlanMovement::ExecFrame() { if (campaign && campaign->IsActive()) { if (Campaign::Stardate() - exec_time < 7200) return; campaign->GetAllCombatUnits(-1, all_units); ListIter<CombatUnit> iter = all_units; while (++iter) { CombatUnit* u = iter.value(); if (u->IsStarship() && !u->IsStatic()) MoveUnit(u); } all_units.clear(); exec_time = Campaign::Stardate(); } }
/* takes in a list, the map array, and the level counter (current level). Moves the units through the level. */ int Run(List * L, char map[22][80], int levelCount) { int i, cnt; /*X is set to 79 because the x coordinate of the starting location never changes.*/ int X = 79; int Y; int check = 1; /*direction checks whether the unit should move up or down.*/ int direction = -1; int win = 0; cnt = L->size; /*find the y coordinate of the starting position.*/ for(i = 0; i < 22; i++) { if(map[i][79] == 'o') Y = i; } /*set the initial x and y of each unit to the starting locations.*/ for(i = 0; i < L->size; i++) { L->items[i].y = Y; L->items[i].x = X; } /*check is 1 if there are units remaining, and 0 if all units are killed.*/ while(check == 1) { for(i = 0; i < L->size; i++) { check = MoveUnit(i, L, &cnt, &direction, &win, levelCount); } usleep(100000); } return win; }
/* Updates player moves */ void clash::Update(float dt) { _keyPress += dt; if (_turn == AI) NextTurn(); else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Return) && _keyPress > 1.f) { NextTurn(); _keyPress = 0; } // Mouse-over type marker for (int i = 0; i < CHECKBOARD; i++) { for (int j = 0; j < CHECKBOARD; j++) { if (IsMouseOver(_checkBoard[i][j])) { _currentMouseOver = sf::Vector2i(i, j); } } } // Selection tool if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) { _currentChoosen = _currentMouseOver; } // Moving units else if (sf::Mouse::isButtonPressed(sf::Mouse::Right) && _currentChoosen.x >= 0 && _keyPress > 0.2f) { int i = _currentChoosen.x; int j = _currentChoosen.y; int x = _currentMouseOver.x; int y = _currentMouseOver.y; if (((abs(x - i) <= 1 && j == y) || (abs(j - y) <= 1 && i == x)) && _movesPPlayer > 0 && _checkBoard[i][j].CountUnits() > 0) { if (_checkBoard[i][j]._entity == _checkBoard[x][y]._entity && _turn == _checkBoard[i][j]._entity) MoveUnit(_currentChoosen, _currentMouseOver); if (_checkBoard[x][y]._entity == NONE && _turn == _checkBoard[i][j]._entity) { _checkBoard[x][y]._entity = _turn; _checkBoard[x][y]._field = UNIT; MoveUnit(_currentChoosen, _currentMouseOver); } if (_checkBoard[x][y]._entity >= 0 && _checkBoard[x][y]._entity != _checkBoard[i][j]._entity) { if (_checkBoard[x][y].CountUnits() > 0 && _checkBoard[i][j].CountUnits() > 0) { _checkBoard[x][y].Kill(1); _checkBoard[i][j].Kill(1); _movesPPlayer--; } else if (_checkBoard[x][y].CountUnits() == 0 && _checkBoard[i][j].CountUnits() > 0) { if (_checkBoard[x][y]._field == FACTORY) { _checkBoard[x][y]._field = UNIT; _player[_checkBoard[x][y]._entity - 1] = false; } if (_checkBoard[x][y]._field == CORE) { //Window.GetGameManager()->_winner = (int)(_checkBoard[i][j]._entity + 1); //Window.GetGameManager()->MoveForward(); Window.Stop(); } _checkBoard[x][y]._entity = _checkBoard[i][j]._entity; MoveUnit(_currentChoosen, _currentMouseOver); } } } _keyPress = 0; } if (_turn == AI && _pcTurn >= 2 && _pcTurn != 3) { if (_pcTurn == 4) { for (int i = 0; i < CHECKBOARD; i++) { for (int j = 0; j < CHECKBOARD; j++) { if (_checkBoard[i][j]._entity == AI) { _checkBoard[i][j].TurnAlive(1); } } } _pcTurn = 0; } for (int i = 1; i <= 2; i++) { int ww = 0, wh = 0; if (i == 1 || i == 4) wh = 1; if (i == 1 || i == 3) ww = 1; if (i == 3 || i == 2) wh = CHECKBOARD - 2; if (i == 4 || i == 2) ww = CHECKBOARD - 2; if (_checkBoard[ww][wh]._entity == NONE) { _checkBoard[ww][wh]._entity = (ENTITY_TYPE) (i); _checkBoard[ww][wh]._field = UNIT; } if (_checkBoard[ww][wh]._entity == (ENTITY_TYPE) (i) && _player[_checkBoard[ww][wh]._entity-1]) { _checkBoard[ww][wh].TurnAlive(2); } } } if (_movesPPlayer > 0) _check = false; if (_moves != _movesPPlayer) { if (_movesPPlayer == 0) Window.UpdateStatusbar("Press ENTER for next turn"); else if (_turnCounter == 1 && _movesPPlayer == 0 && _check) { _moves = 1; _check = false; } else Window.UpdateStatusbar(toString(_movesPPlayer) + " moves left"); } }
void Unit::Order_NukeLaunch(ProgressUnitResults *results) { if (order_state < 5 && !related) { Kill(results); return; } switch (order_state) { case 0: PlaySound(Sound::NukeLaunch, this, 1, 0); // Wtf ChangeMovementTarget(Point(sprite->position.x, units_dat_dimensionbox[NuclearMissile].top)); unk_move_waypoint = Point(sprite->position.x, units_dat_dimensionbox[NuclearMissile].top); order_timer = 90; order_state = 1; break; case 1: if (order_timer > 45 && IsStandingStill() == 0) return; PlaySound(Sound::Advisor_NukeLaunch + *bw::player_race, nullptr, 1, 0); PrintInfoMessage((*bw::stat_txt_tbl)->GetTblString(String::NuclearLaunchDetected)); order_state = 2; break; case 2: if (order_timer && IsStandingStill() == 0) return; HideUnit(this); related->related = this; StopMoving(this); order_state = 3; break; case 3: if (flingy_flags & 0x2) return; SetIscriptAnimation(Iscript::Animation::WarpIn, true, "Order_NukeLaunch state 3", results); order_state = 4; break; case 4: { if (~order_signal & 0x2) return; order_signal &= ~0x2; Point new_pos = order_target_pos; new_pos.x = std::max(units_dat_dimensionbox[NuclearMissile].left, new_pos.x); new_pos.y = std::max((int)units_dat_dimensionbox[NuclearMissile].top, new_pos.y - 0x140); MoveUnit(this, new_pos.x, new_pos.y); SetDirection((Flingy *)this, 0x80); ChangeMovementTarget(order_target_pos); unk_move_waypoint = order_target_pos; ShowUnit(this); order_state = 5; } break; case 5: if (!IsPointInArea(this, 10, move_target.x, move_target.y)) return; target = this; SetIscriptAnimation(Iscript::Animation::Special1, true, "Order_NukeLaunch state 5", results); order_state = 6; break; case 6: if (~order_signal & 0x1) return; order_signal &= ~0x1; order_flags |= 0x4; Kill(results); break; } }