Skip to content

Add support for h2d file format with first data file #3828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for h2d file format with first data file
- fix farm rendering in Knight castle (#2059)
- add missing farm sprite made by our artist
  • Loading branch information
ihhub committed Jul 11, 2021
commit a8e84e32f307f858e171b4bbea7cacb2debdadf6
2 changes: 1 addition & 1 deletion VisualStudio/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\src\engine;$(MSBuildThisFileDirectory)..\src\fheroes2\gui;$(MSBuildThisFileDirectory)..\src\fheroes2\maps;$(MSBuildThisFileDirectory)..\src\fheroes2\kingdom;$(MSBuildThisFileDirectory)..\src\fheroes2\campaign;$(MSBuildThisFileDirectory)..\src\fheroes2\game;$(MSBuildThisFileDirectory)..\src\fheroes2\dialog;$(MSBuildThisFileDirectory)..\src\fheroes2\system;$(MSBuildThisFileDirectory)..\src\fheroes2\spell;$(MSBuildThisFileDirectory)..\src\fheroes2\monster;$(MSBuildThisFileDirectory)..\src\fheroes2\castle;$(MSBuildThisFileDirectory)..\src\fheroes2\agg;$(MSBuildThisFileDirectory)..\src\fheroes2\heroes;$(MSBuildThisFileDirectory)..\src\fheroes2\resource;$(MSBuildThisFileDirectory)..\src\fheroes2\ai;$(MSBuildThisFileDirectory)..\src\fheroes2\army;$(MSBuildThisFileDirectory)..\src\fheroes2\battle;$(MSBuildThisFileDirectory)..\src\fheroes2\pocketpc;$(MSBuildThisFileDirectory)..\src\fheroes2\objects;$(MSBuildThisFileDirectory)..\src\fheroes2\world;$(MSBuildThisFileDirectory)..\src\fheroes2\image;$(MSBuildThisFileDirectory)..\src\thirdparty\libsmacker;$(MSBuildThisFileDirectory)packages\installed\zlib\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\src\engine;$(MSBuildThisFileDirectory)..\src\fheroes2\gui;$(MSBuildThisFileDirectory)..\src\fheroes2\maps;$(MSBuildThisFileDirectory)..\src\fheroes2\kingdom;$(MSBuildThisFileDirectory)..\src\fheroes2\campaign;$(MSBuildThisFileDirectory)..\src\fheroes2\game;$(MSBuildThisFileDirectory)..\src\fheroes2\dialog;$(MSBuildThisFileDirectory)..\src\fheroes2\system;$(MSBuildThisFileDirectory)..\src\fheroes2\spell;$(MSBuildThisFileDirectory)..\src\fheroes2\monster;$(MSBuildThisFileDirectory)..\src\fheroes2\castle;$(MSBuildThisFileDirectory)..\src\fheroes2\agg;$(MSBuildThisFileDirectory)..\src\fheroes2\heroes;$(MSBuildThisFileDirectory)..\src\fheroes2\resource;$(MSBuildThisFileDirectory)..\src\fheroes2\ai;$(MSBuildThisFileDirectory)..\src\fheroes2\army;$(MSBuildThisFileDirectory)..\src\fheroes2\battle;$(MSBuildThisFileDirectory)..\src\fheroes2\h2d;$(MSBuildThisFileDirectory)..\src\fheroes2\objects;$(MSBuildThisFileDirectory)..\src\fheroes2\world;$(MSBuildThisFileDirectory)..\src\fheroes2\image;$(MSBuildThisFileDirectory)..\src\thirdparty\libsmacker;$(MSBuildThisFileDirectory)packages\installed\zlib\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(fheroes2_build_version)'!=''">BUILD_VERSION=$(fheroes2_build_version);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatSpecificWarningsAsErrors>4018;4028;4100;4114;4189;4245;4267;4309;4319;4389;4456;4458;4554;4592;4702;4706;4715;4800</TreatSpecificWarningsAsErrors>
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ after_build:
- cmd: xcopy /Y /s /Q "docs\README.txt" "."
- cmd: xcopy /Y /s /Q "script\demo\demo_windows.bat" "."
- cmd: xcopy /Y /s /Q "script\demo\demo_windows.ps1" "."
- cmd: 7z a build\%platform%\%configuration%\fheroes2_windows_%platform%_%deploy_conf_name%.zip demo_windows.bat demo_windows.ps1 LICENSE fheroes2.key changelog.txt README.txt
- cmd: 7z a build\%platform%\%configuration%\fheroes2_windows_%platform%_%deploy_conf_name%.zip demo_windows.bat demo_windows.ps1 LICENSE fheroes2.key changelog.txt README.txt data\resurrection.h2d
- cmd: iscc script\windows\fheroes2.iss /DAppVersion=%APPVEYOR_BUILD_VERSION% "/DBuildDir=C:\projects\fheroes2\build\%platform%\%configuration%" /DPlatform=%platform% /DDeployConfName=%deploy_conf_name%

artifacts:
Expand Down
Binary file added data/resurrection.h2d
Binary file not shown.
4 changes: 4 additions & 0 deletions fheroes2-vs2015.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@
<ClCompile Include="src\fheroes2\gui\ui_text.cpp" />
<ClCompile Include="src\fheroes2\gui\ui_tool.cpp" />
<ClCompile Include="src\fheroes2\gui\ui_window.cpp" />
<ClCompile Include="src\fheroes2\h2d\h2d.cpp" />
<ClCompile Include="src\fheroes2\h2d\h2d_file.cpp" />
<ClCompile Include="src\fheroes2\heroes\direction.cpp" />
<ClCompile Include="src\fheroes2\heroes\heroes.cpp" />
<ClCompile Include="src\fheroes2\heroes\heroes_action.cpp" />
Expand Down Expand Up @@ -485,6 +487,8 @@
<ClInclude Include="src\fheroes2\gui\ui_text.h" />
<ClInclude Include="src\fheroes2\gui\ui_tool.h" />
<ClInclude Include="src\fheroes2\gui\ui_window.h" />
<ClInclude Include="src\fheroes2\h2d\h2d.h" />
<ClInclude Include="src\fheroes2\h2d\h2d_file.h" />
<ClInclude Include="src\fheroes2\heroes\direction.h" />
<ClInclude Include="src\fheroes2\heroes\heroes.h" />
<ClInclude Include="src\fheroes2\heroes\heroes_base.h" />
Expand Down
4 changes: 4 additions & 0 deletions fheroes2-vs2019.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@
<ClCompile Include="src\fheroes2\gui\ui_text.cpp" />
<ClCompile Include="src\fheroes2\gui\ui_tool.cpp" />
<ClCompile Include="src\fheroes2\gui\ui_window.cpp" />
<ClCompile Include="src\fheroes2\h2d\h2d.cpp" />
<ClCompile Include="src\fheroes2\h2d\h2d_file.cpp" />
<ClCompile Include="src\fheroes2\heroes\direction.cpp" />
<ClCompile Include="src\fheroes2\heroes\heroes.cpp" />
<ClCompile Include="src\fheroes2\heroes\heroes_action.cpp" />
Expand Down Expand Up @@ -486,6 +488,8 @@
<ClInclude Include="src\fheroes2\gui\ui_text.h" />
<ClInclude Include="src\fheroes2\gui\ui_tool.h" />
<ClInclude Include="src\fheroes2\gui\ui_window.h" />
<ClInclude Include="src\fheroes2\h2d\h2d.h" />
<ClInclude Include="src\fheroes2\h2d\h2d_file.h" />
<ClInclude Include="src\fheroes2\heroes\direction.h" />
<ClInclude Include="src\fheroes2\heroes\heroes.h" />
<ClInclude Include="src\fheroes2\heroes\heroes_base.h" />
Expand Down
16 changes: 16 additions & 0 deletions src/fheroes2/agg/agg_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "agg.h"
#include "agg_file.h"
#include "agg_image.h"
#include "h2d.h"
#include "icn.h"
#include "image.h"
#include "image_tool.h"
Expand Down Expand Up @@ -937,6 +938,21 @@ namespace fheroes2
Blit( common, output );
return true;
}
case ICN::KNIGHT_CASTLE_RIGHT_FARM: {
_icnVsSprite[id].resize( 1 );
Sprite & output = _icnVsSprite[id][0];
output = GetICN( ICN::TWNKWEL2, 0 );

ApplyPalette( output, 28, 21, output, 28, 21, 39, 1, 8 );
ApplyPalette( output, 0, 22, output, 0, 22, 69, 1, 8 );
ApplyPalette( output, 0, 23, output, 0, 23, 53, 1, 8 );
ApplyPalette( output, 0, 24, output, 0, 24, 54, 1, 8 );
ApplyPalette( output, 0, 25, output, 0, 25, 62, 1, 8 );
return true;
}
case ICN::KNIGHT_CASTLE_LEFT_FARM:
_icnVsSprite[id].resize( 1 );
h2d::readImage( "knight_castle_left_farm", _icnVsSprite[id][0] );
default:
break;
}
Expand Down
5 changes: 4 additions & 1 deletion src/fheroes2/agg/icn.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace ICN
{
enum
enum : int
{
UNKNOWN,
ADVBORDE,
Expand Down Expand Up @@ -946,6 +946,9 @@ namespace ICN
NEW_CAMPAIGN_DISABLED_BUTTON,
MAX_DISABLED_BUTTON,

KNIGHT_CASTLE_RIGHT_FARM,
KNIGHT_CASTLE_LEFT_FARM,

// IMPORTANT! Put any new entry just above this one.
LASTICN
};
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/castle/castle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ int Castle::GetICNBuilding( u32 build, int race )
case BUILD_CAPTAIN:
return ICN::TWNKCAPT;
case BUILD_WEL2:
return ICN::TWNKWEL2;
return ICN::KNIGHT_CASTLE_RIGHT_FARM;
case BUILD_LEFTTURRET:
return ICN::TWNKLTUR;
case BUILD_RIGHTTURRET:
Expand Down
7 changes: 6 additions & 1 deletion src/fheroes2/castle/castle_building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ void CastleDialog::CastleRedrawBuildingExtended( const Castle & castle, const fh
CastleDialog::RedrawBuildingSpriteToArea( sprite21, dst_pt.x + sprite21.x(), dst_pt.y + sprite21.y(), max, alpha );
}
}
else if ( castle.GetRace() == Race::KNGT && BUILD_WEL2 == build && !castle.isBuild( BUILD_CASTLE ) ) {
const fheroes2::Sprite & rightFarm = fheroes2::AGG::GetICN( ICN::KNIGHT_CASTLE_RIGHT_FARM, 0 );
const fheroes2::Sprite & leftFarm = fheroes2::AGG::GetICN( ICN::KNIGHT_CASTLE_LEFT_FARM, 0 );
CastleDialog::RedrawBuildingSpriteToArea( leftFarm, dst_pt.x + rightFarm.x() - leftFarm.width(), dst_pt.y + rightFarm.y(), max, alpha );
}
}

