Skip to content

Commit

Permalink
Change intro otis model to otis, remap body and head keyvalues
Browse files Browse the repository at this point in the history
malortie/custom-hl-viewmodels#21
  • Loading branch information
SamVanheer committed May 25, 2022
1 parent 797c366 commit dc8a54f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using HalfLife.UnifiedSdk.Utilities.Entities;
using HalfLife.UnifiedSdk.Utilities.Games;
using HalfLife.UnifiedSdk.Utilities.Tools.UpgradeTool;

namespace HalfLife.UnifiedSdk.MapUpgrader.Upgrades
{
/// <summary>
/// Converts the <c>monster_otis</c> model and body value to the appropriate keyvalues.
/// </summary>
internal sealed class ConvertOtisModelUpgrade : IMapUpgradeAction
{
private const string OtisModelName = "models/otis.mdl";
private const string IntroOtisModelName = "models/intro_otis.mdl";

private enum OtisSleeves
{
Random = -1,
Long = 0,
Short
}

private enum OtisSkin
{
Random = -1,
HeadWithHair = 0,
Bald,
BlackHeadWithHair
}

public void Apply(MapUpgradeContext context)
{
foreach (var otis in context.Map.Entities.OfClass("monster_otis"))
{
var head = otis.GetInteger("head");

otis.Remove("head");
//Remove this because it will just screw up the submodel state otherwise.
otis.Remove("body");
//Previously unused, but now exist.
otis.Remove("sleeves");
otis.Remove("item");

otis.SetInteger("skin", head);

var sleeves = OtisSleeves.Long;

if (head == (int)OtisSkin.Bald)
{
sleeves = OtisSleeves.Short;
}

otis.SetInteger("sleeves", (int)sleeves);
}

//Only Blue Shift uses Otis models separately from Opposing Force so this section only applies to that game.
if (ValveGames.BlueShift.IsMap(context.Map.BaseName))
{
foreach (var entity in context.Map.Entities.WhereString("model", OtisModelName))
{
var body = entity.GetInteger("body");

//Remap old submodels to new ones. Hardcoded to the body values used in Blue Shift to keep things simple.
body = body switch
{
2 => 15,
_ => 3,
};

entity.SetInteger("body", body);
entity.SetInteger("skin", (int)OtisSkin.Bald);
}

foreach (var entity in context.Map.Entities.WhereString("model", IntroOtisModelName))
{
//Use the main Otis model for these.
entity.SetModel(OtisModelName);

entity.SetInteger("body", 9);
entity.SetInteger("skin", (int)OtisSkin.Bald);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static MapUpgradeBuilder AddSharedUpgrades(this MapUpgradeBuilder builder
//Must come before any other upgrades.
builder.AddAction(new ConvertAngleToAnglesUpgrade());
builder.AddAction(new AdjustShotgunAnglesUpgrade());
builder.AddAction(new ConvertOtisModelUpgrade());
return builder;
}

Expand Down

0 comments on commit dc8a54f

Please sign in to comment.