raze/source/games/duke/src/game_misc.cpp

531 lines
16 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 1996, 2003 - 3D Realms Entertainment
2020-06-28 07:03:31 +00:00
Copyright (C) 2020 - Christoph Oelckers
This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
Duke Nukem 3D 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.
Original Source: 1996 - Todd Replogle
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
*/
//-------------------------------------------------------------------------
2020-07-05 14:49:00 +00:00
// This file collects several functions from the original game.c
// that do not fit any particular category.
#include "ns.h" // Must come before everything else!
2020-09-06 10:44:58 +00:00
#include "automap.h"
2020-06-21 20:18:12 +00:00
#include "duke3d.h"
#include "m_argv.h"
#include "mapinfo.h"
#include "texturemanager.h"
#include "statusbar.h"
2020-07-03 22:32:09 +00:00
#include "st_start.h"
#include "i_interface.h"
#include "prediction.h"
#include "gamestate.h"
#include "dukeactor.h"
#include "interpolate.h"
#include "razefont.h"
#include "startscreen.h"
BEGIN_DUKE_NS
2020-07-03 19:44:57 +00:00
//---------------------------------------------------------------------------
//
// debug output
//
//---------------------------------------------------------------------------
std::pair<DVector3, DAngle> GameInterface::GetCoordinates()
2020-07-03 19:44:57 +00:00
{
return std::make_pair(ps[screenpeek].pos, ps[screenpeek].angle.ang);
2020-07-03 19:44:57 +00:00
}
GameStats GameInterface::getStats()
{
2022-02-07 10:04:19 +00:00
player_struct* p = &ps[myconnectindex];
2020-07-03 19:44:57 +00:00
return { p->actors_killed, p->max_actors_killed, p->secret_rooms, p->max_secret_rooms, p->player_par / REALGAMETICSPERSEC, p->frag };
}
2020-07-03 22:32:09 +00:00
//---------------------------------------------------------------------------
//
2020-07-24 18:21:51 +00:00
//
2020-07-03 22:32:09 +00:00
//
//---------------------------------------------------------------------------
static void endthegame(bool)
2020-07-03 22:32:09 +00:00
{
endoomName = isRR() ? "redneck.bin" : !isShareware() ? "duke3d.bin" : "dukesw.bin";
ST_Endoom();
}
void GameInterface::ExitFromMenu()
{
#if 0
// do we really need this scoreboard stuff here?
auto runbonus = [=](auto completion)
{
2020-07-03 22:32:09 +00:00
// MP scoreboard
if (playerswhenstarted > 1 && !ud.coop) ShowScoreboard(playerswhenstarted);
else completion(false);
};
2020-07-03 22:32:09 +00:00
auto runtwoscreens = [](auto completion)
{
2020-07-03 22:32:09 +00:00
// shareware and TEN screens
if (isShareware() && !isRR())
StartCutscene("DukeCutscenes.BuildSharewareExit", 0, completion);
else completion(false);
};
2020-07-03 22:32:09 +00:00
runbonus([=](bool aborted) { runtwoscreens(endthegame); });
#else
if (isShareware() && !isRR())
StartCutscene("DukeCutscenes.BuildSharewareExit", 0, endthegame);
else endthegame(false);
#endif
}
2020-06-30 20:53:15 +00:00
//---------------------------------------------------------------------------
//
// This now redirects the messages to the console's notification display
2020-07-03 19:44:57 +00:00
// which has all the features to reasonably do this in Duke style.
2020-06-30 20:53:15 +00:00
//
//---------------------------------------------------------------------------
2022-02-07 10:04:19 +00:00
void FTA(int q, player_struct* p)
2020-06-30 20:53:15 +00:00
{
if (q < 0 || gamestate != GS_LEVEL)
return;
if (p->ftq != q || (PlayClock - p->ftt > TICRATE && q != QUOTE_DEAD))
{
2020-07-30 19:09:11 +00:00
p->ftq = q;
auto qu = quoteMgr.GetQuote(q);
2020-07-07 21:01:34 +00:00
if (p == &ps[screenpeek] && qu[0] != '\0')
{
#if 0
if (q >= 70 && q <= 72)
{
// Todo: redirect this to a centered message (these are "need a key" messages)
}
else
#endif
{
Printf(PRINT_MEDIUM | PRINT_NOTIFY, "%s\n", qu);
}
}
}
p->ftt = PlayClock;
2020-06-30 20:53:15 +00:00
}
//==========================================================================
//
// Draws the background
//
//==========================================================================
void GameInterface::DrawBackground()
{
twod->ClearScreen();
auto tex = tileGetTexture(TILE_MENUSCREEN);
PalEntry color = 0xff808080;
if (!hud_bgstretch)
DrawTexture(twod, tex, 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_Color, color, TAG_DONE);
else
DrawTexture(twod, tex, 0, 0, DTA_VirtualWidth, twod->GetWidth(), DTA_VirtualHeight, twod->GetHeight(), DTA_KeepRatio, true, DTA_Color, color, TAG_DONE);
}
//---------------------------------------------------------------------------
//
// this is from ZDoom
//
//---------------------------------------------------------------------------
void V_AddBlend (float r, float g, float b, float a, float v_blend[4])
{
r = clamp(r/255.f, 0.f, 0.25f);
2020-07-24 18:21:51 +00:00
g = clamp(g/255.f, 0.f, 0.25f);
b = clamp(b/255.f, 0.f, 0.25f);
a = clamp(a/255.f, 0.f, 0.25f);
float a2, a3;
if (a <= 0)
return;
a2 = v_blend[3] + (1-v_blend[3])*a; // new total alpha
a3 = v_blend[3]/a2; // fraction of color from old
v_blend[0] = v_blend[0]*a3 + r*(1-a3);
v_blend[1] = v_blend[1]*a3 + g*(1-a3);
v_blend[2] = v_blend[2]*a3 + b*(1-a3);
v_blend[3] = a2;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void setgamepalette(int palid)
{
2020-07-20 21:21:27 +00:00
if (palid >= MAXBASEPALS || palid < 0) palid = 0;
auto& fstint = lookups.tables[MAXPALOOKUPS - 1];
if (palid == WATERPAL) fstint.tintColor = PalEntry(224, 192, 255);
else if (palid == SLIMEPAL) fstint.tintColor = PalEntry(208, 255, 192);
else fstint.tintColor = 0xffffff;
2020-07-20 21:21:27 +00:00
videoSetPalette(palid);
}
//---------------------------------------------------------------------------
//
// draws the weapon sprite and other 2D content that's part of the scene.
//
//---------------------------------------------------------------------------
void drawweapon(double smoothratio)
{
auto pp = &ps[screenpeek];
if (!isRR() && pp->newOwner != nullptr)
cameratext(pp->newOwner);
else
{
fi.displayweapon(screenpeek, smoothratio);
if (pp->over_shoulder_on == 0)
fi.displaymasks(screenpeek, pp->GetActor()->spr.pal == 1 || !pp->insector() ? 1 : pp->cursector->floorpal, smoothratio);
}
}
//---------------------------------------------------------------------------
//
// draws everything not part of the 3D scene and its weapon sprite.
//
//---------------------------------------------------------------------------
void drawoverlays(double smoothratio)
{
2022-02-07 10:04:19 +00:00
player_struct* pp;
int cposx, cposy;
DAngle cang;
pp = &ps[screenpeek];
// set palette here, in case the 3D view is off.
setgamepalette(setpal(pp));
float blend[4] = {};
// this does pain tinting etc from the CON
V_AddBlend(pp->pals.r, pp->pals.g, pp->pals.b, pp->pals.a, blend);
// loogies courtesy of being snotted on
if (pp->loogcnt > 0 && !isRR())
{
2021-05-12 15:57:36 +00:00
V_AddBlend(0, 63, 0, float(pp->loogcnt >> 1), blend);
}
if (blend[3])
{
// result must be multiplied by 4 and normalised to 255. (4*255 = 1020)
2020-08-07 20:00:43 +00:00
auto comp = [&](int i, int maxv=255) { return clamp(int(blend[i] * 1020), 0, maxv); };
videoFadePalette(comp(0), comp(1), comp(2), comp(3, 192)); // Never fully saturate the alpha channel
}
else
videoclearFade();
2021-12-02 00:05:07 +00:00
MarkSectorSeen(pp->cursector);
2020-11-02 22:53:55 +00:00
if (ud.cameraactor == nullptr)
{
if (automapMode != am_off)
{
DoInterpolations(smoothratio / 65536.);
2020-11-02 23:20:51 +00:00
if (pp->newOwner == nullptr && playrunning())
{
if (screenpeek == myconnectindex && numplayers > 1)
{
cposx = interpolatedvalue(omyx, myx, smoothratio);
cposy = interpolatedvalue(omyy, myy, smoothratio);
cang = !SyncInput() ? myang : interpolatedangle(omyang, myang, smoothratio);
}
else
{
cposx = interpolatedvalue(pp->player_int_opos().X, pp->player_int_pos().X, smoothratio);
cposy = interpolatedvalue(pp->player_int_opos().Y, pp->player_int_pos().Y, smoothratio);
cang = !SyncInput() ? pp->angle.ang : interpolatedangle(pp->angle.oang, pp->angle.ang, smoothratio);
}
}
else
{
cposx = pp->player_int_opos().X;
cposy = pp->player_int_opos().Y;
cang = pp->angle.oang;
}
DrawOverheadMap(cposx, cposy, cang, smoothratio);
RestoreInterpolations();
}
}
DrawStatusBar();
2020-11-02 23:20:51 +00:00
if (ps[myconnectindex].newOwner == nullptr && ud.cameraactor == nullptr)
{
DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -pp->angle.look_anghalf(smoothratio), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1);
}
if (paused == 2)
{
double x = 160, y = 100;
double scale = isRR() ? 0.4 : 1.;
const char* text = GStrings("Game Paused");
auto myfont = PickBigFont(text);
x -= myfont->StringWidth(text) * 0.5 * scale;
DrawText(twod, myfont, CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-11-02 23:20:51 +00:00
void cameratext(DDukeActor *cam)
{
auto drawitem = [=](int tile, double x, double y, bool flipx, bool flipy)
{
DrawTexture(twod, tileGetTexture(tile), x, y, DTA_ViewportX, viewport3d.Left(), DTA_ViewportY, viewport3d.Top(), DTA_ViewportWidth, viewport3d.Width(),
DTA_ViewportHeight, viewport3d.Height(), DTA_FlipX, flipx, DTA_FlipY, flipy, DTA_CenterOffsetRel, 2, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
};
2020-11-02 23:20:51 +00:00
if (!cam->temp_data[0])
{
drawitem(TILE_CAMCORNER, 24, 33, false, false);
drawitem(TILE_CAMCORNER + 1, 320 - 26, 33, false, false);
drawitem(TILE_CAMCORNER + 1, 24, 163, true, true);
drawitem(TILE_CAMCORNER + 1, 320 - 26, 163, false, true);
if (PlayClock & 16)
drawitem(TILE_CAMLIGHT, 46, 32, false, false);
}
else
{
for (int x = -64; x < 394; x += 64)
for (int y = 0; y < 200; y += 64)
drawitem(TILE_STATIC, x, y, !!(PlayClock & 8), !!(PlayClock & 16));
}
}
2020-07-06 01:00:52 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int startrts(int lumpNum, int localPlayer)
2020-07-06 01:00:52 +00:00
{
if (SoundEnabled() &&
RTS_IsInitialized() && rtsplaying == 0 && (snd_speech & (localPlayer ? 1 : 4)))
{
auto sid = RTS_GetSoundID(lumpNum - 1);
if (sid != -1)
{
S_PlaySound(sid, CHAN_AUTO, CHANF_UI);
rtsplaying = 7;
return 1;
}
}
return 0;
}
ReservedSpace GameInterface::GetReservedScreenSpace(int viewsize)
{
// todo: factor in the frag bar: tileHeight(TILE_FRAGBAR)
int sbar = tileHeight(TILE_BOTTOMSTATUSBAR);
if (isRR())
{
sbar >>= 1;
}
return { 0, sbar };
}
2020-07-18 09:56:49 +00:00
::GameInterface* CreateInterface()
{
return new GameInterface;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, const double czoom, const DAngle cang, double const smoothratio)
{
DVector2 b1, b2, b3, b4, v1, v2, v3, v4;
DAngle an;
int i, j, xoff, yoff;
int xspan, yspan, sprx, spry;
int tilenum;
int xvect, yvect;
int p;
PalEntry col;
xvect = -cang.Sin() * 16384. * czoom;
yvect = -cang.Cos() * 16384. * czoom;
int xdim = twod->GetWidth() << 11;
int ydim = twod->GetHeight() << 11;
auto xydim = DVector2(twod->GetWidth() * 0.5, twod->GetHeight() * 0.5);
auto cp = DVector2(cposx, cposy) * inttoworld;
//Draw sprites
auto pactor = ps[screenpeek].GetActor();
for (unsigned ii = 0; ii < sector.Size(); ii++)
{
if (!gFullMap || !show2dsector[ii]) continue;
DukeSectIterator it(ii);
while (auto act = it.Next())
{
2021-12-21 19:29:46 +00:00
if (act == pactor || (act->spr.cstat & CSTAT_SPRITE_INVISIBLE) || act->spr.cstat == CSTAT_SPRITE_BLOCK_ALL || act->spr.xrepeat == 0) continue;
col = PalEntry(0, 170, 170);
2021-12-21 19:29:46 +00:00
if (act->spr.cstat & CSTAT_SPRITE_BLOCK) col = PalEntry(170, 0, 170);
sprx = act->int_pos().X;
spry = act->int_pos().Y;
auto sp = DVector2(sprx, spry) * inttoworld;
2021-12-21 19:29:46 +00:00
if ((act->spr.cstat & CSTAT_SPRITE_BLOCK_ALL) != 0) switch (act->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK)
{
case CSTAT_SPRITE_ALIGNMENT_FACING:
an = -cang;
v1 = OutAutomapVector(DVector2(sprx - cposx, spry - cposy) * inttoworld, an.Sin(), an.Cos(), czoom / 1024.);
v2 = OutAutomapVector(act->spr.angle.ToVector() * 8., an.Sin(), an.Cos(), czoom / 1024.);
drawlinergb(v1.X - v2.X + xydim.X, v1.Y - v2.Y + xydim.Y, v1.X + v2.X + xydim.X, v1.Y + v2.Y + xydim.Y, col);
drawlinergb(v1.X - v2.Y + xydim.X, v1.Y + v2.X + xydim.Y, v1.X + v2.X + xydim.X, v1.Y + v2.Y + xydim.Y, col);
drawlinergb(v1.X + v2.Y + xydim.X, v1.Y - v2.X + xydim.Y, v1.X + v2.X + xydim.X, v1.Y + v2.Y + xydim.Y, col);
break;
case CSTAT_SPRITE_ALIGNMENT_WALL:
2022-01-19 09:48:18 +00:00
if (actorflag(act, SFLAG2_SHOWWALLSPRITEONMAP))
{
2021-12-21 19:29:46 +00:00
tilenum = act->spr.picnum;
xoff = tileLeftOffset(tilenum) + act->spr.xoffset;
if ((act->spr.cstat & CSTAT_SPRITE_XFLIP) > 0) xoff = -xoff;
xspan = tileWidth(tilenum);
an = -cang;
b1 = act->spr.angle.ToVector().Rotated90CW() * act->spr.xrepeat * (1. / 64.);
b2 = sp * inttoworld - b1 * ((xspan * 0.5) + xoff);
b3 = b2 + b1 * xspan;
v1 = OutAutomapVector(b2 - cp, an.Sin(), an.Cos(), czoom / 1024., xydim);
v2 = OutAutomapVector(b3 - cp, an.Sin(), an.Cos(), czoom / 1024., xydim);
drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col);
}
break;
case CSTAT_SPRITE_ALIGNMENT_FLOOR:
case CSTAT_SPRITE_ALIGNMENT_SLOPE:
2021-12-21 19:29:46 +00:00
tilenum = act->spr.picnum;
xoff = tileLeftOffset(tilenum);
yoff = tileTopOffset(tilenum);
2021-12-21 19:29:46 +00:00
if ((act->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLOPE)
{
2021-12-21 19:29:46 +00:00
xoff += act->spr.xoffset;
yoff += act->spr.yoffset;
}
2021-12-21 19:29:46 +00:00
if ((act->spr.cstat & CSTAT_SPRITE_XFLIP) > 0) xoff = -xoff;
if ((act->spr.cstat & CSTAT_SPRITE_YFLIP) > 0) yoff = -yoff;
an = -cang;
auto acos = act->spr.angle.Cos();
auto asin = act->spr.angle.Sin();
xspan = tileWidth(tilenum);
auto xrep = act->spr.xrepeat * (1. / 64.);
yspan = tileHeight(tilenum);
auto yrep = act->spr.yrepeat * (1. / 64.);
auto xscale = DVector2(-asin * xspan * xrep, +acos * xspan * xrep);
auto yscale = DVector2(-acos * yspan * yrep, -asin * yspan * yrep);
auto b0 = DVector2(((xspan * 0.5) + xoff) * xrep, ((yspan * 0.5) + yoff) * yrep);
b1 = sp + (b0 * asin) + (b0.Rotated90CW() * acos);
b2 = b1 + xscale;
b3 = b2 + yscale;
b4 = b1 + yscale;
v1 = OutAutomapVector(-(b1 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim);
v2 = OutAutomapVector(-(b2 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim);
v3 = OutAutomapVector(-(b3 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim);
v4 = OutAutomapVector(-(b4 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim);
drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col);
drawlinergb(v2.X, v2.Y, v3.X, v3.Y, col);
drawlinergb(v3.X, v3.Y, v4.X, v4.Y, col);
drawlinergb(v4.X, v4.Y, v1.X, v1.Y, col);
break;
}
}
}
for (p = connecthead; p >= 0; p = connectpoint2[p])
{
if (p == screenpeek || ud.coop == 1)
{
auto& pp = ps[p];
auto act = pp.GetActor();
i = TILE_APLAYERTOP + (act->spr.xvel > 16 && pp.on_ground ? (PlayClock >> 4) & 3 : 0);
j = clamp(czoom * (act->spr.yrepeat + abs(pp.truefz - pp.pos.Z)), 22000., 131072.);
an = -cang;
auto const vec = OutAutomapVector(DVector2(mx, my) * inttoworld - cp, an.Sin(), an.Cos(), czoom / 1024., xydim);
auto const daang = -((!SyncInput() ? act->spr.angle : act->interpolatedangle(smoothratio / 65536.)) - cang).Normalized360().Degrees();
DrawTexture(twod, tileGetTexture(i), vec.X, vec.Y, DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), act->spr.pal), DTA_CenterOffset, true,
DTA_Rotate, daang, DTA_Color, shadeToLight(act->spr.shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE);
}
}
return true;
}
2020-07-18 09:56:49 +00:00
END_DUKE_NS