Skip to content
Snippets Groups Projects
Commit b2356890 authored by Frederik Alexander Keens's avatar Frederik Alexander Keens
Browse files

Merge branch 'main' into 'cleanUpMenus'

# Conflicts:
#   src/game/level/Level.cpp
#   src/game/main.cpp
parents 9da732cb ddc96ece
No related branches found
No related tags found
1 merge request!45Clean up Help Menu and UnitInfo Menu
......@@ -78,6 +78,8 @@ add_executable(advanced_wars ${ADVANCED_WARS_SOURCES})
set(CMAKE_MODULE_PATH ${ADVANCED_WARS_SOURCE_DIR}/cmake/ ${CMAKE_MODULE_PATH})
find_package(Qt6 REQUIRED COMPONENTS Widgets)
# Plattform-spezifische Konfiguration
if(APPLE)
# SDL2 Frameworks für macOS
......@@ -96,6 +98,7 @@ if(APPLE)
${SDL2_PATH}/SDL2.framework/SDL2
${SDL2_PATH}/SDL2_image.framework/SDL2_image
${SDL2_PATH}/SDL2_ttf.framework/SDL2_ttf
Qt6::Core
Boost::graph
box2d
)
......@@ -127,6 +130,7 @@ else()
target_link_libraries(advanced_wars
${HDF5_LIBRARIES}
Qt6::Core
-lSDL2
-lSDL2_image
-lSDL2_ttf
......@@ -138,7 +142,6 @@ endif()
# leveleditor
# Find Qt
find_package(Qt6 REQUIRED COMPONENTS Widgets)
file(GLOB_RECURSE LEVELEDITOR_SOURCES
"${PROJECT_SOURCE_DIR}/src/editor/*.cpp"
......
......@@ -40,7 +40,6 @@
<Weapons>
<PrimaryWeapon name="Bazooka">
<DamageTable>
<Damage unitId="recon" value="85"/>
<Damage unitId="apc" value="75"/>
<Damage unitId="anti_air_tank" value="65"/>
......@@ -50,7 +49,6 @@
<Damage unitId="artillery" value="70"/>
<Damage unitId="rocket_artillery" value="85"/>
<Damage unitId="anti_air_missile_launcher" value="85"/>
</DamageTable>
</PrimaryWeapon>
<SecondaryWeapon name="Machine-Gun">
......@@ -139,7 +137,6 @@
<Damage unitId="anti_air_missile_launcher" value="55"/>
<Damage unitId="transport_helicopter" value="105"/>
<Damage unitId="battle_helicopter" value="105"/>
<Damage unitId="stealth" value="75"/>
<Damage unitId="fighter" value="65"/>
<Damage unitId="bomber" value="75"/>
</DamageTable>
......@@ -244,7 +241,6 @@
<Weapons>
<PrimaryWeapon name="New Cannon">
<DamageTable>
<Damage unitId="recon" value="125"/>
<Damage unitId="apc" value="125"/>
<Damage unitId="anti_air_tank" value="115"/>
......@@ -254,7 +250,6 @@
<Damage unitId="artillery" value="115"/>
<Damage unitId="rocket_artillery" value="125"/>
<Damage unitId="anti_air_missile_launcher" value="125"/>
</DamageTable>
</PrimaryWeapon>
<SecondaryWeapon name="Machine-Gun">
......@@ -301,7 +296,6 @@
<Damage unitId="rocket_artillery" value="80"/>
<Damage unitId="anti_air_missile_launcher" value="80"/>
<Damage unitId="lander" value="55"/>
<Damage unitId="black_boat" value="55"/>
<Damage unitId="cruiser" value="50"/>
<Damage unitId="submarine" value="60"/>
<Damage unitId="battleship" value="40"/>
......@@ -334,7 +328,6 @@
<Damage unitId="rocket_artillery" value="85"/>
<Damage unitId="anti_air_missile_launcher" value="90"/>
<Damage unitId="lander" value="60"/>
<Damage unitId="black_boat" value="60"/>
<Damage unitId="cruiser" value="60"/>
<Damage unitId="submarine" value="85"/>
<Damage unitId="battleship" value="55"/>
......@@ -423,7 +416,6 @@
<PrimaryWeapon name="Torpedoes">
<DamageTable>
<Damage unitId="lander" value="95"/>
<Damage unitId="black_boat" value="95"/>
<Damage unitId="cruiser" value="25"/>
<Damage unitId="submarine" value="55"/>
<Damage unitId="battleship" value="55"/>
......@@ -456,7 +448,6 @@
<Damage unitId="rocket_artillery" value="85"/>
<Damage unitId="anti_air_missile_launcher" value="90"/>
<Damage unitId="lander" value="95"/>
<Damage unitId="black_boat" value="95"/>
<Damage unitId="cruiser" value="95"/>
<Damage unitId="submarine" value="95"/>
<Damage unitId="battleship" value="50"/>
......@@ -505,8 +496,6 @@
<DamageTable>
<Damage unitId="infantry" value="75"/>
<Damage unitId="mechanized_infantry" value="75"/>
</DamageTable>
</SecondaryWeapon>
</Weapons>
......@@ -526,7 +515,6 @@
<DamageTable>
<Damage unitId="transport_helicopter" value="100"/>
<Damage unitId="battle_helicopter" value="100"/>
<Damage unitId="fighter" value="55"/>
<Damage unitId="bomber" value="100"/>
</DamageTable>
......@@ -558,7 +546,6 @@
<Damage unitId="rocket_artillery" value="105"/>
<Damage unitId="anti_air_missile_launcher" value="105"/>
<Damage unitId="lander" value="95"/>
<Damage unitId="black_boat" value="95"/>
<Damage unitId="cruiser" value="85"/>
<Damage unitId="submarine" value="95"/>
<Damage unitId="battleship" value="75"/>
......
......@@ -60,22 +60,22 @@ Level::Level(const std::string& path, Engine& engine)
// if level is smaler than 20x20 surround with water tiles
if (m_width < 20 || m_height < 20)
{
int w_start = (20 - m_width) / 2;
int h_start = (20 - m_height) / 2;
int x_start = (20 - width) / 2;
int y_start = (20 - height) / 2;
std::vector<uint8_t> transformed_tiles_array;
transformed_tiles_array.reserve(20 * 20);
for (int y = 0; y < 20; y++)
{
for (int x = 0; x < 20; x++)
{
if (x < w_start || y < h_start || x >= w_start + m_width || y >= h_start + m_height)
if (x < x_start || y < y_start || x >= x_start + width || y >= y_start + height)
{
transformed_tiles_array.push_back(1);
}
else
{
transformed_tiles_array.push_back(
level_tilesarray[x - w_start + (y - h_start) * m_width]);
level_tilesarray[x - x_start + (y - y_start) * width]);
}
}
}
......@@ -91,30 +91,31 @@ Level::Level(const std::string& path, Engine& engine)
std::vector<Building> buildings;
tiles.reserve(m_width * m_height);
bool has_factions[] = {false, false, false, false, false};
for (int i = 0; i < level_tilesarray.size(); i++)
for (size_t i = 0; i < level_tilesarray.size(); i++)
{
int tileX = i % m_width;
int tileY = i / m_width;
if (level_tilesarray[i] >= 50)
{
tiles.push_back(Tile(TileId(TileId::PLAIN), tileX, tileY));
// tile id >= 50 -> building -> have to add Plain Tile and Building
tiles.push_back(Tile(TileId(TileId::PLAIN), x, y));
BuildingId building_id = static_cast<BuildingId>((level_tilesarray[i] - 50) % 5);
Faction factionId = static_cast<Faction>((level_tilesarray[i] - 50) / 5);
BuildingFaction faction_id =
static_cast<BuildingFaction>((level_tilesarray[i] - 50) / 5);
if (building_id == BuildingId::HEADQUARTER)
{
int index = static_cast<int>(factionId);
if (!has_factions[index])
{
addUnit(
tileX, tileY, factionId, UnitTypeId::INFANTERY, UnitState::UNAVAILABLE,
engine.getUnitConfig());
}
has_factions[static_cast<int>(factionId)] = true;
// an infantery unit should be added onto every HQ
units.push_back(Unit(
x, y, static_cast<UnitFaction>(faction_id), UnitId::INFANTERY,
UnitState::UNAVAILABLE, engine.getUnitConfig()));
has_factions[static_cast<int>(faction_id)] = true; // collect existing factions
// for later building turnQ
}
buildings.push_back(Building(tileX, tileY, building_id, factionId));
}
else
{
// if tile id belongs to terrain tile, just a tile needs to added
TileId tile_id = static_cast<TileId>(level_tilesarray[i]);
tiles.push_back(Tile(tile_id, tileX, tileY));
}
......@@ -145,8 +146,8 @@ Level::Level(const std::string& path, Engine& engine)
m_turnQ = turnQ;
m_turnQ.front().startTurn(m_units, m_buildings);
std::cout << "exiting" << "\n";
level.m_turnQ.front().startTurn(level.m_units, level.m_buildings);
return std::make_shared<Level>(level);
}
std::pair<int, int> Level::calcTilePos(int mouseX, int mouseY)
......
......@@ -6,20 +6,49 @@
#include <SDL2/SDL.h>
#include <SDL_image.h>
#include <QCoreApplication>
#include <QCommandLineParser>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <vector>
#include <string>
#include <optional>
#include <filesystem>
using namespace advanced_wars;
std::optional<std::string> get_level_filepath(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationVersion("1.0.0");
QCommandLineParser parser;
parser.addVersionOption();
parser.addHelpOption();
parser.setApplicationDescription("Advanced Wars is a multi player strategy game.\nCapture citys, build units and defeat your opponents. No mercy!");
parser.addPositionalArgument("path", "The path to the HDF5 level file from which the level should be loaded.", "<path>");
parser.process(app);
if (parser.positionalArguments().size() != 1)
{
std::cerr << "Command not recognized." << std::endl;
parser.showHelp();
return std::nullopt;
}
std::string filepath = parser.positionalArguments()[0].toStdString();
if (!std::filesystem::exists(filepath))
{
std::cerr << "The hdf5 level file path: '" << filepath <<"' does not exist." << std::endl;
return std::nullopt;
}
return parser.positionalArguments()[0].toStdString();
}
int main(int argc, char* argv[])
{
if (argc <= 1)
std::optional<std::string> level_filepath = get_level_filepath(argc, argv);
if (!level_filepath.has_value())
{
std::cerr << "Please provide the path to the level that you want to play as a command line "
"argument."
<< "\n";
return 1;
}
......@@ -43,7 +72,7 @@ int main(int argc, char* argv[])
engine.setSpritesheet(spritesheet);
std::shared_ptr<Menu> menu = std::make_shared<Menu>(0, argv[1]);
std::shared_ptr<Menu> menu = std::make_shared<Menu>(0, level_filepath.value());
std::shared_ptr<ContextMenu> context_menu = std::make_shared<ContextMenu>();
context_menu->setOptions({"Move", "Info", "Wait"});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment