Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/trust' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Nov 8, 2020
2 parents 77e4fad + b40d150 commit ea13551
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ jobs:
fi
Full_Startup_Checks:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
services:
mysql:
image: mariadb:10.1
image: mariadb
env:
MYSQL_DATABASE: tpzdb
MYSQL_ROOT_PASSWORD: root
Expand All @@ -142,7 +142,7 @@ jobs:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y software-properties-common cmake mariadb-server libmariadb-dev-compat libluajit-5.1-dev libzmq3-dev zlib1g-dev libssl-dev luarocks python3.7
sudo apt-get install -y software-properties-common cmake mariadb-server-10.3 mariadb-client-10.3 libmariadb-dev-compat libluajit-5.1-dev libzmq3-dev zlib1g-dev libssl-dev luarocks python3.7
- name: Configure CMake
run: |
cmake .
Expand Down
48 changes: 36 additions & 12 deletions src/common/tpzrand.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ class tpzrand
mt().seed(seq);
}

/*Generates a random number in the half-open interval [min, max)
@param min
@param max
@returns result
*/
// Generates a random number in the half-open interval [min, max]
// @param min
// @param max
// @returns result
template <typename T>
static inline typename std::enable_if<std::is_integral<T>::value, T>::type
GetRandomNumber(T min, T max)
GetRandomNumber(T min, T max)
{
if (min == max - 1 || max == min)
{
Expand All @@ -37,7 +36,7 @@ class tpzrand

template<typename T>
static inline typename std::enable_if<std::is_floating_point<T>::value, T>::type
GetRandomNumber(T min, T max)
GetRandomNumber(T min, T max)
{
if (min == max)
{
Expand All @@ -47,14 +46,39 @@ class tpzrand
return dist(mt());
}

/*Generates a random number in the half-open interval [0, max)
@param min
@param max
@returns result
*/
// Generates a random number in the half-open interval [0, max)
// @param min
// @param max
// @returns result
template <typename T>
static inline T GetRandomNumber(T max)
{
return GetRandomNumber<T>(0, max);
}

// Gets a random element from the given stl-like container (container must have members: at() and size()).
// @param container
// @returns result
template <typename T> static inline typename T::value_type GetRandomElement(T* container)
{
// NOTE: the specialisation for integral types uses: dist(min, max - 1), so no need to offset container->size()
return container->at(GetRandomNumber<std::size_t>(0U, container->size()));
}

// Gets a random element from the given stl-like container (container must have members: at() and size()).
// @param container
// @returns result
template <typename T> static inline typename T::value_type GetRandomElement(T& container)
{
return GetRandomElement(&container);
}

// Gets a random element from the given initializer_list.
// @param initializer_list
// @returns result
template <typename T> static inline T GetRandomElement(std::initializer_list<T> list)
{
std::vector<T> container(list);
return GetRandomElement(container);
}
};
2 changes: 1 addition & 1 deletion src/map/ai/helpers/gambits_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ bool CGambitsContainer::TryTrustSkill()
{
case G_SELECT::RANDOM:
{
chosen_skill = tp_skills.at(tpzrand::GetRandomNumber<std::size_t>(tp_skills.size()));
chosen_skill = tpzrand::GetRandomElement(tp_skills);
break;
}
case G_SELECT::HIGHEST: // Form the best possible skillchain
Expand Down
1 change: 1 addition & 0 deletions src/map/packet_guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void Init()
allowList[SUBSTATE_IN_CS][0x05A] = true; // Map Update (Conquest, Besieged, Campaign)
allowList[SUBSTATE_IN_CS][0x05B] = true; // Event Update (Completion or Update)
allowList[SUBSTATE_IN_CS][0x05C] = true; // Event Update (Update Player Position)
allowList[SUBSTATE_IN_CS][0x060] = true; // Event Update (String Update)
allowList[SUBSTATE_IN_CS][0x061] = true; // Full Char Update
allowList[SUBSTATE_IN_CS][0x0B5] = true; // Chat Message
allowList[SUBSTATE_IN_CS][0x0B6] = true; // Tell Message
Expand Down

0 comments on commit ea13551

Please sign in to comment.