From c8f7c99c805bca2f5de54c879aaefbaf34d9af92 Mon Sep 17 00:00:00 2001 From: Zero Fanker Date: Tue, 7 May 2024 00:50:43 -0400 Subject: [PATCH] made some progress, but SHP image position is not always correct . --- 3rdParty/xcc/misc/cc_file.cpp | 2 +- 3rdParty/xcc/misc/cc_file.h | 8 +- 3rdParty/xcc/misc/cc_structures.h | 4 +- 3rdParty/xcc/misc/mix_file.cpp | 2 +- 3rdParty/xcc/misc/mix_file.h | 14 +- 3rdParty/xcc/misc/tmp_file.h | 2 +- MissionEditor/IsoView.cpp | 1 + MissionEditor/Loading.cpp | 308 ++++++------------ MissionEditor/MapData.cpp | 4 + MissionEditor/inlines.h | 22 +- MissionEditorPackLib/MissionEditorPackLib.cpp | 42 +-- MissionEditorPackLib/MissionEditorPackLib.h | 5 +- 12 files changed, 162 insertions(+), 252 deletions(-) diff --git a/3rdParty/xcc/misc/cc_file.cpp b/3rdParty/xcc/misc/cc_file.cpp index cb20d31..ccf1481 100644 --- a/3rdParty/xcc/misc/cc_file.cpp +++ b/3rdParty/xcc/misc/cc_file.cpp @@ -257,7 +257,7 @@ int Ccc_file::read() return 0; } -int Ccc_file::read(void* data, int size) +int Ccc_file::read(void* data, int64_t size) { if (get_p() < 0 || get_p() + size > get_size()) return 1; diff --git a/3rdParty/xcc/misc/cc_file.h b/3rdParty/xcc/misc/cc_file.h index b60c7b5..ef7e9b1 100644 --- a/3rdParty/xcc/misc/cc_file.h +++ b/3rdParty/xcc/misc/cc_file.h @@ -114,7 +114,7 @@ public: void load(const Ccc_file& f); t_file_type get_file_type(bool fast = true); int read(); - int read(void* data, int size); + int read(void* data, int64_t size); int extract(const string& name); virtual void close(); Ccc_file(bool read_on_open); @@ -154,7 +154,7 @@ public: return m_data; } - int get_p() const + int64_t get_p() const { return m_p; } @@ -174,7 +174,7 @@ public: m_p = p; } - void skip(int p) + void skip(int64_t p) { m_p += p; } @@ -189,7 +189,7 @@ private: Cvirtual_binary m_data; Cfile32 m_f; bool m_is_open = false; - int m_p; + int64_t m_p; const bool m_read_on_open; size_t m_size; }; diff --git a/3rdParty/xcc/misc/cc_structures.h b/3rdParty/xcc/misc/cc_structures.h index fba04e5..9956db8 100644 --- a/3rdParty/xcc/misc/cc_structures.h +++ b/3rdParty/xcc/misc/cc_structures.h @@ -194,7 +194,7 @@ struct t_mix_index_entry { t_mix_index_entry() = default; - t_mix_index_entry(unsigned int id_, int offset_, int size_) + t_mix_index_entry(unsigned int id_, int offset_, unsigned __int32 size_) { id = id_; offset = offset_; @@ -203,7 +203,7 @@ struct t_mix_index_entry unsigned __int32 id; __int32 offset; - __int32 size; + unsigned __int32 size; }; struct t_mix_rg_header diff --git a/3rdParty/xcc/misc/mix_file.cpp b/3rdParty/xcc/misc/mix_file.cpp index 19535a4..689134f 100644 --- a/3rdParty/xcc/misc/mix_file.cpp +++ b/3rdParty/xcc/misc/mix_file.cpp @@ -318,7 +318,7 @@ string Cmix_file::get_name(int id) #endif } -int Cmix_file::get_id(t_game game, string name) +unsigned int Cmix_file::get_id(t_game game, string name) { boost::to_upper(name); std::replace(name.begin(), name.end(), '/', '\\'); diff --git a/3rdParty/xcc/misc/mix_file.h b/3rdParty/xcc/misc/mix_file.h index ab37c00..6797b02 100644 --- a/3rdParty/xcc/misc/mix_file.h +++ b/3rdParty/xcc/misc/mix_file.h @@ -26,7 +26,7 @@ class Cmix_file : public Ccc_file public: int post_open(); string get_name(int id); - static int get_id(t_game game, string name); + static unsigned int get_id(t_game game, string name); int get_index(unsigned int id) const; using Ccc_file::get_size; using Ccc_file::vdata; @@ -80,10 +80,14 @@ public: return m_index[get_index(id)].offset; } - int get_size(unsigned int id) const + size_t get_size(unsigned int id) const { - assert(get_index(id) != -1); - return m_index[get_index(id)].size; + auto const idx = get_index(id); + //assert(idx != -1); + if (idx >= 0) { + return m_index[idx].size; + } + return 0; } bool has_checksum() const @@ -101,7 +105,7 @@ public: return &m_index[0]; } private: - using t_id_index = map; + using t_id_index = map; static bool m_ft_support; diff --git a/3rdParty/xcc/misc/tmp_file.h b/3rdParty/xcc/misc/tmp_file.h index 53647e2..993e0dd 100644 --- a/3rdParty/xcc/misc/tmp_file.h +++ b/3rdParty/xcc/misc/tmp_file.h @@ -27,7 +27,7 @@ public: bool is_valid() const { const t_tmp_header& h = header(); - int size = get_size(); + auto const size = get_size(); return !(sizeof(t_tmp_header) > size || h.cx != 24 || h.cy != 24 || diff --git a/MissionEditor/IsoView.cpp b/MissionEditor/IsoView.cpp index d2b69d6..57fa652 100644 --- a/MissionEditor/IsoView.cpp +++ b/MissionEditor/IsoView.cpp @@ -5506,6 +5506,7 @@ void CIsoView::DrawMap() SetError("Loading graphics"); theApp.m_loading->LoadUnitGraphic(buildingId); ::Map->UpdateBuildingInfo(&buildingId); + pic = buildinginfo[id].pic[0]; } if (pic.pic == NULL) { diff --git a/MissionEditor/Loading.cpp b/MissionEditor/Loading.cpp index 8687481..1d00972 100644 --- a/MissionEditor/Loading.cpp +++ b/MissionEditor/Loading.cpp @@ -1233,12 +1233,12 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) CString filename; // filename of the image char theat = cur_theat; // standard theater char is t (Temperat). a is snow. - BOOL bAlwaysSetChar = FALSE; // second char is always theater, even if NewTheater not specified! + bool bAlwaysSetChar = FALSE; // second char is always theater, even if NewTheater not specified! WORD wStep = 1; // step is 1 for infantry, buildings, etc, and for shp vehicles it specifies the step rate between every direction WORD wStartWalkFrame = 0; // for examply cyborg reaper has another walk starting frame int iTurretOffset = 0; // used for centering y pos of turret (if existing) (for vehicles) - const BOOL bStructure = rules["BuildingTypes"].HasValue(lpUnittype); // is this a structure? - const BOOL bVehicle = rules["VehicleTypes"].HasValue(lpUnittype); // is this a structure? + const bool bStructure = rules["BuildingTypes"].HasValue(lpUnittype); // is this a structure? + const bool bVehicle = rules["VehicleTypes"].HasValue(lpUnittype); // is this a structure? auto const bPowerUp = !rules.GetString(lpUnittype, "PowersUpBuilding").IsEmpty(); @@ -1314,7 +1314,6 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) SHPHEADER specialanim3_h; BYTE* specialanim4 = NULL; SHPHEADER specialanim4_h; - BYTE** lpT = NULL; SHPHEADER* lpT_h = NULL; std::vector turretColors[8]; std::vector turretLighting[8]; @@ -1360,8 +1359,8 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) FSunPackLib::VoxelNormalClass vnc = FSunPackLib::VoxelNormalClass::Unknown; - if (rules.GetBool(image, "Turret")) { - turretanim_name = rules.GetString(image, "TurretAnim"); + if (rules.GetBool(lpUnittype, "Turret")) { + turretanim_name = rules.GetString(lpUnittype, "TurretAnim"); auto vxl_turretanim_filename = turretanim_name.IsEmpty() ? image + "tur.vxl" : turretanim_name + ".vxl"; auto vxl_barrelanim_filename = image + "barl.vxl"; auto const& imageID = art.GetString(turretanim_name, "Image"); @@ -1369,40 +1368,40 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) vxl_turretanim_filename = imageID + ".vxl"; } - if (bStructure && turretanim_name.GetLength() > 0 && !rules.GetBool(image, "TurretAnimIsVoxel")) { + if (bStructure && turretanim_name.GetLength() > 0 && !rules.GetBool(lpUnittype, "TurretAnimIsVoxel")) { turretanim_filename = turretanim_name + ".shp"; auto const& imageID = art.GetString(turretanim_name, "Image"); if (!imageID.IsEmpty()) { turretanim_filename = imageID + ".shp"; } - - if (artSection.GetBool("NewTheater")) { + turretanim_filename.SetAt(1, 'G'); + if (artSection.GetBool("NewTheater", true)) { auto tmp = turretanim_filename; tmp.SetAt(1, theat); - if (FSunPackLib::XCC_DoesFileExist(tmp, hShpMix)) + if (FSunPackLib::XCC_DoesFileExist(tmp, hShpMix)) { turretanim_filename = tmp; + } } - + turretanim_filename.MakeUpper(); FSunPackLib::SetCurrentSHP(turretanim_filename, hShpMix); FSunPackLib::XCC_GetSHPHeader(&head); - int iStartTurret = 0; - const WORD wAnimCount = 4; // anims between each "normal" direction, seems to be hardcoded + auto const turretFrameStart = art.GetInteger(turretanim_name, "LoopStart"); + auto const turretFrameCount = art.GetInteger(turretanim_name, "LoopEnd", 32); + const WORD wAnimCount = turretFrameCount / 8; // anims between each "normal" direction - int i; - - for (i = 0; i < 8; i++) { - if (iStartTurret + i * wAnimCount < head.c_images) { - FSunPackLib::XCC_GetSHPImageHeader(iStartTurret + i * wAnimCount, &turretinfo[i]); + for (auto i = 0; i < 8; i++) { + if (turretFrameStart + i * wAnimCount < head.c_images) { + FSunPackLib::XCC_GetSHPImageHeader(turretFrameStart + i * wAnimCount, &turretinfo[i]); FSunPackLib::XCC_GetSHPHeader(&turrets_h[i]); - FSunPackLib::LoadSHPImage(iStartTurret + i * wAnimCount, turretColors[i]); + FSunPackLib::LoadSHPImage(turretFrameStart + i * wAnimCount, turretColors[i]); turretLighting[i].clear(); } } } else if ( - (bStructure && turretanim_name.GetLength() > 0 && rules.GetBool(image, "TurretAnimIsVoxel")) + (bStructure && !turretanim_name.IsEmpty() && rules.GetBool(lpUnittype, "TurretAnimIsVoxel")) || (!bStructure && (FindFileInMix(vxl_turretanim_filename) || FindFileInMix(vxl_barrelanim_filename))) ) { turretanim_filename = vxl_turretanim_filename; @@ -1545,17 +1544,16 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) if (bSuccess) { FSunPackLib::XCC_GetSHPHeader(&head); - int i; int maxPics = head.c_images; - if (maxPics > 8) { - maxPics = 8; // we only need 8 pictures for every direction! - } - if (bStructure && !bPowerUp && !rules.GetBool(image, "Turret")) { + if (bStructure && !bPowerUp) { maxPics = 1; } - if (bVoxelTurret) { + if (rules.GetBool(lpUnittype, "Turret")) { maxPics = 8; } + if (maxPics > 8) { + maxPics = 8; // we only need 8 pictures for every direction! + } if (!bStructure && rules.GetBool(image, "Turret")) { int iStartTurret = wStartWalkFrame + 8 * wStep; @@ -1572,32 +1570,23 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) // create an array of pointers to directdraw surfaces - lpT = new(BYTE * [maxPics]); + auto lpT = new(BYTE * [maxPics]); ::memset(lpT, 0, sizeof(BYTE) * maxPics); std::vector> lighting(maxPics); std::vector shp_image_headers(maxPics); - if (bVoxelTurret && bStructure) { - for (i = 0; i < maxPics; i++) { - FSunPackLib::LoadSHPImage(0, 1, &lpT[i]); - FSunPackLib::XCC_GetSHPImageHeader(0, &shp_image_headers[i]); - } - } else if (wStep == 1 && (rules.GetString(lpUnittype, "PowersUpBuilding").IsEmpty() || !rules.GetBool(lpUnittype, "Turret"))) { - // standard case... - FSunPackLib::LoadSHPImage(wStartWalkFrame, maxPics, lpT); - for (int i = 0; i < maxPics; ++i) { - FSunPackLib::XCC_GetSHPImageHeader(wStartWalkFrame + i, &shp_image_headers[i]); - } + if (lpUnittype == "CAWBNKR1") { + printf(""); + } - } else if (!rules.GetString(lpUnittype, "PowersUpBuilding").IsEmpty() && rules.GetBool(lpUnittype, "Turret")) { - // a "real" turret (vulcan cannon, etc...) - for (i = 0; i < maxPics; i++) { - FSunPackLib::LoadSHPImage(i * 4, 1, &lpT[i]); - FSunPackLib::XCC_GetSHPImageHeader(i * 4, &shp_image_headers[i]); + if (bStructure) { + for (auto i = 0; i < maxPics; i++) { + FSunPackLib::XCC_GetSHPImageHeader(0, &shp_image_headers[i]); + FSunPackLib::LoadSHPImage(0, 1, &lpT[i]); } - } else { + } else {// vehicle, infantry // walk frames used - for (i = 0; i < maxPics; i++) { + for (auto i = 0; i < maxPics; i++) { const int dir = bVehicle ? ((i + 1) % 8) : i; const int pic_in_file = dir * wStep + wStartWalkFrame; FSunPackLib::LoadSHPImage(pic_in_file, 1, &lpT[i]); @@ -1605,20 +1594,12 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) } } - for (i = 0; i < maxPics; i++) { - int pic_in_file = i; - if (bStructure && bVoxelTurret) pic_in_file = 0; - SHPIMAGEHEADER imghead = shp_image_headers[i]; - //FSunPackLib::XCC_GetSHPImageHeader(pic_in_file, &imghead); - + // this block handles one-direction only building frame + if (bStructure) { + SHPIMAGEHEADER imghead = shp_image_headers[0]; + auto blitDst = lpT[0]; if (bib != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, bib, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, bib, bib_h.cx, bib_h.cy); + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, bib, bib_h.cx, bib_h.cy); imghead.cx = head.cx - imghead.x; // update size of main graphic imghead.cy = head.cy - imghead.y; @@ -1626,144 +1607,73 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) } if (activeanim != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, activeanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, activeanim, activeanim_h.cx, activeanim_h.cy); + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, activeanim, activeanim_h.cx, activeanim_h.cy); } if (idleanim != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, idleanim, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, idleanim, idleanim_h.cx, idleanim_h.cy); + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, idleanim, idleanim_h.cx, idleanim_h.cy); } if (activeanim2 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, activeanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, activeanim2, activeanim2_h.cx, activeanim2_h.cy); + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, activeanim2, activeanim2_h.cx, activeanim2_h.cy); } if (activeanim3 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, activeanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, activeanim3, activeanim3_h.cx, activeanim3_h.cy); + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, activeanim3, activeanim3_h.cx, activeanim3_h.cy); } if (superanim1 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, superanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, superanim_1_zadjust, head.cx, head.cy, superanim1, superanim1_h.cx, superanim1_h.cy); - - + Blit_Pal(blitDst, 0, superanim_1_zadjust, head.cx, head.cy, superanim1, superanim1_h.cx, superanim1_h.cy); } if (superanim2 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, superanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, superanim_2_zadjust, head.cx, head.cy, superanim2, superanim2_h.cx, superanim2_h.cy); - - + Blit_Pal(blitDst, 0, superanim_2_zadjust, head.cx, head.cy, superanim2, superanim2_h.cx, superanim2_h.cy); } if (superanim3 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, superanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, superanim_3_zadjust, head.cx, head.cy, superanim3, superanim3_h.cx, superanim3_h.cy); - - + Blit_Pal(blitDst, 0, superanim_3_zadjust, head.cx, head.cy, superanim3, superanim3_h.cx, superanim3_h.cy); } - if (superanim4 != NULL && strcmp(lpUnittype, "YAGNTC") != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, superanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, superanim_4_zadjust, head.cx, head.cy, superanim4, superanim4_h.cx, superanim4_h.cy); + Blit_Pal(blitDst, 0, superanim_4_zadjust, head.cx, head.cy, superanim4, superanim4_h.cx, superanim4_h.cy); } - if (specialanim1 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, specialanim1, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, specialanim1, specialanim1_h.cx, specialanim1_h.cy); - - + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, specialanim1, specialanim1_h.cx, specialanim1_h.cy); } - if (specialanim2 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, specialanim2, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, specialanim2, specialanim2_h.cx, specialanim2_h.cy); - + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, specialanim2, specialanim2_h.cx, specialanim2_h.cy); } - if (specialanim3 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, specialanim3, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, specialanim3, specialanim3_h.cx, specialanim3_h.cy); - - + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, specialanim3, specialanim3_h.cx, specialanim3_h.cy); } if (specialanim4 != NULL) { - DDBLTFX fx; - - ::memset(&fx, 0, sizeof(DDBLTFX)); - fx.dwSize = sizeof(DDBLTFX); - - //lpT[i]->Blt(NULL, specialanim4, NULL, DDBLT_KEYSRC | DDBLT_WAIT , &fx); - Blit_Pal(lpT[i], 0, 0, head.cx, head.cy, specialanim4, specialanim4_h.cx, specialanim4_h.cy); + Blit_Pal(blitDst, 0, 0, head.cx, head.cy, specialanim4, specialanim4_h.cx, specialanim4_h.cy); } + } + + for (auto i = 0; i < maxPics; i++) { + SHPIMAGEHEADER* imghead = &shp_image_headers[i]; + if (bStructure) { + imghead = &shp_image_headers[0]; + if (!lpT[i]) { + auto const dataLen = imghead->cx * imghead->cy; + auto data = new(BYTE[dataLen]); + memcpy(data, lpT[0], dataLen); + lpT[i] = data; + } + } + //FSunPackLib::XCC_GetSHPImageHeader(pic_in_file, &imghead); + + if (!vxlBarrelLighting[i].empty() || !turretLighting[i].empty()) lighting[i].resize(head.cx * head.cy, 46); // value needs to lead to 1.0 lighting @@ -1823,24 +1733,26 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) ddsd.dwWidth = turrets_h[i].cx; ddsd.dwHeight = turrets_h[i].cy; - int XMover, YMover; - char c[50]; - itoa(i, c, 10); -#ifdef RA2_MODE - XMover = g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "X"); - YMover = g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "Y"); - XMover += g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "X" + c); - YMover += g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "Y" + c); -#else - XMover = g_data.GetInteger("BuildingVoxelTurrets", lpUnittype + "X"); - YMover = g_data.GetInteger("BuildingVoxelTurrets", lpUnittype + "Y"); -#endif + int XMover = 0; + int YMover = 0; RECT srcRect, destRect; if (bVoxelTurret) { - int mx = head.cx / 2 + rules.GetInteger(image, "TurretAnimX") - turretinfo[i].x; - int my = head.cy / 2 + rules.GetInteger(image, "TurretAnimY") - turretinfo[i].y; + int mx = head.cx / 2 + rules.GetInteger(lpUnittype, "TurretAnimX") - turretinfo[i].x; + int my = head.cy / 2 + rules.GetInteger(lpUnittype, "TurretAnimY") - turretinfo[i].y; + + char c[50]; + itoa(i, c, 10); +#ifdef RA2_MODE + XMover = g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "X"); + YMover = g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "Y"); + XMover += g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "X" + c); + YMover += g_data.GetInteger("BuildingVoxelTurretsRA2", lpUnittype + "Y" + c); +#else + XMover = g_data.GetInteger("BuildingVoxelTurrets", lpUnittype + "X"); + YMover = g_data.GetInteger("BuildingVoxelTurrets", lpUnittype + "Y"); +#endif srcRect.top = 0; srcRect.left = 0; @@ -1851,13 +1763,9 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) destRect.right = destRect.left + ddsd.dwWidth;; destRect.bottom = destRect.top + ddsd.dwHeight; - } else // !bVoxelTurret - { - - int mx = rules.GetInteger(image, "TurretAnimX"); - int my = rules.GetInteger(image, "TurretAnimY");//+rules.GetInteger(image, "barrelAnimZAdjust"); - - + } else {// !bVoxelTurret + int mx = rules.GetInteger(lpUnittype, "TurretAnimX"); + int my = rules.GetInteger(lpUnittype, "TurretAnimY");//+rules.GetInteger(image, "barrelAnimZAdjust"); srcRect.top = 0; srcRect.left = 0; @@ -1921,7 +1829,7 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) } - if (!bPowerUp && i != 0 && (imghead.unknown == 0 && !g_data.GetBool("Debug", "IgnoreSHPImageHeadUnused")) && bStructure) { + if (!bPowerUp && i != 0 && (imghead->unknown == 0 && !g_data.GetBool("Debug", "IgnoreSHPImageHeadUnused")) && bStructure) { if (lpT[i]) delete[] lpT[i]; lpT[i] = NULL; } else { @@ -1948,10 +1856,10 @@ BOOL CLoading::LoadUnitGraphic(const CString& lpUnittype) if (hPalette == m_hPalUnitTemp || hPalette == m_hPalUnitUrb || hPalette == m_hPalUnitSnow || hPalette == m_hPalUnitDes || hPalette == m_hPalUnitLun || hPalette == m_hPalUnitUbn) p.pal = iPalUnit; if (hPalette == m_hPalLib) p.pal = iPalLib; - p.x = imghead.x; - p.y = imghead.y; - p.wHeight = imghead.cy; - p.wWidth = imghead.cx; + p.x = imghead->x; + p.y = imghead->y; + p.wHeight = imghead->cy; + p.wWidth = imghead->cx; p.wMaxWidth = head.cx; p.wMaxHeight = head.cy; p.bType = PICDATA_TYPE_SHP; @@ -3643,7 +3551,7 @@ void CLoading::LoadOverlayGraphic(const CString& lpOvrlName_, int iOvrlNum) FSunPackLib::SetTSPaletteEntry(hPalette, 0x10 + i, &rgbNew, &rgbOld[i]); } - } + } #endif FSunPackLib::LoadSHPImage(0, maxPics, lpT); @@ -3703,10 +3611,10 @@ void CLoading::LoadOverlayGraphic(const CString& lpOvrlName_, int iOvrlNum) delete[] lpT; - } - } +} + int i; for (i = 0; i < 0xFF; i++) { char ic[50]; @@ -4435,21 +4343,21 @@ void CLoading::FreeAll() #endif i->second.pic = NULL; - } catch (...) { - CString err; - err = "Access violation while trying to release surface "; - char c[6]; - itoa(e, c, 10); - err += c; + } catch (...) { + CString err; + err = "Access violation while trying to release surface "; + char c[6]; + itoa(e, c, 10); + err += c; - err += "\n"; - OutputDebugString(err); - continue; + err += "\n"; + OutputDebugString(err); + continue; + } + + i++; } - i++; - } - try { @@ -4469,7 +4377,7 @@ void CLoading::FreeAll() } catch (...) { errstream << "Exception while freeing DirectDraw" << endl; } -} + } void CLoading::PostNcDestroy() { @@ -4738,7 +4646,7 @@ void CLoading::LoadStrings() //CCStrings[*rules.GetSectionName(i)].SetString=rul CCStrings[*rules.GetSectionName(i)].SetString((LPSTR)(LPCSTR)rules.GetSection(i)->values["Name"]); } - } +} #endif diff --git a/MissionEditor/MapData.cpp b/MissionEditor/MapData.cpp index 4ccab1c..b3bfb32 100644 --- a/MissionEditor/MapData.cpp +++ b/MissionEditor/MapData.cpp @@ -3493,6 +3493,10 @@ void CMapData::UpdateBuildingInfo(const CString* lpUnitType) buildinginfo[n].bUrban = TRUE; } + if (type == "NALASR") { + printf(""); + } + buildinginfo[n].pic_count = 8; for (auto k = 0; k < 8; k++) { lpPicFile = GetUnitPictureFilename(type, k); diff --git a/MissionEditor/inlines.h b/MissionEditor/inlines.h index 960aa89..8a3ba42 100644 --- a/MissionEditor/inlines.h +++ b/MissionEditor/inlines.h @@ -52,28 +52,20 @@ inline CString GetUnitPictureFilename(LPCTSTR lpUnitName, DWORD dwPicIndex) { CIniFile& ini = Map->GetIniFile(); - CString UnitName = lpUnitName; + auto artname = rules.GetStringOr(lpUnitName, "Image", lpUnitName); + artname = ini.GetStringOr(lpUnitName, "Image", artname); - UnitName = ini.GetString(lpUnitName, "Image"); - if (UnitName.IsEmpty()) { - UnitName = rules.GetString(lpUnitName, "Image"); - } - - CString artname = UnitName; - if (UnitName.IsEmpty()) { - artname = lpUnitName; - } - auto const shapeName = art.GetString(UnitName, "Image"); + auto const& shapeName = art.GetString(artname, "Image"); if (!shapeName.IsEmpty()) { - if (!g_data.GetBool("IgnoreArtImage", UnitName)) { + if (!g_data.GetBool("IgnoreArtImage", artname)) { artname = shapeName; } } - CString filename = UnitName; + CString filename = artname; - if (art.GetBool(UnitName, "NewTheater") && !art.GetBool(UnitName, "DemandLoad")) { + if (art.GetBool(artname, "NewTheater") && !art.GetBool(artname, "DemandLoad")) { filename.SetAt(1, 'T'); } @@ -81,7 +73,7 @@ inline CString GetUnitPictureFilename(LPCTSTR lpUnitName, DWORD dwPicIndex) _itoa_s(dwPicIndex, n, 10); - if (pics.find(artname + n) != pics.end()) { + if (pics.find((artname + n)) != pics.end()) { filename = artname; // yes, found filename += n; } else if (pics.find(artname + ".bmp") != pics.end()) // since June, 15th (Matze): Only use BMP if no SHP/VXL exists diff --git a/MissionEditorPackLib/MissionEditorPackLib.cpp b/MissionEditorPackLib/MissionEditorPackLib.cpp index 67b1149..115dc25 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.cpp +++ b/MissionEditorPackLib/MissionEditorPackLib.cpp @@ -558,26 +558,30 @@ namespace FSunPackLib return TRUE; }; - BOOL SetCurrentSHP(LPCSTR szSHP, HMIXFILE hOwner) + bool SetCurrentSHP(LPCSTR szSHP, HMIXFILE hOwner) { - if (cur_shp.is_open()) cur_shp.close(); + if (cur_shp.is_open()) { + cur_shp.close(); + } if (hOwner == NULL) { if (open_read(cur_shp, szSHP) != 0) { - return FALSE; + return false; } } else { - int id = mixfiles[hOwner - 1].get_id(mixfiles[hOwner - 1].get_game(), szSHP); - int size = mixfiles[hOwner - 1].get_size(id); - if (size == 0) + auto const id = mixfiles[hOwner - 1].get_id(mixfiles[hOwner - 1].get_game(), szSHP); + auto const size = mixfiles[hOwner - 1].get_size(id); + if (size == 0) { OutputDebugString("NULL size"); + return false; + } BYTE* b = new(BYTE[size]); mixfiles[hOwner - 1].seek(mixfiles[hOwner - 1].get_offset(id)); mixfiles[hOwner - 1].read(b, size); cur_shp.load(Cvirtual_binary(b, size)); } - return TRUE; + return true; }; BOOL XCC_GetTMPTileInfo(int iTile, POINT* lpPos, int* lpWidth, int* lpHeight, BYTE* lpDirection, BYTE* lpTileHeight, BYTE* lpTileType, RGBTRIPLE* lpRgbLeft, RGBTRIPLE* lpRgbRight) @@ -876,7 +880,7 @@ namespace FSunPackLib } - BOOL LoadSHPImage(int iImageIndex, int iCount, BYTE** lpPics) + BOOL LoadSHPImage(int startIndex, int wantedNum, BYTE** lpPics) { t_shp_ts_image_header imghead; BYTE* image = NULL; @@ -889,26 +893,22 @@ namespace FSunPackLib return FALSE; } - - - - int pic; std::vector decode_image_buffer; - for (pic = 0; pic < iCount; pic++) { - if (cur_shp.get_image_header(iImageIndex + pic)) { - imghead = *(cur_shp.get_image_header(iImageIndex + pic)); + for (auto frameIdx = 0; frameIdx < wantedNum; frameIdx++) { + if (cur_shp.get_image_header(startIndex + frameIdx)) { + imghead = *(cur_shp.get_image_header(startIndex + frameIdx)); // if(imghead.offset!=0) { - if (cur_shp.is_compressed(iImageIndex + pic)) { + if (cur_shp.is_compressed(startIndex + frameIdx)) { decode_image_buffer.resize(imghead.cx * imghead.cy); image = decode_image_buffer.data(); - decode3(cur_shp.get_image(iImageIndex + pic), image, imghead.cx, imghead.cy); + decode3(cur_shp.get_image(startIndex + frameIdx), image, imghead.cx, imghead.cy); } else - image = (unsigned char*)cur_shp.get_image(iImageIndex + pic); + image = (unsigned char*)cur_shp.get_image(startIndex + frameIdx); - lpPics[pic] = new(BYTE[head.cx * head.cy]); + lpPics[frameIdx] = new(BYTE[head.cx * head.cy]); int i, e; for (i = 0; i < head.cx; i++) { @@ -920,9 +920,9 @@ namespace FSunPackLib dwRead = (i - imghead.x) + (e - imghead.y) * imghead.cx; if (dwRead != 0xFFFFFFFF) { - lpPics[pic][dwWrite] = image[dwRead]; + lpPics[frameIdx][dwWrite] = image[dwRead]; } else - lpPics[pic][dwWrite] = 0; + lpPics[frameIdx][dwWrite] = 0; } diff --git a/MissionEditorPackLib/MissionEditorPackLib.h b/MissionEditorPackLib/MissionEditorPackLib.h index ef73036..aa83ccc 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.h +++ b/MissionEditorPackLib/MissionEditorPackLib.h @@ -181,7 +181,7 @@ namespace FSunPackLib BOOL SetCurrentTMP(LPCSTR szTMP, HMIXFILE hOwner); - BOOL SetCurrentSHP(LPCSTR szSHP, HMIXFILE hOwner); + bool SetCurrentSHP(LPCSTR szSHP, HMIXFILE hOwner); BOOL XCC_GetTMPTileInfo(int iTile, POINT* lpPos, int* lpWidth, int* lpHeight, BYTE* lpDirection, BYTE* lpTileHeight, BYTE* lpTileType, RGBTRIPLE* lpRgbLeft, RGBTRIPLE* lpRgbRight); @@ -195,7 +195,8 @@ namespace FSunPackLib BOOL LoadTMPImage(int iStart, int iCount, BYTE** lpTileArray); BOOL LoadSHPImageInSurface(IDirectDraw4* pdd, HTSPALETTE hPalette, int iImageIndex, int iCount, LPDIRECTDRAWSURFACE4* pdds); - BOOL LoadSHPImage(int iImageIndex, int iCount, BYTE** lpPics); + // load 'wantedNum' frames at 'startIndex' + BOOL LoadSHPImage(int startIndex, int wantedNum, BYTE** lpPics); BOOL LoadSHPImage(int iImageIndex, std::vector& pic); HTSPALETTE LoadTSPalette(LPCSTR szPalette, HMIXFILE hPaletteOwner);