Skip to content

Commit

Permalink
Begin MvM Upgrade Support
Browse files Browse the repository at this point in the history
  • Loading branch information
caxanga334 committed Apr 2, 2024
1 parent ac48df4 commit 95fcb65
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ CopyFiles('configs', 'addons/sourcemod/configs/navbot',

# TF2 Config files
CopyFiles('configs/tf', 'addons/sourcemod/configs/navbot/tf',
[ 'weapons.cfg', 'class_selection.cfg', 'places.db' ]
[ 'weapons.cfg', 'mvm_upgrades.cfg', 'class_selection.cfg', 'places.db' ]
)

# Copy binaries.
Expand Down
74 changes: 74 additions & 0 deletions configs/tf/mvm_upgrades.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
TFMvMUpgrades
{
/**
* NavBot TF2 MvM Upgrade priority configuration file
*
* Defines which upgrades each class should buy
*
* Look at scripts/items/mvm_upgrades.txt
*
* "scout" -- class section
* {
* "upgrade" -- this must always be named "upgrade"
* {
* "attribute" "damage bonus" -- attribute name, must match an attribute defined in the game's upgrade script file
* "quality" "2" -- can be omitted, 2 is the default quality. Omit this unless it's also specified in the game's upgrade script file
*
* priority, bots will buy upgrades with the lowest priority first.
* in case two or more upgrades have the same priority, they will be selected randomly
* "priority" "1"
* "slot" "0" -- weapon slot used by this upgrade, -1 for player upgrades, 9 for canteen power up bottle
* "weapons" "5,7,333" -- comma-delimited list of item definition index this upgrade is restricted to
* }
* }
*
*/

"scout"
{
// Scout, priorize blast and bullet res + mobility first, then fire res + jump mobility, then health regen

"upgrade"
{
"attribute" "dmg taken from blast reduced"
"priority" "1"
"slot" "-1"
}
"upgrade"
{
"attribute" "dmg taken from bullets reduced"
"priority" "1"
"slot" "-1"
}
"upgrade"
{
"attribute" "dmg taken from crit reduced"
"priority" "1"
"slot" "-1"
}
"upgrade"
{
"attribute" "move speed bonus"
"priority" "1"
"slot" "-1"
}
"upgrade"
{
"attribute" "dmg taken from fire reduced"
"priority" "2"
"slot" "-1"
}
"upgrade"
{
"attribute" "increased jump height"
"priority" "2"
"slot" "-1"
}
"upgrade"
{
"attribute" "health regen"
"priority" "3"
"slot" "-1"
}
}
}
1 change: 1 addition & 0 deletions extension/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ sourceFiles = [
'mods/tf2/tf2lib.cpp',
'mods/tf2/tf2mod_gameevents.cpp',
'mods/tf2/tf2_class_selection.cpp',
'mods/tf2/mvm_upgrade_manager.cpp',
'mods/tf2/nav/tfnavarea.cpp',
'mods/tf2/nav/tfnavmesh.cpp',
'mods/tf2/nav/tfnav_edit.cpp',
Expand Down
114 changes: 114 additions & 0 deletions extension/mods/tf2/mvm_upgrade.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#ifndef NAVBOT_TF2_MVM_UPGRADE_H_
#define NAVBOT_TF2_MVM_UPGRADE_H_
#pragma once

#include <string>
#include <unordered_set>

struct MvMUpgrade_t
{
MvMUpgrade_t()
{
index = 0;
attribute.reserve(64);
increment = 0.0f;
cap = 0.0f;
cost = 0;
quality = 0;
max_purchases = 0;
}

bool operator==(const MvMUpgrade_t& other) const
{
return this->index == other.index;
}

bool operator!=(const MvMUpgrade_t& other) const
{
return this->index != other.index;
}

// Max amount of purchases possible
void FindMaxPurchases()
{
if (increment == 0.0f || (increment == cap))
{
max_purchases = 1;
return;
}

int count = 0;

// increment is positive
if (increment > 0.0f)
{
for (float base = 1.0f; base < cap; base += increment)
{
++count;
}
}
else if (increment < 0.0f) // increment is negative
{
for (float base = 1.0f; base > cap; base += increment)
{
++count;
}
}

max_purchases = count;
}

int index;
std::string attribute;
float increment;
float cap;
int cost;
int quality;
int max_purchases;
};

// Used by the bot to reference an upgrade bought
struct TF2BotUpgrade_t
{
TF2BotUpgrade_t(const MvMUpgrade_t* up)
{
upgrade = up;
times_bought = 0;
}

const bool IsMaxed() const { return times_bought >= upgrade->max_purchases; }

const MvMUpgrade_t* upgrade;
int times_bought;
};

// Upgrade Information
struct TF2BotUpgradeInfo_t
{
TF2BotUpgradeInfo_t()
{
attribute.reserve(64);
quality = 0; // default
priority = 0;
itemslot = 0;
allowedweapons.reserve(4);
}

// if allowedweapons is empty, then any weapon is allowed
const bool AnyWeapon() const { return allowedweapons.empty(); }
const bool IsWeaponAllowed(const int itemindex) const
{
if (AnyWeapon())
return true;

return allowedweapons.find(itemindex) != allowedweapons.end();
}

std::string attribute;
int quality;
int priority;
int itemslot;
std::unordered_set<int> allowedweapons;
};

#endif // !NAVBOT_TF2_MVM_UPGRADE_H_
Loading

0 comments on commit 95fcb65

Please sign in to comment.