From 5b0f5292610cf5b432776042331efbf3817d8544 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 21 Jun 2026 19:16:53 +0200 Subject: [PATCH] patched in IVAN3D --- Main/Include/command.h | 1 + Main/Include/game.h | 8 + Main/Include/iconf.h | 15 ++ Main/Include/igraph.h | 20 ++ Main/Include/ivandef.h | 13 ++ Main/Include/level.h | 2 + Main/Include/lterra.h | 3 + Main/Source/bodypart.cpp | 10 +- Main/Source/char.cpp | 43 +++- Main/Source/command.cpp | 12 + Main/Source/database.cpp | 1 + Main/Source/fluid.cpp | 12 +- Main/Source/game.cpp | 80 ++++++- Main/Source/iconf.cpp | 14 ++ Main/Source/igraph.cpp | 487 ++++++++++++++++++++++++++++++++++++++- Main/Source/item.cpp | 18 +- Main/Source/level.cpp | 143 ++++++++++++ Main/Source/lsquare.cpp | 17 +- Main/Source/lterra.cpp | 13 +- Main/Source/lterras.cpp | 3 +- Main/Source/rain.cpp | 5 +- Main/Source/smoke.cpp | 2 +- Main/Source/stack.cpp | 5 +- Main/Source/traps.cpp | 2 +- Script/define.dat | 12 + Script/glterra.dat | 4 + Script/olterra.dat | 18 ++ 27 files changed, 920 insertions(+), 43 deletions(-) diff --git a/Main/Include/command.h b/Main/Include/command.h index 9be4e1b3f..2c0dbad78 100644 --- a/Main/Include/command.h +++ b/Main/Include/command.h @@ -101,6 +101,7 @@ class commandsystem static truth AssignName(character*); static truth Search(character*); static truth Consume(character*, cchar*, cchar*, sorter, truth = false); + static truth Mode3(character*); static truth ShowWorldSeed(character*); #ifdef WIZARD static truth WizardMode(character*); diff --git a/Main/Include/game.h b/Main/Include/game.h index c669399bf..fdf15fe4c 100644 --- a/Main/Include/game.h +++ b/Main/Include/game.h @@ -20,6 +20,7 @@ #include "femath.h" #include "festring.h" #include "ivandef.h" +#include "iconf.h" #ifndef LIGHT_BORDER #define LIGHT_BORDER 80 @@ -288,6 +289,8 @@ class game static v2 CalculateScreenCoordinates(v2); static truth PosCurrentlyOnScreen(v2); static v2 ScreenCoordinatesToPos(v2); + static int AdjustForFacing(int d); + static int UnadjustForFacing(int d); static void BusyAnimation(); static void BusyAnimation(bitmap*, truth); static v2 PositionQuestion(cfestring&, v2, positionhandler = 0, positionkeyhandler = 0, truth = true); @@ -395,6 +398,9 @@ class game static lsquare* GetHighlightedMapNoteLSquare(); static bool ToggleShowMapNotes(); static bool CheckAddAutoMapNote(square* =NULL); + static void SetFacing(int x) { Mode3Facing = x; } + static int GetFacing(); + static const v2 GetFacingVector(int I) { return FacingVector[I]; } static int CheckAutoPickup(square* sqr = NULL); static void UpdateAutoPickUpMatching(); static int RotateMapNotes(); @@ -572,6 +578,8 @@ class game static int FreedomStoryState; static int AslonaStoryState; static int RebelStoryState; + static int Mode3Facing; + static const v2 FacingVector[]; static truth InGetCommand; static truth PlayerHurtByExplosion; static area* CurrentArea; diff --git a/Main/Include/iconf.h b/Main/Include/iconf.h index c1f8ac544..161d791c2 100644 --- a/Main/Include/iconf.h +++ b/Main/Include/iconf.h @@ -69,6 +69,16 @@ class ivanconfig static truth GetSmartOpenCloseApply() { return SmartOpenCloseApply.Value; } static truth IsSetupCustomKeys() { return SetupCustomKeys.Value; } static truth GetBeNice() { return BeNice.Value; } + static truth GetMode3() { return Mode3.Value; } + static void SwitchMode3() { Mode3.Value = !Mode3.Value; } + static truth GetIsoMode() { return IsoMode.Value; } + static truth GetShowAllInIso() { return ShowAllInIso.Value; } + static truth GetAnaglyph() { return Anaglyph.Value; } + static truth GetShowMiniMap() { return ShowMiniMap.Value; } + + static truth Mode3Iso() { return Mode3.Value && IsoMode.Value; } + static truth Mode3FPP() { return Mode3.Value && !IsoMode.Value; } + static int GetAltListItemPos() { return AltListItemPos.Value; } static truth GetPlaySounds() { return PlaySounds.Value; } static truth IsShowTurn() { return ShowTurn.Value; } @@ -274,6 +284,11 @@ class ivanconfig #endif static col24 ContrastLuminance; + static truthoption Mode3; + static truthoption IsoMode; + static truthoption ShowAllInIso; + static numberoption Anaglyph; + static truthoption ShowMiniMap; static truthoption PlaySounds; static truthoption ShowTurn; diff --git a/Main/Include/igraph.h b/Main/Include/igraph.h index 661fd2d4a..fc7c5422b 100644 --- a/Main/Include/igraph.h +++ b/Main/Include/igraph.h @@ -24,6 +24,7 @@ class rawbitmap; class outputfile; class inputfile; class festring; +struct blitdata; /* memcmp doesn't like alignment of structure members */ @@ -121,6 +122,13 @@ class igraph static void BlitBackGround(bitmap* bmpAt, v2 Pos, v2 Border); static void CreateBackGround(int); static bitmap* GenerateScarBitmap(int, int, int); + + /* IVAN3D additions */ + static int defx, defy; + static truth noCeiling; + static void fDrawRainPixel(v2 x, col16 c); + static void Blit3(const bitmap *b, blitdata &B, int mode); + static cbitmap* GetSmileyGraphic() { return Graphic[GR_SMILEY]; } static void AddOutlinesIfNeeded(); private: @@ -148,4 +156,16 @@ class igraph static int CurrentColorType; }; +#define MF_BLIT_FLAGS 15 + +#define MF_BLIT_LUMINANCE 1 +#define MF_BLIT_PRIORITY 2 +#define MF_BLIT_ALPHA 4 +#define MF_BLIT_MASKED 8 + +#define MF_BLIT_ALPHA_PRIORITY MF_BLIT_ALPHA | MF_BLIT_PRIORITY +#define MF_BLIT_ALPHA_LUMINANCE MF_BLIT_ALPHA | MF_BLIT_LUMINANCE +#define MF_BLIT_LUMINANCE_MASKED MF_BLIT_LUMINANCE | MF_BLIT_MASKED +#define MF_BLIT_MASKED_PRIORITY MF_BLIT_MASKED | MF_BLIT_PRIORITY + #endif diff --git a/Main/Include/ivandef.h b/Main/Include/ivandef.h index 149de2984..474cf23f1 100644 --- a/Main/Include/ivandef.h +++ b/Main/Include/ivandef.h @@ -1028,6 +1028,18 @@ cv2 SILHOUETTE_SIZE(48, 64); // it is TILE_SIZE*3,TILE_SIZE*4 tho.. #define FORCE_THE 8 #define SHOW_MATERIAL 16 // only works for terrains +/* IVAN3D Spatial Flags */ +#define MF_OBJECT 256 +#define MF_FLOOR 512 +#define MF_CEIL 1024 +#define MF_WALL 2048 +#define MF_ONFLOOR 4096 +#define MF_LOWWALL 8192 +#define MF_TABLE 16384 +#define MF_WINDOW 128 +#define MF_LARGE 64 +#define MF_STAIR 32 + /****************************/ /* Character DataBase flags */ /****************************/ @@ -1185,6 +1197,7 @@ cv2 TILE_V2(TILE_SIZE, TILE_SIZE); #define SQUARE_INDEX_MASK 0xFFFF #define ALLOW_ANIMATE 0x10000 #define ALLOW_ALPHA 0x20000 +#define DO_BLIT3 0x40000 #define TALENTS 5 diff --git a/Main/Include/level.h b/Main/Include/level.h index c66eccd80..d38aa8d55 100644 --- a/Main/Include/level.h +++ b/Main/Include/level.h @@ -37,6 +37,7 @@ class material; class team; struct node; struct emitter; +struct blitdata; template struct fearray; struct nodepointerstorer @@ -197,6 +198,7 @@ class level : public area void Explosion(character*, cfestring&, v2, int, truth = true, truth = false); truth CollectCreatures(charactervector&, character*, truth); void ApplyLSquareScript(const squarescript*); + virtual void Draw3(int x, int y, truth esp, blitdata &BlitData) const; void DrawHitEffects(cint XMin,cint XMax,cint YMin,cint YMax) const; virtual void Draw(truth) const; v2 GetEntryPos(ccharacter*, int) const; diff --git a/Main/Include/lterra.h b/Main/Include/lterra.h index e50c3722c..7774a6f62 100644 --- a/Main/Include/lterra.h +++ b/Main/Include/lterra.h @@ -50,6 +50,7 @@ struct lterraindatabase : public databasebase fearray MaterialConfigChances; long MaterialConfigChanceSum; int OKVisualEffects; + int SpatialFlags; col16 MaterialColorB; col16 MaterialColorC; col16 MaterialColorD; @@ -175,6 +176,7 @@ class glterrain : public lterrain, public gterrain virtual DATA_BASE_VALUE(const fearray&, MaterialConfigChances); virtual DATA_BASE_VALUE(long, MaterialConfigChanceSum); DATA_BASE_VALUE(int, OKVisualEffects); + DATA_BASE_VALUE(int, SpatialFlags); virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorB, int); virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorC, int); virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorD, int); @@ -288,6 +290,7 @@ class olterrain : public lterrain, public oterrain virtual DATA_BASE_VALUE(const fearray&, MaterialConfigChances); virtual DATA_BASE_VALUE(long, MaterialConfigChanceSum); DATA_BASE_VALUE(int, OKVisualEffects); + DATA_BASE_VALUE(int, SpatialFlags); virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorB, int); virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorC, int); virtual DATA_BASE_VALUE_WITH_PARAMETER(col16, MaterialColorD, int); diff --git a/Main/Source/bodypart.cpp b/Main/Source/bodypart.cpp index 7ddf08815..f88d3d218 100644 --- a/Main/Source/bodypart.cpp +++ b/Main/Source/bodypart.cpp @@ -2549,9 +2549,9 @@ void bodypart::Draw(blitdata& BlitData) const cbitmap* P = GraphicData.Picture[F]; if(BlitData.CustomData & ALLOW_ALPHA) - P->AlphaPriorityBlit(BlitData); + igraph::Blit3(P, BlitData, MF_BLIT_ALPHA_PRIORITY | MF_OBJECT); else - P->MaskedPriorityBlit(BlitData); + igraph::Blit3(P, BlitData, MF_BLIT_MASKED_PRIORITY | MF_OBJECT); if(Fluid && ShowFluids()) DrawFluids(BlitData); @@ -3014,7 +3014,7 @@ void bodypart::DrawEquipment(const graphicdata& GraphicData, blitdata& BlitData) if(EAF) { int F = !(BlitData.CustomData & ALLOW_ANIMATE) || EAF == 1 ? 0 : GET_TICK() & (EAF - 1); - GraphicData.Picture[F]->AlphaPriorityBlit(BlitData); + igraph::Blit3(GraphicData.Picture[F], BlitData, MF_BLIT_ALPHA_PRIORITY | MF_OBJECT); } } @@ -3424,9 +3424,9 @@ void dogtorso::Draw(blitdata& BlitData) const cbitmap* P = GraphicData.Picture[Index]; if(BlitData.CustomData & ALLOW_ALPHA) - P->AlphaPriorityBlit(BlitData); + igraph::Blit3(P, BlitData, MF_BLIT_ALPHA_PRIORITY | MF_OBJECT); else - P->MaskedPriorityBlit(BlitData); + igraph::Blit3(P, BlitData, MF_BLIT_MASKED_PRIORITY | MF_OBJECT); } void corpse::SetLifeExpectancy(int Base, int RandPlus) diff --git a/Main/Source/char.cpp b/Main/Source/char.cpp index 51f454cf2..b0acbd370 100644 --- a/Main/Source/char.cpp +++ b/Main/Source/char.cpp @@ -3674,11 +3674,38 @@ void character::PerformPlayerCommand(int Key, bool& HasActed, bool& ValidKeyPres int c; for(c = 0; c < DIRECTION_COMMAND_KEYS; ++c) - if(Key == game::GetMoveCommandKey(c)) - MoveByVector(game::GetMoveVector(c)); + if(Key == game::GetMoveCommandKey(c)){ + + if(ivanconfig::Mode3FPP() && !game::IsInWilderness()) + { + if(c == 3){ + game::SetFacing(game::AdjustForFacing(0)); + ValidKeyPressed = true; + } + if(c == 4){ + game::SetFacing(game::AdjustForFacing(2)); + ValidKeyPressed = true; + } + } + + if(!ValidKeyPressed){ + int d = game::AdjustForFacing(c); + if(!ivanconfig::Mode3FPP()) game::SetFacing(d); + MoveByVector(game::GetMoveVector(d)); + } + } if(Key >= KEY_CONTROLLER_DIRECTION + 1 && Key <= KEY_CONTROLLER_DIRECTION + 9) - MoveByVector(game::GetDirectionVectorForKey(Key)); + { + if(ivanconfig::GetMode3()) + { + auto v = game::GetDirectionVectorForKey(Key); + for(int c = 0; c < DIRECTION_COMMAND_KEYS; ++c) + if(game::GetMoveVector(c) == v) + MoveByVector(game::GetMoveVector(game::AdjustForFacing(c))); + } + else MoveByVector(game::GetDirectionVectorForKey(Key)); + } if(ValidKeyPressed) return; @@ -7423,30 +7450,32 @@ void character::Draw(blitdata& BlitData) const BlitData.Src.Y = 16; cint SquareIndex = BlitData.CustomData & SQUARE_INDEX_MASK; + const bitmap *b = (bitmap*) igraph::GetSymbolGraphic(); + if(GetTeam() == PLAYER->GetTeam() && !IsPlayer() && SquareIndex == GetTameSymbolSquareIndex()) { BlitData.Src.X = 32; - igraph::GetSymbolGraphic()->LuminanceMaskedBlit(BlitData); + igraph::Blit3(b, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_OBJECT); } if(IsFlying() && SquareIndex == GetFlySymbolSquareIndex()) { BlitData.Src.X = 128; - igraph::GetSymbolGraphic()->LuminanceMaskedBlit(BlitData); + igraph::Blit3(b, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_OBJECT); } if(IsSwimming() && SquareIndex == GetSwimmingSymbolSquareIndex()) { BlitData.Src.X = 240; - igraph::GetSymbolGraphic()->LuminanceMaskedBlit(BlitData); + igraph::Blit3(b, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_OBJECT); } if(GetAction() && GetAction()->IsUnconsciousness() && SquareIndex == GetUnconsciousSymbolSquareIndex()) { BlitData.Src.X = 224; - igraph::GetSymbolGraphic()->LuminanceMaskedBlit(BlitData); + igraph::Blit3(b, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_OBJECT); } BlitData.Src.X = BlitData.Src.Y = 0; diff --git a/Main/Source/command.cpp b/Main/Source/command.cpp index d141d4a6a..8fa759f0f 100644 --- a/Main/Source/command.cpp +++ b/Main/Source/command.cpp @@ -101,6 +101,7 @@ command* commandsystem::Command[] = new command(&Apply, "apply item", 'a', 'a', 'a', false), new command(&ApplyAgain, "apply last item again", 'A', 'A', 'A', false), new command(&Zap, "zap a wand", 'z', 'z', 'z', false), + new command(&Mode3, "switch 3D mode", 'Z', 'Z', 'Z', true), new command(&Read, "read", 'r', 'r', 'r', false), new command(&Eat, "eat", 'e', 'e', 'e', true), new command(&Drink, "drink liquid", 'D', 'D', 'D', true), @@ -1723,6 +1724,17 @@ truth commandsystem::ZapItem(character* Char, item* Item) } } +truth commandsystem::Mode3(character*) +{ + ivanconfig::SwitchMode3(); + if(ivanconfig::GetMode3()) + ADD_MESSAGE("3D mode activated."); + else + ADD_MESSAGE("Map mode activated."); + game::GetCurrentArea()->SendNewDrawRequest(); + return false; +} + truth commandsystem::Rest(character* Char) { if(Char->StateIsActivated(PANIC)) diff --git a/Main/Source/database.cpp b/Main/Source/database.cpp index 6be03e885..3699b4a1d 100644 --- a/Main/Source/database.cpp +++ b/Main/Source/database.cpp @@ -643,6 +643,7 @@ void databasecreator::CreateLTerrainDataBaseMemberMap() ADD_MEMBER(MaterialConfigChances); ADD_MEMBER(IsAbstract); ADD_MEMBER(OKVisualEffects); + ADD_MEMBER(SpatialFlags); ADD_MEMBER(MaterialColorB); ADD_MEMBER(MaterialColorC); ADD_MEMBER(MaterialColorD); diff --git a/Main/Source/fluid.cpp b/Main/Source/fluid.cpp index bec487267..98b573346 100644 --- a/Main/Source/fluid.cpp +++ b/Main/Source/fluid.cpp @@ -183,7 +183,7 @@ void fluid::Load(inputfile& SaveFile) void fluid::SimpleDraw(blitdata& BlitData) const { - Image.Picture->AlphaLuminanceBlit(BlitData); + igraph::Blit3(Image.Picture, BlitData, MF_BLIT_ALPHA_LUMINANCE | MF_FLOOR); } void fluid::Draw(blitdata& BlitData) const @@ -198,10 +198,10 @@ void fluid::Draw(blitdata& BlitData) const { /* Priority Bug!!! */ Picture->BlitAndCopyAlpha(igraph::GetFlagBuffer(), SpecialFlags); - igraph::GetFlagBuffer()->AlphaLuminanceBlit(BlitData); + igraph::Blit3(igraph::GetFlagBuffer(), BlitData, MF_BLIT_ALPHA_LUMINANCE | MF_OBJECT); } else - Picture->AlphaPriorityBlit(BlitData); + igraph::Blit3(Picture, BlitData, MF_BLIT_ALPHA_PRIORITY | MF_OBJECT); if(MotherItem && BlitData.CustomData & ALLOW_ANIMATE) Image.Animate(BlitData, SpecialFlags); @@ -425,10 +425,10 @@ void fluid::DrawGearPicture(blitdata& BlitData, int SpecialFlags) const if(SpecialFlags & 0x7) { Picture->BlitAndCopyAlpha(igraph::GetFlagBuffer(), SpecialFlags); - igraph::GetFlagBuffer()->AlphaPriorityBlit(BlitData); + igraph::Blit3(igraph::GetFlagBuffer(), BlitData, MF_BLIT_ALPHA_PRIORITY | MF_OBJECT); } else - GearImage->Picture->AlphaPriorityBlit(BlitData); + igraph::Blit3(GearImage->Picture, BlitData, MF_BLIT_ALPHA_PRIORITY | MF_OBJECT); if(BlitData.CustomData & ALLOW_ANIMATE) GearImage->Animate(BlitData, SpecialFlags); @@ -446,7 +446,7 @@ void fluid::DrawBodyArmorPicture(blitdata& BlitData, int SpecialFlags) const if(Index >= BODY_ARMOR_PARTS) Index = 0; - GearImage[Index].Picture->AlphaPriorityBlit(BlitData); + igraph::Blit3(GearImage[Index].Picture, BlitData, MF_BLIT_ALPHA_PRIORITY | MF_OBJECT); if(BlitData.CustomData & ALLOW_ANIMATE) GearImage[Index].Animate(BlitData, 0); diff --git a/Main/Source/game.cpp b/Main/Source/game.cpp index b104d1a8e..ca1973bed 100644 --- a/Main/Source/game.cpp +++ b/Main/Source/game.cpp @@ -195,6 +195,10 @@ festring game::DefaultWish; festring game::DefaultChangeMaterial; festring game::DefaultDetectMaterial; truth game::WizardMode; + +int game::Mode3Facing; +const v2 game::FacingVector[] = { v2(1,0), v2(1,1), v2(0,1), v2(-1,1), v2(-1,0), v2(-1,-1), v2(0,-1), v2(1,-1) }; + int game::AutoPlayMode=0; int game::SeeWholeMapCheatMode; truth game::GoThroughWallsCheat; @@ -2956,6 +2960,7 @@ void game::DrawEverythingNoBlit(truth AnimationDraw) GetWorldMap()->UpdateLOS(); } + if(!ivanconfig::GetMode3()) if(OnScreen(CursorPos)) { if(!IsInWilderness() || CurrentWSquareMap[CursorPos.X][CursorPos.Y]->GetLastSeen() || GetSeeWholeMapCheatMode()) @@ -2980,7 +2985,7 @@ void game::DrawEverythingNoBlit(truth AnimationDraw) if(!AnimationDraw) msgsystem::Draw(); - if(!bXBRZandFelist && OnScreen(CursorPos)) + if(!bXBRZandFelist && OnScreen(CursorPos) && !ivanconfig::GetMode3()) { v2 ScreenCoord = CalculateScreenCoordinates(CursorPos); blitdata B = { DOUBLE_BUFFER, @@ -3011,7 +3016,15 @@ void game::DrawEverythingNoBlit(truth AnimationDraw) igraph::DrawCursor(ScreenCoord, CursorData); } - if(!bXBRZandFelist && Player->IsEnabled()) + if((ivanconfig::GetMode3() && CursorPos != v2(-1,-1)) || OnScreen(CursorPos)) + { + igraph::defx = CursorPos.X; + igraph::defy = CursorPos.Y; + v2 ScreenCoordinates = CalculateScreenCoordinates(CursorPos); + igraph::DrawCursor(ScreenCoordinates, CursorData); + } + + if(!bXBRZandFelist && Player->IsEnabled() && !ivanconfig::GetMode3()) { if(Player->IsSmall()) { @@ -3062,6 +3075,31 @@ void game::DrawEverythingNoBlit(truth AnimationDraw) } } + if(ivanconfig::GetMode3() && !IsInWilderness()) + { + for(int c = 0; c < Player->GetBodyParts(); ++c) + { + arm* Arm = dynamic_cast (Player->GetBodyPart(c)); + + if(!Arm) continue; + + item* Wpn = Arm->GetWielded(); + if(!Wpn) continue; + + igraph::defx = Arm->IsRightArm() ? 1 : -1; + igraph::defy = -1; + blitdata BlitData = { DOUBLE_BUFFER, + { 0, 0 }, + { 0, 0 }, + { TILE_SIZE, TILE_SIZE }, + { ivanconfig::GetContrastLuminance() }, + TRANSPARENT_COLOR, + ALLOW_ANIMATE | ALLOW_ALPHA | DO_BLIT3 }; + + Wpn->Draw(BlitData); + } + } + if(!bXBRZandFelist){ for(size_t c = 0; c < SpecialCursorPos.size(); ++c){ if(OnScreen(SpecialCursorPos[c])) @@ -3702,11 +3740,43 @@ festring game::SaveName(cfestring& Base,bool bLoadingFromAnAutosave) return PathAndBaseSaveName; } +int MoveToFacing(int d) { + for(int k=0; k<8; k++) + if(game::GetFacingVector(k) == game::GetMoveVector(d)) + return k; + return DIR_ERROR; +} + +int FacingToMove(int d) { + for(int k=0; k<8; k++) + if(game::GetFacingVector(d) == game::GetMoveVector(k)) + return k; + return DIR_ERROR; +} + +int game::GetFacing() +{ + if(IsInWilderness()) return 0; + if(ivanconfig::Mode3FPP()) return MoveToFacing(Mode3Facing)+2; + if(ivanconfig::Mode3Iso()) return 7; + return 0; +} + +int game::AdjustForFacing(int f) +{ + return FacingToMove((MoveToFacing(f)+GetFacing())&7); +} + +int game::UnadjustForFacing(int f) +{ + return FacingToMove((MoveToFacing(f)-GetFacing())&7); +} + int game::GetMoveCommandKeyBetweenPoints(v2 A, v2 B) { for(int c = 0; c < EXTENDED_DIRECTION_COMMAND_KEYS; ++c) if((A + GetMoveVector(c)) == B) - return GetMoveCommandKey(c); + return GetMoveCommandKey(UnadjustForFacing(c)); return DIR_ERROR; } @@ -3731,7 +3801,7 @@ v2 game::GetDirectionVectorForKey(int Key) for(int c = 0; c < EXTENDED_DIRECTION_COMMAND_KEYS; ++c) if(Key == GetMoveCommandKey(c)) - return GetMoveVector(c); + return GetMoveVector(AdjustForFacing(c)); if(Key >= KEY_CONTROLLER_DIRECTION + 1 && Key <= KEY_CONTROLLER_DIRECTION + 9) { @@ -3794,7 +3864,7 @@ int game::DirectionQuestion(cfestring& Topic, truth RequireAnswer, truth AcceptY for(int c = 0; c < DIRECTION_COMMAND_KEYS; ++c) if(Key == GetMoveCommandKey(c)) - return c; + return AdjustForFacing(c); if(Key >= KEY_CONTROLLER_DIRECTION + 1 && Key <= KEY_CONTROLLER_DIRECTION + 9) { diff --git a/Main/Source/iconf.cpp b/Main/Source/iconf.cpp index 580667d17..f008bca3a 100644 --- a/Main/Source/iconf.cpp +++ b/Main/Source/iconf.cpp @@ -383,6 +383,13 @@ truthoption ivanconfig::UseExtraMenuGraphics("UseExtraMenuGraphics", &UseExtraMenuGraphicsChanger); #endif col24 ivanconfig::ContrastLuminance = NORMAL_LUMINANCE; + +truthoption ivanconfig::Mode3("Mode3", "play in 3D", "Play in 3D.", false); +truthoption ivanconfig::IsoMode("IsoMode", "Use isometric mode in 3D", "Use isometricmode in 3D.", false); +truthoption ivanconfig::ShowAllInIso("ShowAllInIso", "Show hidden things in ISO mode", "Show hidden things in ISO mode.", false); +truthoption ivanconfig::ShowMiniMap("ShowMiniMap", "Show mini-map in FPP mode", "Show mini-map in FPP mode.", false); +numberoption ivanconfig::Anaglyph("Anaglyph", "Anaglyph depth of FPP mode", "Anaglyph depth of FPP mode.", 0); + truthoption ivanconfig::PlaySounds( "PlaySounds", "Use sound effects", "Use sound effects for combat, explosions and more.", @@ -1283,6 +1290,13 @@ void ivanconfig::Initialize() configsystem::AddOption(fsCategory,&TransparentMapLM); configsystem::AddOption(fsCategory,&UseExtraMenuGraphics); + fsCategory="IVAN3D"; + configsystem::AddOption(fsCategory,&Mode3); + configsystem::AddOption(fsCategory,&IsoMode); + configsystem::AddOption(fsCategory,&ShowAllInIso); + configsystem::AddOption(fsCategory,&ShowMiniMap); + configsystem::AddOption(fsCategory,&Anaglyph); + fsCategory="Sounds"; configsystem::AddOption(fsCategory,&PlaySounds); diff --git a/Main/Source/igraph.cpp b/Main/Source/igraph.cpp index 15e9c6a37..351540623 100644 --- a/Main/Source/igraph.cpp +++ b/Main/Source/igraph.cpp @@ -167,6 +167,9 @@ void igraph::DrawCursor(v2 Pos, int CursorData, int Index) bitmap* CursorBitmap; int SrcX = 0; + if(ivanconfig::GetMode3() && !game::IsInWilderness()) + BlitData.CustomData |= DO_BLIT3; + if(CursorData & CURSOR_BIG) { CursorBitmap = BigCursor[CursorData&~CURSOR_FLAGS]; @@ -178,7 +181,7 @@ void igraph::DrawCursor(v2 Pos, int CursorData, int Index) if(!(CursorData & (CURSOR_FLASH|CURSOR_TARGET))) { - CursorBitmap->LuminanceMaskedBlit(BlitData); + Blit3(CursorBitmap, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_WALL | MF_FLOOR | MF_CEIL); return; } @@ -186,7 +189,7 @@ void igraph::DrawCursor(v2 Pos, int CursorData, int Index) { int Tick = GET_TICK() & 31; CursorBitmap->FillAlpha(95 + 10 * abs(Tick - 16)); - CursorBitmap->AlphaLuminanceBlit(BlitData); + Blit3(CursorBitmap, BlitData, MF_BLIT_ALPHA_LUMINANCE | MF_WALL | MF_FLOOR | MF_CEIL); return; } @@ -195,11 +198,11 @@ void igraph::DrawCursor(v2 Pos, int CursorData, int Index) int Base = Frame << 4; BlitData.Src.X = SrcX + (CursorData & CURSOR_BIG ? Base << 1 : Base); CursorBitmap->FillAlpha(255 - (Tick & 0xF) * 16); - CursorBitmap->AlphaLuminanceBlit(BlitData); + Blit3(CursorBitmap, BlitData, MF_BLIT_ALPHA_LUMINANCE | MF_WALL | MF_FLOOR | MF_CEIL); Base = ((Frame + 1) % 3) << 4; BlitData.Src.X = SrcX + (CursorData & CURSOR_BIG ? Base << 1 : Base); CursorBitmap->FillAlpha((Tick & 0xF) * 16); - CursorBitmap->AlphaLuminanceBlit(BlitData); + Blit3(CursorBitmap, BlitData, MF_BLIT_ALPHA_LUMINANCE | MF_WALL | MF_FLOOR | MF_CEIL); } tilemap::iterator igraph::AddUser(const graphicid& GI) @@ -756,3 +759,479 @@ void igraph::AddOutlinesIfNeeded() { // RawGraphic[GR_HUMANOID]->Save("test-humanoid.png"); // RawGraphic[GR_CHARACTER]->Save("test-character.png"); } + +int NewRedLuminance, NewGreenLuminance, NewBlueLuminance; + +void setLum(blitdata& B, int mode) { + if(!(mode & MF_BLIT_LUMINANCE_MASKED)) + NewRedLuminance = NewGreenLuminance = NewBlueLuminance = 0; + else { + NewRedLuminance = (B.Luminance >> 7 & 0x1F800) - 0x10000; + NewGreenLuminance = (B.Luminance >> 4 & 0xFE0) - 0x800; + NewBlueLuminance = (B.Luminance >> 2 & 0x3F) - 0x20; + } +} + +struct fpoint4 { + int x, y, z, ax; + fpoint4() {} + fpoint4(int X, int Y, int Z, int AX=0) {x=X; y=Y; z=Z; ax=AX;} +}; + +fpoint4 operator + (fpoint4& a, fpoint4& b) { + return fpoint4(a.x+b.x, a.y+b.y, a.z+b.z, a.ax+b.ax); +} + +struct fpoint { + bool ok; + float x; + float y; + fpoint() {ok = false;} + fpoint(fpoint4 i); +}; + +static inline float cross(fpoint a, fpoint b, int x, int y) { + return (x-a.x) * (b.y-a.y) - (b.x-a.x) * (y-a.y); +} + +#include "char.h" + +int currEye, cc, currAY; + +fpoint::fpoint(fpoint4 i) { + + int sx = game::GetScreenXSize(); + int sy = game::GetScreenYSize(); + + if(igraph::defy == -1) { + y = (26 - i.x - i.y) / 2.0; + if(y <= 0) {ok = false; return;} + x = i.x - i.y; + x = igraph::defx * (16+x); + if(cc == 1) x -= 2; + if(cc == 2) x += 2; + x = sx*8 + sy*2*x/y; + y = sy*8 + sy*32/y; + x += sx * currEye / 10.0; + ok = true; + return; + } + + float tx = i.x - PLAYER->GetPos().X * 64 - 32; + float ty = i.y - PLAYER->GetPos().Y * 64 - 32; + + if(ivanconfig::Mode3FPP()) { + + int fac = game::GetFacing(); + + float angle = fac * M_PI / 4; + + float S = -sin(angle); + float C = cos(angle); + + x = tx * C - ty * S + i.ax; + y = tx * S + ty * C + currAY; + + if(cc == 1) x += 2; + if(cc == 2) x -= 2; + + ok = y < -1e-6; + if(!ok) return; + + float eyelevel = (PLAYER->GetSize() * 64) / 300.0; + if(eyelevel > 63) eyelevel = 63; + + if(PLAYER -> IsFlying()) + eyelevel = 48 + sin(GET_TICK()/16.0); + + eyelevel = i.z - eyelevel; + + if(PLAYER -> TemporaryStateIsActivated(CONFUSED)) { + float angle = GET_TICK() * M_PI / 64; + tx = x; ty = eyelevel; + S = -sin(angle); + C = cos(angle); + x = C * tx + S * ty; + eyelevel = -S * tx + C * ty; + } + + x = sx * 8 - sy * 8 * x / y - 0.5; + x += sx * currEye / 10.0; + y = sy * 8 + sy * 8 * eyelevel / y - 0.5; + } + else { + x = tx - ty; y = tx + ty; + if(!ivanconfig::GetShowAllInIso()) x *= sqrt(3.0) / 2; + x = sx * 8 + x/2.0 + i.ax/2.0 - 0.5; + y = sy * 8 + y/4.0-i.z /2.0 - 0.5; + ok = true; + } +} + +static inline col16 apply(col16 SrcCol, col16 DestCol, alpha Alpha) { + int Red = (SrcCol & 0xF800) + NewRedLuminance; + int Green = (SrcCol & 0x7E0 ) + NewGreenLuminance; + int Blue = (SrcCol & 0x1F ) + NewBlueLuminance; + + if(cc == 2) + { + Green += (Red >> 14) << 5; + Blue += (Red >> 15); + } + if(cc == 1) + Red += ((Green >> 10) + (Blue >> 5)) << 11; + + if(Red >= 0) {if(Red > 0xF800) Red = 0xF800;} else Red = 0; + if(Green >= 0) {if(Green > 0x7E0 ) Green = 0x7E0 ;} else Green = 0; + if(Blue >= 0) {if(Blue > 0x1F ) Blue = 0x1F ;} else Blue = 0; + + int DestRed = (DestCol & 0xF800); + int DestGreen = (DestCol & 0x7E0); + int DestBlue = (DestCol & 0x1F); + + if(cc != 2) + Red = (((Red - DestRed) * Alpha >> 8) + DestRed) & 0xF800; + else + Red = DestRed; + if(cc != 1) + { + Green = (((Green - DestGreen) * Alpha >> 8) + DestGreen) & 0x7E0; + Blue = ((Blue - DestBlue) * Alpha >> 8) + DestBlue; + } + else + { + Green = DestGreen; + Blue = DestBlue; + } + return Red | Green | Blue; +} + +struct boundbox { + int xmin, ymin, xmax, ymax; + boundbox(fpoint bp[4]) { + int sx = game::GetScreenXSize(); + int sy = game::GetScreenYSize(); + + xmin = sx*16; ymin = sy*16; xmax = 0; ymax = 0; + + for(int k=0; k<4; k++) { + if(bp[k].x < xmin) xmin = int(floor(bp[k].x)); + if(bp[k].x > xmax) xmax = int(ceil (bp[k].x)); + if(bp[k].y < ymin) ymin = int(floor(bp[k].y)); + if(bp[k].y > ymax) ymax = int(ceil (bp[k].y)); + } + + if(xmin < 0) xmin = 0; if(xmax >= sx*16) xmax = sx*16-1; + if(ymin < 0) ymin = 0; if(ymax >= sy*16) ymax = sy*16-1; + } +}; + +void fDrawRect(fpoint a, fpoint b, fpoint c, fpoint d, col16 SrcCol, alpha Alpha) { + + fpoint p[4]; + p[0] = a; p[1] = b; p[2] = c; p[3] = d; + if((!a.ok) || (!b.ok) || (!c.ok) || (!d.ok)) return; + boundbox bb(p); + + for(int x=bb.xmin; x<=bb.xmax; x++) for(int y=bb.ymin; y<=bb.ymax; y++) { + if(cross(a,b,x,y) > -1e-6 && + cross(b,c,x,y) > +1e-6 && + cross(c,d,x,y) > +1e-6 && + cross(d,a,x,y) > -1e-6 + ) { + + col16 DestCol = DOUBLE_BUFFER->GetPixel(16+x, 32+y); + + DOUBLE_BUFFER->PutPixel(16+x, 32+y, apply(SrcCol, DestCol, Alpha)); + } + } +} + +#define SetCA \ + col16 c = b->GetPixel(B.Src.X+px, B.Src.Y+py); \ + if(c == mask) continue; \ + if(non != -1) { Alpha = (c == non) ? 192 : 256; } \ + if((mode & MF_BLIT_ALPHA) && b->GetAlphaMap()) \ + Alpha = b->GetAlpha(B.Src.X+px, B.Src.Y+py); \ + +#define RF2(x) (RF(x+1)?x+1:x) +#define RF4(x) (RF(x+2)?RF2(x+2):RF2(x)) +#define RF8(x) (RF(x+4)?RF4(x+4):RF4(x)) +#define RF16(v) if(RF(8)) \ + {if(RF(16)) continue; v = RF8(8);} else {if(!RF(0)) continue; v = RF8(0);} + +void tileRect(const bitmap *b, blitdata &B, int mode, + fpoint4 corner, fpoint4 dx, fpoint4 dy, bool mirror, int non) { + + if(ivanconfig::GetAnaglyph() && (currEye == 0)) + { + currEye = ivanconfig::GetAnaglyph(); cc = 1; + tileRect(b,B,mode,corner,dx,dy,mirror,non); + currEye = -ivanconfig::GetAnaglyph(); cc = 2; + tileRect(b,B,mode,corner,dx,dy,mirror,non); + currEye = 0; cc = 0; + return; + } + if(igraph::defy != -1) { + corner.x += igraph::defx * 64; + corner.y += igraph::defy * 64; + } + fpoint4 p[32][32]; + fpoint pt[32][32]; + p[0][0] = corner; + for(int py=0; py<16; py++) p[py+1][0] = p[py][0] + dy; + for(int py=0; py<=16; py++) { + for(int px=0; px<16; px++) p[py][px+1] = p[py][px] + dx; + } + for(int py=0; py<=16; py++) { + pt[py][0] = fpoint(p[py][0]); + pt[py][16] = fpoint(p[py][16]); + pt[0][py] = fpoint(p[0][py]); + pt[16][py] = fpoint(p[16][py]); + } + int Alpha = 256; + int mask = B.MaskColor; + if((!pt[0][0].ok) && (!pt[0][16].ok) && (!pt[16][0].ok) && (!pt[16][16].ok)) + return; + if(pt[0][0].ok && pt[0][16].ok && pt[16][0].ok && pt[16][16].ok) { + fpoint p[4]; + p[0] = pt[0][0]; p[1] = pt[0][16]; p[2] = pt[16][0]; p[3] = pt[16][16]; + boundbox bb(p); + for(int x=bb.xmin; x<=bb.xmax; x++) for(int y=bb.ymin; y<=bb.ymax; y++) { + int px, py; + if(mirror) { +#define RF(c) (cross(pt[0][c], pt[16][c], x,y) > -1e-6) + RF16(px); +#undef RF +#define RF(c) (cross(pt[c][0], pt[c][16], x,y) < -1e-6) + RF16(py); +#undef RF + } + else { +#define RF(c) (cross(pt[0][c], pt[16][c], x,y) < -1e-6) + RF16(px); +#undef RF +#define RF(c) (cross(pt[c][0], pt[c][16], x,y) > -1e-6) + RF16(py); +#undef RF + } + SetCA; + col16 DestCol = DOUBLE_BUFFER->GetPixel(16+x, 32+y); + DOUBLE_BUFFER->PutPixel(16+x, 32+y, apply(c, DestCol, Alpha)); + } + } + else { + for(int px=1; px<16; px++) for(int py=1; py<16; py++) + pt[py][px] = fpoint(p[py][px]); + for(int px=0; px<16; px++) for(int py=0; py<16; py++) { + SetCA; + if(mirror) + fDrawRect(pt[py][px], pt[py+1][px], pt[py+1][px+1], pt[py][px+1], c,Alpha); + else + fDrawRect(pt[py][px], pt[py][px+1], pt[py+1][px+1], pt[py+1][px], c,Alpha); + } + } +} + +void tileObject(const bitmap *b, blitdata &B, int mode); + +void tileFloor(const bitmap *b, blitdata &B, int mode) { + tileRect(b, B, mode, + fpoint4(0,0,0), fpoint4(4,0,0), fpoint4(0,4,0), true, -1 + ); +} + +void tileTable(const bitmap *b, blitdata &B, int mode) { + tileRect(b, B, mode, + fpoint4(0,0,16), fpoint4(4,0,0), fpoint4(0,4,0), true, -1 + ); +} + +void tileCeil(const bitmap *b, blitdata &B, int mode) { + tileRect(b, B, mode, + fpoint4(0,0,64), fpoint4(4,0,0), fpoint4(0,4,0), false, -1 + ); +} + +void tileWalls(const bitmap *b, blitdata &B, int mode) { + if(!ivanconfig::Mode3Iso()) + tileRect(b, B, mode, + fpoint4(64,0,64), fpoint4(-4,0,0), fpoint4(0,0,-4), true, -1 + ); + tileRect(b, B, mode, + fpoint4(64,64,64), fpoint4(0,-4,0), fpoint4(0,0,-4), true, -1 + ); + tileRect(b, B, mode, + fpoint4(0,64,64), fpoint4(4,0,0), fpoint4(0,0,-4), true, -1 + ); + if(!ivanconfig::Mode3Iso()) + tileRect(b, B, mode, + fpoint4(0,0,64), fpoint4(0,4,0), fpoint4(0,0,-4), true, -1 + ); + if(ivanconfig::Mode3Iso()) + tileRect(b, B, mode, + fpoint4(0,0,64), fpoint4(4,0,0), fpoint4(0,4,0), true, -1 + ); +} + +void tileWindow(const bitmap *b, blitdata &B, int mode) { + int cw = b->GetPixel(8,8); + if(ivanconfig::Mode3Iso()) cw = -1; + if(!ivanconfig::Mode3Iso()) + tileRect(b, B, mode, + fpoint4(64,0,64), fpoint4(-4,0,0), fpoint4(0,0,-4), true, cw + ); + tileRect(b, B, mode, + fpoint4(64,64,64), fpoint4(0,-4,0), fpoint4(0,0,-4), true, cw + ); + tileRect(b, B, mode, + fpoint4(0,64,64), fpoint4(4,0,0), fpoint4(0,0,-4), true, cw + ); + if(!ivanconfig::Mode3Iso()) + tileRect(b, B, mode, + fpoint4(0,0,64), fpoint4(0,4,0), fpoint4(0,0,-4), true, cw + ); + if(ivanconfig::Mode3Iso()) + tileRect(b, B, mode, + fpoint4(0,0,64), fpoint4(4,0,0), fpoint4(0,4,0), true, -1 + ); +} + +void tileLowWalls(const bitmap *b, blitdata &B, int mode) { + if(!ivanconfig::Mode3Iso()) + tileRect(b, B, mode, + fpoint4(64,0,16), fpoint4(-4,0,0), fpoint4(0,0,-1), true, -1 + ); + tileRect(b, B, mode, + fpoint4(64,64,16), fpoint4(0,-4,0), fpoint4(0,0,-1), true, -1 + ); + tileRect(b, B, mode, + fpoint4(0,64,16), fpoint4(4,0,0), fpoint4(0,0,-1), true, -1 + ); + if(!ivanconfig::Mode3Iso()) + tileRect(b, B, mode, + fpoint4(0,0,16), fpoint4(0,4,0), fpoint4(0,0,-1), true, -1 + ); +} + +void tileObject(const bitmap *b, blitdata &B, int mode) { + currAY = 24; + tileRect(b, B, mode, + fpoint4(32,32,64,-32), fpoint4(0,0,0,4), fpoint4(0,0,-4), true, -1 + ); + currAY = 0; +} + +void tileLarge(const bitmap *b, blitdata &B, int mode) { + int i = B.CustomData & SQUARE_INDEX_MASK; + int cx = 1-i&1, cy = 1-(i>>1)&1; + if(ivanconfig::Mode3Iso()) { + tileRect(b, B, mode, + fpoint4(cx*64,cy*64,64+cy*64,-cx*64), fpoint4(0,0,0,4), fpoint4(0,0,-4), true, -1 + ); + return; + } + currAY = 64; + tileRect(b, B, mode, + fpoint4(cx*64,cy*64,32+cy*32,-cx*48), fpoint4(0,0,0,3), fpoint4(0,0,-2), true, -1 + ); + currAY = 0; +} + +void tileOnFloor(const bitmap *b, blitdata &B, int mode) { + int m = B.CustomData & SQUARE_INDEX_MASK; + if(m) + { + if(m == 1+DOWN) + tileRect(b, B, mode, + fpoint4(0,0,48), fpoint4(4,0,0), fpoint4(0,0,-4), true, -1 + ); + if(m == 1+LEFT) + tileRect(b, B, mode, + fpoint4(64,0,-16), fpoint4(0,0,4), fpoint4(0,4,0), true, -1 + ); + if(m == 1+UP) + tileRect(b, B, mode, + fpoint4(0,64,-16), fpoint4(4,0,0), fpoint4(0,0,4), true, -1 + ); + if(m == 1+RIGHT) + tileRect(b, B, mode, + fpoint4(0,0,48), fpoint4(0,0,-4), fpoint4(0,4,0), true, -1 + ); + return; + } + if(ivanconfig::Mode3Iso()) { + tileObject(b, B, mode); + return; + } + + for(int y=15; y>=0; y--) + for(int x=0; x<16; x++) + if(b->GetPixel(x,y) != B.MaskColor) + { + currAY = 12; + tileRect(b, B, mode, + fpoint4(32,32,2*y+2,-16), fpoint4(0,0,0,2), fpoint4(0,0,-2), true, -1 + ); + currAY = 0; + return; + } +} + +void igraph::fDrawRainPixel(v2 p, col16 c) { + NewRedLuminance = NewGreenLuminance = NewBlueLuminance = 0; + fDrawRect( + fpoint(fpoint4(defx*64+32, defy*64+32, 64-p.Y*4, p.X*4-32)), + fpoint(fpoint4(defx*64+32, defy*64+32, 60-p.Y*4, p.X*4-32)), + fpoint(fpoint4(defx*64+32, defy*64+32, 60-p.Y*4, p.X*4-28)), + fpoint(fpoint4(defx*64+32, defy*64+32, 64-p.Y*4, p.X*4-28)), + c,255 + ); + } + +int igraph::defx; +int igraph::defy; +truth igraph::noCeiling; + +#include + +void igraph::Blit3(const bitmap *b, blitdata &B, int mode) { + + if(!(B.CustomData & DO_BLIT3)) switch(mode & MF_BLIT_FLAGS) { + case MF_BLIT_ALPHA_PRIORITY: b->AlphaPriorityBlit(B); return; + case MF_BLIT_ALPHA_LUMINANCE: b->AlphaLuminanceBlit(B); return; + case MF_BLIT_MASKED_PRIORITY: b->MaskedPriorityBlit(B); return; + case MF_BLIT_LUMINANCE_MASKED: b->LuminanceMaskedBlit(B); return; + default: + ADD_MESSAGE("Unknown flag %d.\n", mode); + ivanconfig::SwitchMode3(); + } + setLum(B, mode); + + if(defy == -1) + { + truth tr = defx != -1; + if(b->GetPixel(12,12) != B.MaskColor) + tileRect(b, B, mode, + fpoint4(0,0,0), fpoint4(1,0,0), fpoint4(0,1,0), tr, -1 + ); + else + tileRect(b, B, mode, + fpoint4(15,0,0), fpoint4(-1,0,0), fpoint4(0,1,0), !tr, -1 + ); + return; + } + + currEye = 0; + + if(mode & MF_FLOOR) tileFloor (b, B, mode); + if(mode & MF_CEIL) tileCeil (b, B, mode); + if(mode & MF_OBJECT) tileObject (b, B, mode); + if(mode & MF_STAIR) if(ivanconfig::Mode3Iso()) tileObject (b, B, mode); + if(mode & MF_ONFLOOR) tileOnFloor (b, B, mode); + if(mode & MF_WALL) tileWalls (b, B, mode); + if(mode & MF_LOWWALL) tileLowWalls(b, B, mode); + if(mode & MF_TABLE) tileTable (b, B, mode); + if(mode & MF_WINDOW) tileWindow (b, B, mode); + if(mode & MF_LARGE) tileLarge (b, B, mode); + } diff --git a/Main/Source/item.cpp b/Main/Source/item.cpp index d8a33ca7b..acae9d3b8 100644 --- a/Main/Source/item.cpp +++ b/Main/Source/item.cpp @@ -1513,10 +1513,20 @@ void item::Draw(blitdata& BlitData) const } cbitmap* P = bmp; + if(GetSquarePosition() != CENTER) + { + BlitData.CustomData |= 1 + GetSquarePosition(); + } + if(BlitData.CustomData & ALLOW_ALPHA) - P->AlphaLuminanceBlit(BlitData); + igraph::Blit3(P, BlitData, MF_BLIT_ALPHA_LUMINANCE | MF_ONFLOOR); else - P->LuminanceMaskedBlit(BlitData); + igraph::Blit3(P, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_ONFLOOR); + + if(GetSquarePosition() != CENTER) + { + BlitData.CustomData &= ~SQUARE_INDEX_MASK; + } if(Fluid && ShowFluids()) DrawFluids(BlitData); @@ -1536,9 +1546,9 @@ void item::LargeDraw(blitdata& BlitData) const cbitmap* P = GraphicData.Picture[F]; if(BlitData.CustomData & ALLOW_ALPHA) - P->AlphaLuminanceBlit(BlitData); + igraph::Blit3(P, BlitData, MF_BLIT_ALPHA_LUMINANCE | MF_LARGE); else - P->LuminanceMaskedBlit(BlitData); + igraph::Blit3(P, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_LARGE); } void item::DonateIDTo(item* Item) diff --git a/Main/Source/level.cpp b/Main/Source/level.cpp index 6bb619e6e..718d8cd9a 100644 --- a/Main/Source/level.cpp +++ b/Main/Source/level.cpp @@ -1307,6 +1307,69 @@ void level::DrawHitEffects(cint XMin,cint XMax,cint YMin,cint YMax) const } } +void level::Draw3(int x, int y, truth esp, blitdata& BlitData) const { + + if(!(x >= 0 && y >= 0 && x < XSize && y < YSize)) return; + + const ulong LOSTick = game::GetLOSTick(); + + igraph::defx = x; + igraph::defy = y; + + if(ivanconfig::Mode3Iso()) + { + int px = PLAYER->GetPos().X; + int py = PLAYER->GetPos().Y; + if(x+y > px+py+16) return; + if(x+y < px+py-16) return; + if(x-y > px-py+14) return; + if(x-y < px-py-14) return; + } + + const lsquare* Square = Map[x][y]; + const ulong LastSeen = Square->LastSeen; + Square->Flags |= STRONG_NEW_DRAW_REQUEST; + + if(LastSeen == LOSTick) { + if(!esp) Square->Draw(BlitData); + } + else + { + if(ivanconfig::Mode3Iso() && ivanconfig::GetShowAllInIso()) + { + Square->Flags |= STRONG_NEW_DRAW_REQUEST; + + BlitData.Dest.X = RES.X - 64; + BlitData.Dest.Y = RES.Y - 64; + + if(LastSeen == LOSTick) + Square->Draw(BlitData); + else if(Square->Flags & STRONG_BIT || LastSeen == LOSTick - 2) + Square->DrawMemorized(BlitData); + BlitData.Src.X = RES.X - 64; + BlitData.Src.Y = RES.Y - 64; + + festring s = Square->GetMemorizedDescription(); + truth b = s.Find("wall") != festring::NPos; + if(b) b = ! (s.Find("on the wall") != festring::NPos); + if(!b) b = s.Find("earth") != festring::NPos; + if(!b) b = s.Find("door") != festring::NPos; + if(b) + igraph::Blit3(DOUBLE_BUFFER, BlitData, MF_WALL); + else + igraph::Blit3(DOUBLE_BUFFER, BlitData, MF_FLOOR); + BlitData.Src.X = 0; + BlitData.Src.Y = 0; + } + if(esp) + { + const character* C = Square->Character; + if(C && C->CanBeSeenByPlayer()) + Square->DrawMemorizedCharacter(BlitData); + } + } +} + void level::Draw(truth AnimationDraw) const { cint XMin = Max(game::GetCamera().X, 0); @@ -1322,6 +1385,62 @@ void level::Draw(truth AnimationDraw) const TRANSPARENT_COLOR, ALLOW_ANIMATE|ALLOW_ALPHA }; + if(ivanconfig::Mode3FPP()) { + int sx = game::GetScreenXSize(); + int sy = game::GetScreenYSize(); + BlitData.CustomData |= DO_BLIT3; + + col16 c = BLACK; + if(game::GetCurrentDungeonIndex() == NEW_ATTNAM) c = BLUE; + if(game::GetCurrentDungeonIndex() == ATTNAM) c = LIGHT_GRAY; + if((game::GetCurrentDungeonIndex() == ELPURI_CAVE) && + (game::GetCurrentLevelIndex() == OREE_LAIR)) c = 0x3800; + + DOUBLE_BUFFER->Fill(16,32,sx*16, sy*16, c); + + int px = PLAYER->GetPos().X; + int py = PLAYER->GetPos().Y; + for(int t=0; t<2; t++) + { + for(int d=20; d>=1; d--) { + Draw3(px+d,py+d, t==1, BlitData); + Draw3(px-d,py+d, t==1, BlitData); + Draw3(px+d,py-d, t==1, BlitData); + Draw3(px-d,py-d, t==1, BlitData); + for(int e=d-1; e>0; e--) { + Draw3(px+d, py+e, t==1, BlitData); + Draw3(px+d, py-e, t==1, BlitData); + Draw3(px-d, py+e, t==1, BlitData); + Draw3(px-d, py-e, t==1, BlitData); + Draw3(px+e, py+d, t==1, BlitData); + Draw3(px+e, py-d, t==1, BlitData); + Draw3(px-e, py+d, t==1, BlitData); + Draw3(px-e, py-d, t==1, BlitData); + } + Draw3(px+d,py, t==1, BlitData); + Draw3(px-d,py, t==1, BlitData); + Draw3(px,py+d, t==1, BlitData); + Draw3(px,py-d, t==1, BlitData); + } + Draw3(px,py, t==1, BlitData); + } + } + else + if(ivanconfig::Mode3Iso()) { + int sx = game::GetScreenXSize(); + int sy = game::GetScreenYSize(); + + DOUBLE_BUFFER->Fill(16,32,sx*16, sy*16, BLACK); + BlitData.CustomData |= DO_BLIT3; + + for(int x=0; xDraw(BlitData); } } + if(ivanconfig::Mode3FPP() && ivanconfig::GetShowMiniMap()) { + BlitData.CustomData &= ~DO_BLIT3; + for(int rx = -2; rx <= 2; ++rx) + { + for(int ry = -2; ry <= 2; ++ry) + { + int x = rx + PLAYER->GetPos().X; + int y = ry + PLAYER->GetPos().Y; + if(x < 0 || y < 0 || x >= XSize || y >= YSize) continue; + const lsquare* Square = Map[x][y]; + const ulong LastSeen = Square->LastSeen; + + Square->Flags |= STRONG_NEW_DRAW_REQUEST; + + BlitData.Dest.X = RES.X - 64 + 16 * rx; + BlitData.Dest.Y = RES.Y - 64 + 16 * ry; + + if(LastSeen == LOSTick) + Square->Draw(BlitData); + else if(Square->Flags & STRONG_BIT || LastSeen == LOSTick - 2) + Square->DrawMemorized(BlitData); + } + } + } DrawHitEffects(XMin,XMax,YMin,YMax); // so it will be drawn above everything else } diff --git a/Main/Source/lsquare.cpp b/Main/Source/lsquare.cpp index f0ffcb95d..e35b54e2e 100644 --- a/Main/Source/lsquare.cpp +++ b/Main/Source/lsquare.cpp @@ -228,10 +228,23 @@ void lsquare::DrawStaticContents(blitdata& BlitData) const if(StaticContentCache.Luminance != BlitData.Luminance) UpdateStaticContentCache(BlitData.Luminance); - StaticContentCache.Bitmap->FastBlit(BlitData.Bitmap, BlitData.Dest); - return; + if(!(BlitData.CustomData & DO_BLIT3)) { + StaticContentCache.Bitmap->FastBlit(BlitData.Bitmap, BlitData.Dest); + return; + } } + igraph::noCeiling = + GetLevel()->IsOnGround() && + ((game::GetCurrentDungeonIndex() == NEW_ATTNAM) || + (game::GetCurrentDungeonIndex() == ATTNAM) || + (game::GetCurrentDungeonIndex() == ASLONA_CASTLE) || + (game::GetCurrentDungeonIndex() == REBEL_CAMP) || + (game::GetCurrentDungeonIndex() == MONDEDR) || + (game::GetCurrentDungeonIndex() == DARK_FOREST) || + (game::GetCurrentDungeonIndex() == IRINOX) + ) && !IsInside(); + if(!OLTerrain || OLTerrain->ShowThingsUnder()) GLTerrain->Draw(BlitData); diff --git a/Main/Source/lterra.cpp b/Main/Source/lterra.cpp index 89619c6d0..a12e3de56 100644 --- a/Main/Source/lterra.cpp +++ b/Main/Source/lterra.cpp @@ -355,6 +355,8 @@ int olterrainprototype::CreateSpecialConfigurations(olterraindatabase** TempConf ConfigDataBase->PostFix << "with a window"; ConfigDataBase->IsAlwaysTransparent = true; ConfigDataBase->BitmapPos = ConfigDataBase->WindowBitmapPos; + ConfigDataBase->SpatialFlags &= ~MF_WALL; + ConfigDataBase->SpatialFlags |= MF_WINDOW; TempConfig[Configs++] = ConfigDataBase; } } @@ -401,6 +403,8 @@ v2 glterrain::GetBorderBitmapPos(v2 BasePos, int I) const void glterrain::Draw(blitdata& BlitData) const { + int flags = MF_BLIT_LUMINANCE_MASKED|GetSpatialFlags(); + if(igraph::noCeiling) flags = MF_BLIT_LUMINANCE_MASKED|MF_FLOOR; if(UseBorderTiles()) { cint TrueAF = GraphicData.AnimationFrames / 9; @@ -409,13 +413,13 @@ void glterrain::Draw(blitdata& BlitData) const if(BlitData.CustomData & ALLOW_ANIMATE && TrueAF != 1) PictureIndex += GET_TICK() & (TrueAF - 1); - GraphicData.Picture[PictureIndex]->LuminanceMaskedBlit(BlitData); + igraph::Blit3(GraphicData.Picture[PictureIndex], BlitData, flags); } else { cint AF = GraphicData.AnimationFrames; cint F = !(BlitData.CustomData & ALLOW_ANIMATE) || AF == 1 ? 0 : GET_TICK() & (AF - 1); - GraphicData.Picture[F]->LuminanceBlit(BlitData); + igraph::Blit3(GraphicData.Picture[F], BlitData, flags); } } @@ -455,19 +459,20 @@ void olterrain::Draw(blitdata& BlitData) const { if(UseBorderTiles()) { + if((BlitData.CustomData & DO_BLIT3) && ((BlitData.CustomData & SQUARE_INDEX_MASK) != 0)) return; cint TrueAF = GraphicData.AnimationFrames / 9; int PictureIndex = (BlitData.CustomData & SQUARE_INDEX_MASK) * TrueAF; if(BlitData.CustomData & ALLOW_ANIMATE && TrueAF != 1) PictureIndex += GET_TICK() & (TrueAF - 1); - GraphicData.Picture[PictureIndex]->AlphaLuminanceBlit(BlitData); + igraph::Blit3(GraphicData.Picture[PictureIndex], BlitData, MF_BLIT_ALPHA_LUMINANCE ^ GetSpatialFlags()); } else { cint AF = GraphicData.AnimationFrames; cint F = !(BlitData.CustomData & ALLOW_ANIMATE) || AF == 1 ? 0 : GET_TICK() & (AF - 1); - GraphicData.Picture[F]->AlphaLuminanceBlit(BlitData); + igraph::Blit3(GraphicData.Picture[F], BlitData, MF_BLIT_ALPHA_LUMINANCE ^ GetSpatialFlags()); } } diff --git a/Main/Source/lterras.cpp b/Main/Source/lterras.cpp index a8ca60f91..0ab1cc093 100644 --- a/Main/Source/lterras.cpp +++ b/Main/Source/lterras.cpp @@ -115,7 +115,8 @@ void altar::Draw(blitdata& BlitData) const { olterrain::Draw(BlitData); BlitData.Src.X = GetConfig() << 4; - igraph::GetSymbolGraphic()->LuminanceMaskedBlit(BlitData); + bitmap *b = (bitmap*) igraph::GetSymbolGraphic(); + igraph::Blit3(b, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_TABLE); BlitData.Src.X = BlitData.Src.Y = 0; } diff --git a/Main/Source/rain.cpp b/Main/Source/rain.cpp index 9dbb50ddc..596df38d9 100644 --- a/Main/Source/rain.cpp +++ b/Main/Source/rain.cpp @@ -92,7 +92,10 @@ void rain::Draw(blitdata& BlitData) const continue; } - BlitData.Bitmap->AlphaPutPixel(DropPos + BlitData.Dest, Color, BlitData.Luminance, 255); + if(BlitData.CustomData & DO_BLIT3) + igraph::fDrawRainPixel(DropPos, Color); + else + BlitData.Bitmap->AlphaPutPixel(DropPos + BlitData.Dest, Color, BlitData.Luminance, 255); } this->Drops = Drops; diff --git a/Main/Source/smoke.cpp b/Main/Source/smoke.cpp index ca56419c1..8d7f61627 100644 --- a/Main/Source/smoke.cpp +++ b/Main/Source/smoke.cpp @@ -98,7 +98,7 @@ void smoke::Be() void smoke::Draw(blitdata& BlitData) const { - Picture[(GET_TICK() >> 1) & 3]->AlphaLuminanceBlit(BlitData); + igraph::Blit3(Picture[(GET_TICK() >> 1) & 3], BlitData, MF_BLIT_ALPHA_LUMINANCE | MF_OBJECT); } void smoke::Save(outputfile& SaveFile) const diff --git a/Main/Source/stack.cpp b/Main/Source/stack.cpp index 9e1657fd8..d37ce5a82 100644 --- a/Main/Source/stack.cpp +++ b/Main/Source/stack.cpp @@ -55,14 +55,15 @@ void stack::Draw(ccharacter* Viewer, blitdata& BlitData, col24 L = BlitData.Luminance; BlitData.Luminance = ivanconfig::GetContrastLuminance(); BlitData.Src.Y = 16; + const bitmap *b = (bitmap*) igraph::GetSymbolGraphic(); if(PlusSymbol) - igraph::GetSymbolGraphic()->LuminanceMaskedBlit(BlitData); + igraph::Blit3(b, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_OBJECT); if(Dangerous) { BlitData.Src.X = 160; - igraph::GetSymbolGraphic()->LuminanceMaskedBlit(BlitData); + igraph::Blit3(b, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_OBJECT); } BlitData.Src.X = BlitData.Src.Y = 0; /// check diff --git a/Main/Source/traps.cpp b/Main/Source/traps.cpp index 4f21e195a..fa98abf35 100644 --- a/Main/Source/traps.cpp +++ b/Main/Source/traps.cpp @@ -187,7 +187,7 @@ void web::AddTrapName(festring& String, int) const void web::Draw(blitdata& BlitData) const { - Picture->LuminanceMaskedBlit(BlitData); + igraph::Blit3(Picture, BlitData, MF_BLIT_LUMINANCE_MASKED | MF_WALL | MF_OBJECT); } truth web::IsStuckToBodyPart(int I) const diff --git a/Script/define.dat b/Script/define.dat index 0d0bcb87f..6c98f4b36 100644 --- a/Script/define.dat +++ b/Script/define.dat @@ -1387,6 +1387,18 @@ #define FORCE_THE 8 #define SHOW_MATERIAL 16 +/* Spatial Flags */ +#define MF_OBJECT 256 +#define MF_FLOOR 512 +#define MF_CEIL 1024 +#define MF_WALL 2048 +#define MF_ONFLOOR 4096 +#define MF_LOWWALL 8192 +#define MF_TABLE 16384 +#define MF_WINDOW 128 +#define MF_LARGE 64 +#define MF_STAIR 32 + /***************************/ /* Material DataBase flags */ /***************************/ diff --git a/Script/glterra.dat b/Script/glterra.dat index 92e99034e..b8b16a5a7 100644 --- a/Script/glterra.dat +++ b/Script/glterra.dat @@ -38,6 +38,7 @@ glterrain /* Obligatory if multiple material configurations defined: MaterialConfigChances */ IsAbstract = true; /* This is false by default and does not inherit! */ OKVisualEffects = NONE; + SpatialFlags = MF_FLOOR | MF_CEIL; MaterialColorB = 0; MaterialColorC = 0; MaterialColorD = 0; @@ -134,6 +135,7 @@ liquidterrain /* glterrain-> */ { NameSingular = "pool"; SitMessage = "You sit on the pool surface. Oddly enough, you sink. You feel stupid."; + SpatialFlags = MF_FLOOR; } Config UNDERGROUND_LAKE; @@ -144,6 +146,7 @@ liquidterrain /* glterrain-> */ SitMessage = "You sit on the lake surface. Oddly enough, you sink. You feel stupid."; UseBorderTiles = true; BorderTilePriority = 10; + SpatialFlags = MF_FLOOR; } Config SEA; @@ -152,5 +155,6 @@ liquidterrain /* glterrain-> */ SitMessage = "You sit on the sea waves. Oddly enough, you sink. You feel stupid."; UseBorderTiles = true; BorderTilePriority = 10; + SpatialFlags = MF_FLOOR; } } diff --git a/Script/olterra.dat b/Script/olterra.dat index 20b1b4e70..05ae8b7ee 100644 --- a/Script/olterra.dat +++ b/Script/olterra.dat @@ -38,6 +38,7 @@ olterrain /* Obligatory if multiple material configurations defined: MaterialConfigChances */ IsAbstract = true; /* This is false by default and does not inherit! */ OKVisualEffects = NONE; + SpatialFlags = MF_OBJECT; MaterialColorB = 0; MaterialColorC = 0; MaterialColorD = 0; @@ -79,6 +80,7 @@ wall ShowThingsUnder = false; LeftOverItems == NaturalMaterialForm { MainMaterial = 0 { Volume = 500:1500; } Times = 1:4; } IsWall = true; + SpatialFlags = MF_WALL; Config BRICK_FINE; { @@ -244,6 +246,7 @@ decoration MainMaterialConfig == FABRIC; NameSingular = "carpet"; BitmapPos = 0, 272; + SpatialFlags = MF_FLOOR; } Config COUCH; @@ -377,6 +380,7 @@ decoration MainMaterialConfig == MARBLE; NameSingular = ""; BitmapPos = 32, 320; + SpatialFlags = MF_FLOOR | MF_CEIL; } Config POOL_CORNER; @@ -385,6 +389,7 @@ decoration MainMaterialConfig == MARBLE; NameSingular = ""; BitmapPos = 48, 320; + SpatialFlags = MF_FLOOR | MF_CEIL; } Config SNOW_PINE; @@ -726,6 +731,7 @@ door /* olterrain-> */ CreateLockConfigurations = true; LeftOverItems == NaturalMaterialForm { MainMaterial = 0 { Volume = 250:750; } Times = 1:3; } IsAlwaysTransparent = false; + SpatialFlags = MF_WALL; Config BARDOOR; { @@ -759,6 +765,7 @@ stairs /* olterrain-> */ Config STAIRS_UP; { + SpatialFlags = MF_CEIL | MF_STAIR; PostFix = "upwards"; BitmapPos = 0, 192; IsUpLink = true; @@ -769,6 +776,7 @@ stairs /* olterrain-> */ PostFix = "downwards"; BitmapPos = 0, 208; IsDownLink = true; + SpatialFlags = MF_FLOOR | MF_STAIR; } Config SUMO_ARENA_ENTRY; @@ -776,6 +784,7 @@ stairs /* olterrain-> */ PostFix = "downwards"; BitmapPos = 0, 208; IsDownLink = true; + SpatialFlags = MF_FLOOR | MF_STAIR; } Config SUMO_ARENA_EXIT; @@ -783,6 +792,7 @@ stairs /* olterrain-> */ PostFix = "upwards"; BitmapPos = 0, 192; IsUpLink = true; + SpatialFlags = MF_CEIL | MF_STAIR; } } @@ -802,6 +812,8 @@ portal /* stairs -> */ Config DARK_LEVEL; { } IsDownLink = true; + SpatialFlags = MF_OBJECT; /* to check */ + Config XINROCH_TOMB_ENTRANCE; { MaterialColorB = rgb16(0, 200, 0); @@ -822,6 +834,7 @@ altar /* olterrain-> */ BitmapPos = 0, 368; /* PostFix depends on Config */ CreateDivineConfigurations = true; + SpatialFlags = MF_LOWWALL | MF_TABLE; IsAbstract = true; } @@ -852,6 +865,7 @@ olterraincontainer /* olterrain->decoration-> */ HPModifier = 20; AttachedGod = SOPHOS; LeftOverItems == NaturalMaterialForm { MainMaterial = 0 { Volume = 250:750; } Times = 1:2; } + SpatialFlags = MF_WALL; } Config CHEST_OF_DRAWERS; @@ -866,6 +880,7 @@ olterraincontainer /* olterrain->decoration-> */ HPModifier = 40; AttachedGod = SOPHOS; LeftOverItems == NaturalMaterialForm { MainMaterial = 0 { Volume = 500:1000; } Times = 1:2; } + SpatialFlags = MF_ONFLOOR; } Config SHELF; @@ -880,6 +895,7 @@ olterraincontainer /* olterrain->decoration-> */ AttachedGod = ATAVUS; LeftOverItems == NaturalMaterialForm { MainMaterial = 0 { Volume = 250:750; } Times = 1:2; } MaterialColorB = rgb16(200,200,200); + SpatialFlags = MF_WALL; } } @@ -934,6 +950,7 @@ boulder /* olterrain-> */ IsAbstract = true; HPModifier = 50; LeftOverItems == NaturalMaterialForm { MainMaterial = 0 { Volume = 500:1500; } Times = 1:3; } + SpatialFlags = MF_ONFLOOR; Config 1; { @@ -995,6 +1012,7 @@ earth ShowThingsUnder = false; LeftOverItems == NaturalMaterialForm { MainMaterial = 0 { Volume = 500:1500; } Times = 1:3; } IsWall = true; + SpatialFlags = MF_WALL; } monsterportal