bool CastleDialog::RoadConnectionNeeded( const Castle & castle, const uint32_t buildId, const bool constructionInProgress )
Expand Down Expand Up @@ -881,9 +886,9 @@ void CastlePackOrdersBuildings( const Castle & castle, std::vector<building_t> &
switch ( castle.GetRace() ) {
case Race::KNGT:
ordersBuildings.push_back( BUILD_TENT );
ordersBuildings.push_back( BUILD_WEL2 );
ordersBuildings.push_back( BUILD_CASTLE );
ordersBuildings.push_back( BUILD_SPEC );
ordersBuildings.push_back( BUILD_WEL2 );
ordersBuildings.push_back( BUILD_CAPTAIN );
ordersBuildings.push_back( BUILD_LEFTTURRET );
ordersBuildings.push_back( BUILD_RIGHTTURRET );
Expand Down
65 changes: 65 additions & 0 deletions src/fheroes2/h2d/h2d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/***************************************************************************
* Free Heroes of Might and Magic II: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2021 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include "h2d.h"
#include "h2d_file.h"
#include "settings.h"

namespace
{
bool isInitialized = false;
fheroes2::H2RReader reader;

void initialize()
{
if ( isInitialized ) {
return;
}

isInitialized = true;

ListFiles files = Settings::FindFiles( "data", ".h2d", false );
if ( files.empty() ) {
return;
}

for ( const std::string & fileName : files ) {
if ( reader.open( fileName ) ) {
return;
}
}
}
}

namespace fheroes2
{
class Sprite;

namespace h2d
{
bool readImage( const std::string & name, Sprite & image )
{
// Initialize only when it's requested.
initialize();

return readImageFromH2D( reader, name, image );
}
}
}
33 changes: 33 additions & 0 deletions src/fheroes2/h2d/h2d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/***************************************************************************
* Free Heroes of Might and Magic II: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2021 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#pragma once

#include <string>

namespace fheroes2
{
class Sprite;

namespace h2d
{
bool readImage( const std::string & name, Sprite & image );
}
}
Loading