Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into refactor-wzstring…
Browse files Browse the repository at this point in the history
…-format
  • Loading branch information
Monsterovich committed Jul 28, 2024
2 parents bd3d498 + 5cde21c commit fb9819a
Show file tree
Hide file tree
Showing 21 changed files with 324 additions and 103 deletions.
2 changes: 1 addition & 1 deletion data/base/script/campaign/cam2-1x.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function setupCyborgGroups()

function setCrashedTeamExp()
{
const DROID_EXP = 32;
const DROID_EXP = camGetRankThreshold("professional");
const droids = enumDroid(MIS_TRANSPORT_TEAM_PLAYER).filter((dr) => (
!camIsSystemDroid(dr) && !camIsTransporter(dr)
));
Expand Down
17 changes: 3 additions & 14 deletions data/base/script/campaign/cam2-a.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function cam2Setup()
//Get some higher rank droids.
function setUnitRank(transport)
{
const droidExp = [128, 64, 32, 16];
const ranks = ["elite", "veteran", "professional", "regular"];
let droids;
let mapRun = false;

Expand All @@ -322,19 +322,8 @@ function setUnitRank(transport)
const droid = droids[i];
if (droid.droidType !== DROID_CONSTRUCT && droid.droidType !== DROID_REPAIR)
{
let mod = 1;
if (droid.droidType === DROID_COMMAND || droid.droidType === DROID_SENSOR)
{
if (camClassicMode())
{
mod = 4;
}
else
{
mod = 8;
}
}
setDroidExperience(droid, mod * droidExp[mapRun ? 0 : (transporterIndex - 1)]);
const USE_COMMAND_RANK = (droid.droidType === DROID_COMMAND || droid.droidType === DROID_SENSOR);
setDroidExperience(droid, camGetRankThreshold(ranks[mapRun ? 0 : (transporterIndex - 1)], USE_COMMAND_RANK));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion data/base/script/campaign/cam3-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ camAreaEvent("phantomFacTrigger", function(droid)

function setAlphaExp()
{
const DROID_EXP = 2048; //Hero rank.
const DROID_EXP = camGetRankThreshold("hero", true); //Hero Commander rank.
const alphaDroids = enumArea("alphaPit", MIS_ALPHA_PLAYER, false).filter((obj) => (
obj.type === DROID
));
Expand Down
7 changes: 6 additions & 1 deletion data/base/script/campaign/cam3-a.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ camAreaEvent ("middleTrigger", function(droid)

function setUnitRank(transport)
{
const droidExp = [2048, 256, 128, 64]; //Can make Hero Commanders if recycled.
const droidExp = [
camGetRankThreshold("hero", true), //Can make Hero Commanders if recycled.
camGetRankThreshold("special"),
camGetRankThreshold("elite"),
camGetRankThreshold("veteran")
];
const droids = enumCargo(transport);

for (let i = 0, len = droids.length; i < len; ++i)
Expand Down
111 changes: 87 additions & 24 deletions data/base/script/campaign/libcampaign_includes/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,57 @@ function camDiscoverCampaign()
return __CAM_UNKNOWN_CAMPAIGN_NUMBER;
}

function camSetExpLevel(number)
//;; ## camGetRankThreshold(rank [, command [, player]])
//;;
//;; Returns the rank threshold for a given rank.
//;;
//;; @param {String|Number} rank
//;; @param {Boolean} command
//;; @param {Number} player
//;; @returns {number}
//;;
function camGetRankThreshold(rankName, command, player)
{
__camExpLevel = number;
if (!camDef(command))
{
command = false;
}
if (!camDef(player))
{
player = CAM_HUMAN_PLAYER;
}
const __BRAIN_TYPE = (command) ? "Command Turret" : "Z NULL BRAIN";
let rank = 0;
if (typeof rankName === "string")
{
rank = __camRankStringToNumber(rankName);
}
return Upgrades[player]["Brain"][__BRAIN_TYPE]["RankThresholds"][rank];
}

//;; ## camSetExpLevel(rank)
//;;
//;; Sets what rank will be used for the AI when it creates units. Can be a rank threshold
//;; index or the name of the rank.
//;;
//;; @param {Number|String} rank
//;; @returns {void}
//;;
function camSetExpLevel(rank)
{
if (!camDef(rank))
{
rank = 0;
}
__camExpLevel = (typeof rank === "string") ? __camRankStringToNumber(rank) : rank;
}

//;; ## camSetOnMapEnemyUnitExp()
//;;
//;; Sets all non-player units to the chosen rank set through camSetExpLevel().
//;;
//;; @returns {void}
//;;
function camSetOnMapEnemyUnitExp()
{
enumDroid(CAM_NEW_PARADIGM)
Expand Down Expand Up @@ -681,35 +727,52 @@ function __camAiPowerReset()
}
}

function __camRankStringToNumber(rankName)
{
if (!camDef(rankName))
{
camDebug("Undefined parameter");
return 0;
}
if (typeof rankName !== "string")
{
camDebug("Please specify rank as a string");
return 0;
}
let rank = 0;
switch (rankName.toLowerCase())
{
case "rookie": rank = 0; break;
case "green": rank = 1; break;
case "trained": rank = 2; break;
case "regular": rank = 3; break;
case "professional": rank = 4; break;
case "veteran": rank = 5; break;
case "elite": rank = 6; break;
case "special": rank = 7; break;
case "hero": rank = 8; break;
default: camDebug("Unknown rank encountered");
}
return rank;
}

function __camGetExpRangeLevel(useCommanderRanks)
{
if (!camDef(useCommanderRanks))
{
useCommanderRanks = false;
}
const unitRanks = {
rookie: 0,
green: 4,
trained: 8,
regular: 16,
professional: 32,
veteran: 64,
elite: 128,
special: 256,
hero: 512,
};
const commandRanks = {
rookie: 0,
green: (camClassicMode()) ? 8 : 16,
trained: (camClassicMode()) ? 16 : 48,
regular: (camClassicMode()) ? 32 : 128,
professional: (camClassicMode()) ? 64 : 256,
veteran: (camClassicMode()) ? 128 : 512,
elite: (camClassicMode()) ? 512 : 1024,
special: (camClassicMode()) ? 1024 : 1536,
hero: 2048,
const ranks = {
rookie: camGetRankThreshold("rookie", useCommanderRanks),
green: camGetRankThreshold("green", useCommanderRanks),
trained: camGetRankThreshold("trained", useCommanderRanks),
regular: camGetRankThreshold("regular", useCommanderRanks),
professional: camGetRankThreshold("professional", useCommanderRanks),
veteran: camGetRankThreshold("veteran", useCommanderRanks),
elite: camGetRankThreshold("elite", useCommanderRanks),
special: camGetRankThreshold("special", useCommanderRanks),
hero: camGetRankThreshold("hero", useCommanderRanks)
};
const ranks = (useCommanderRanks) ? commandRanks : unitRanks;
let exp = [];

switch (__camExpLevel)
Expand Down
5 changes: 4 additions & 1 deletion data/base/shaders/nolight_instanced.frag
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ void main()
}

// Return fragment color
fragColour = mix(fragColour, vec4(fogColor.xyz, fragColour.w), clamp(fogFactor, 0.0, 1.0));
vec3 fogPremultAlphaFactor = mix(vec3(fragColour.a), vec3(1.f,1.f,1.f), vec3(float(alphaTest)));
float fogFactorAdjust = mix(1.f, 0.f, float(alphaTest));
fragColour = vec4(mix(fragColour.rgb, fogColor.rgb * fogPremultAlphaFactor, clamp(fogFactor * fogFactorAdjust, 0.0, 1.0)), fragColour.a);
fragColour.a = fragColour.a * (1.0 - clamp(fogFactor, 0.0, 1.0));
}

#ifdef NEWGL
Expand Down
5 changes: 4 additions & 1 deletion data/base/shaders/vk/nolight_instanced.frag
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ void main()
}

// Return fragment color
fragColour = mix(fragColour, vec4(fogColor.xyz, fragColour.w), clamp(fogFactor, 0.0, 1.0));
vec3 fogPremultAlphaFactor = mix(vec3(fragColour.a), vec3(1.f,1.f,1.f), vec3(float(alphaTest)));
float fogFactorAdjust = mix(1.f, 0.f, float(alphaTest));
fragColour = vec4(mix(fragColour.rgb, fogColor.rgb * fogPremultAlphaFactor, clamp(fogFactor * fogFactorAdjust, 0.0, 1.0)), fragColour.a);
fragColour.a = fragColour.a * (1.0 - clamp(fogFactor, 0.0, 1.0));
}

FragColor = fragColour;
Expand Down
2 changes: 1 addition & 1 deletion data/base/stats/brain.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"maxDroidsMult": 2,
"name": "Command Turret",
"ranks": [ "Rookie", "Green", "Trained", "Regular", "Professional", "Veteran", "Elite", "Special", "Hero" ],
"thresholds": [ 0, 16, 48, 128, 256, 512, 1024, 1536, 2048 ],
"thresholds": [ 0, 24, 48, 96, 192, 384, 768, 1536, 2048 ],
"turret": "CommandTurret1"
},
"ZNULLBRAIN": {
Expand Down
2 changes: 2 additions & 0 deletions lib/ivis_opengl/gfx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ namespace gfx_api
using Draw3DShapeNoLightAlphaNoDepthWRT_Instanced = Draw3DShapeInstanced<REND_ALPHA, SHADER_NOLIGHT_INSTANCED, DEPTH_CMP_LEQ_WRT_OFF>;
using Draw3DShapeAdditiveNoDepthWRT_Instanced = Draw3DShapeInstanced<REND_ADDITIVE, SHADER_COMPONENT_INSTANCED, DEPTH_CMP_LEQ_WRT_OFF>;
using Draw3DShapeNoLightAdditiveNoDepthWRT_Instanced = Draw3DShapeInstanced<REND_ADDITIVE, SHADER_NOLIGHT_INSTANCED, DEPTH_CMP_LEQ_WRT_OFF>;
using Draw3DShapePremulNoDepthWRT_Instanced = Draw3DShapeInstanced<REND_PREMULTIPLIED, SHADER_COMPONENT_INSTANCED, DEPTH_CMP_LEQ_WRT_OFF>;
using Draw3DShapeNoLightPremulNoDepthWRT_Instanced = Draw3DShapeInstanced<REND_PREMULTIPLIED, SHADER_NOLIGHT_INSTANCED, DEPTH_CMP_LEQ_WRT_OFF>;

struct Draw3DShapeInstancedDepthOnlyGlobalUniforms
{
Expand Down
29 changes: 25 additions & 4 deletions lib/ivis_opengl/piedraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ static void draw3dShapeTemplated(const templatedState &lastState, ShaderOnce& gl
}
}

PIELIGHT straightAlphaToPremultiplied(PIELIGHT colour)
{
colour.byte.r = static_cast<uint8_t>((static_cast<uint16_t>(colour.byte.r) * static_cast<uint16_t>(colour.byte.a)) / 255);
colour.byte.g = static_cast<uint8_t>((static_cast<uint16_t>(colour.byte.g) * static_cast<uint16_t>(colour.byte.a)) / 255);
colour.byte.b = static_cast<uint8_t>((static_cast<uint16_t>(colour.byte.b) * static_cast<uint16_t>(colour.byte.a)) / 255);
return colour;
}

static inline gfx_api::Draw3DShapePerInstanceInterleavedData GenerateInstanceData(int frame, PIELIGHT colour, PIELIGHT teamcolour, int pieFlag, int pieFlagData, glm::mat4 const &modelMatrix, float stretchDepth)
{
int ecmState = (pieFlag & pie_ECM) ? 1 : 0;
Expand All @@ -536,6 +544,12 @@ static inline gfx_api::Draw3DShapePerInstanceInterleavedData GenerateInstanceDat
colour.byte.a = (UBYTE)pieFlagData;
}

if (pieFlag & pie_PREMULTIPLIED)
{
colour = straightAlphaToPremultiplied(colour);
teamcolour = straightAlphaToPremultiplied(teamcolour);
}

return gfx_api::Draw3DShapePerInstanceInterleavedData {
modelMatrix,
glm::vec4(stretchDepth, ecmState, !(pieFlag & pie_PREMULTIPLIED), float(frame)),
Expand Down Expand Up @@ -1508,7 +1522,7 @@ static void drawInstanced3dShapeDepthOnly(ShaderOnce& globalsOnce, const gfx_api
// Draw3DInstancedPSO::get().unbind_vertex_buffers(shape->buffers[VBO_VERTEX], shape->buffers[VBO_NORMAL], shape->buffers[VBO_TEXCOORD]);
}

template<SHADER_MODE shader, typename AdditivePSO, typename AdditiveNoDepthWRTPSO, typename AlphaPSO, typename AlphaNoDepthWRTPSO, typename PremultipliedPSO, typename OpaquePSO>
template<SHADER_MODE shader, typename AdditivePSO, typename AdditiveNoDepthWRTPSO, typename AlphaPSO, typename AlphaNoDepthWRTPSO, typename PremultipliedPSO, typename PremultipliedNoDepthWRTPSO, typename OpaquePSO>
static void drawInstanced3dShapeTemplated(ShaderOnce& globalsOnce, const gfx_api::Draw3DShapeInstancedGlobalUniforms& globalUniforms, const iIMDShape * shape, int pieFlag, gfx_api::buffer* instanceDataBuffer, size_t instanceBufferOffset, size_t instance_count, gfx_api::texture* lightmapTexture)
{
/* Set tranlucency */
Expand Down Expand Up @@ -1536,7 +1550,14 @@ static void drawInstanced3dShapeTemplated(ShaderOnce& globalsOnce, const gfx_api
}
else if (pieFlag & pie_PREMULTIPLIED)
{
return drawInstanced3dShapeTemplated_Inner<shader, PremultipliedPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
if (!(pieFlag & pie_NODEPTHWRITE))
{
return drawInstanced3dShapeTemplated_Inner<shader, PremultipliedPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
}
else
{
return drawInstanced3dShapeTemplated_Inner<shader, PremultipliedNoDepthWRTPSO>(globalsOnce, globalUniforms, shape, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
}
}
else
{
Expand Down Expand Up @@ -1592,11 +1613,11 @@ static void pie_Draw3DShape2_Instanced(ShaderOnce& globalsOnce, const gfx_api::D
}
else if (light)
{
drawInstanced3dShapeTemplated<SHADER_COMPONENT_INSTANCED, gfx_api::Draw3DShapeAdditive_Instanced, gfx_api::Draw3DShapeAdditiveNoDepthWRT_Instanced, gfx_api::Draw3DShapeAlpha_Instanced, gfx_api::Draw3DShapeAlphaNoDepthWRT_Instanced, gfx_api::Draw3DShapePremul_Instanced, gfx_api::Draw3DShapeOpaque_Instanced>(globalsOnce, globalUniforms, shape, pieFlag, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
drawInstanced3dShapeTemplated<SHADER_COMPONENT_INSTANCED, gfx_api::Draw3DShapeAdditive_Instanced, gfx_api::Draw3DShapeAdditiveNoDepthWRT_Instanced, gfx_api::Draw3DShapeAlpha_Instanced, gfx_api::Draw3DShapeAlphaNoDepthWRT_Instanced, gfx_api::Draw3DShapePremul_Instanced, gfx_api::Draw3DShapePremulNoDepthWRT_Instanced, gfx_api::Draw3DShapeOpaque_Instanced>(globalsOnce, globalUniforms, shape, pieFlag, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
}
else
{
drawInstanced3dShapeTemplated<SHADER_NOLIGHT_INSTANCED, gfx_api::Draw3DShapeNoLightAdditive_Instanced, gfx_api::Draw3DShapeNoLightAdditiveNoDepthWRT_Instanced, gfx_api::Draw3DShapeNoLightAlpha_Instanced, gfx_api::Draw3DShapeNoLightAlphaNoDepthWRT_Instanced, gfx_api::Draw3DShapeNoLightPremul_Instanced, gfx_api::Draw3DShapeNoLightOpaque_Instanced>(globalsOnce, globalUniforms, shape, pieFlag, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
drawInstanced3dShapeTemplated<SHADER_NOLIGHT_INSTANCED, gfx_api::Draw3DShapeNoLightAdditive_Instanced, gfx_api::Draw3DShapeNoLightAdditiveNoDepthWRT_Instanced, gfx_api::Draw3DShapeNoLightAlpha_Instanced, gfx_api::Draw3DShapeNoLightAlphaNoDepthWRT_Instanced, gfx_api::Draw3DShapeNoLightPremul_Instanced, gfx_api::Draw3DShapeNoLightPremulNoDepthWRT_Instanced, gfx_api::Draw3DShapeNoLightOpaque_Instanced>(globalsOnce, globalUniforms, shape, pieFlag, instanceDataBuffer, instanceBufferOffset, instance_count, lightmapTexture);
}

polyCount += shape->polys.size();
Expand Down
3 changes: 2 additions & 1 deletion src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@ void droidUpdate(DROID *psDroid)
if (psDroid->repairGroup != UBYTE_MAX &&
psDroid->order.type != DORDER_RTR &&
psDroid->order.type != DORDER_RTR_SPECIFIED &&
psDroid->order.type != DORDER_RTB)
psDroid->order.type != DORDER_RTB &&
secondaryGetState(psDroid, DSO_REPAIR_LEVEL) == DSS_REPLEV_NEVER)
{
droidWasFullyRepairedBase(psDroid);
}
Expand Down
2 changes: 1 addition & 1 deletion src/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ static void renderExplosionEffect(const EFFECT *psEffect, const glm::mat4 &viewM

if (premultiplied)
{
pie_Draw3DShape(psEffect->imd, psEffect->frameNumber, 0, brightness, pie_PREMULTIPLIED, 0, modelMatrix, viewMatrix);
pie_Draw3DShape(psEffect->imd, psEffect->frameNumber, 0, brightness, pie_PREMULTIPLIED | pie_NODEPTHWRITE, 0, modelMatrix, viewMatrix);
}
else if (psEffect->type == EXPLOSION_TYPE_PLASMA)
{
Expand Down
Loading

0 comments on commit fb9819a

Please sign in to comment.