Skip to content

Commit

Permalink
Merge pull request #20 from FreeAllegiance/updateScore
Browse files Browse the repository at this point in the history
Update score
  • Loading branch information
BackTrak authored Oct 30, 2017
2 parents ca1f3ef + 0f58a01 commit eeebccf
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 22 deletions.
8 changes: 7 additions & 1 deletion src/FedSrv/CSteamAchievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void CSteamAchievements::AwardRecoverTechAchievement()
}


void CSteamAchievements::AddUserStats(PlayerScoreObject* ppso)
void CSteamAchievements::AddUserStats(PlayerScoreObject* ppso, IshipIGC * pIship)
{
int tempStat;
bool getSucceed;
Expand Down Expand Up @@ -372,6 +372,12 @@ void CSteamAchievements::AddUserStats(PlayerScoreObject* ppso)
SetStat(EStats::PLAYER_LOSS, tempStat + 1);
}

if (pIship->GetRepair() > 0.0)
{
getSucceed = GetStat(EStats::REPAIR_AMOUNT, &tempStat);
if (getSucceed)
SetStat(EStats::REPAIR_AMOUNT, tempStat + floor(pIship->GetRepair()));
}
}

static DWORD WINAPI UpdateLeaderboardThread(LPVOID pThreadParameter)
Expand Down
10 changes: 6 additions & 4 deletions src/FedSrv/CSteamAchievements.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ enum EStats
SUM_SCORE = 5,
PLAYER_RANK = 6,
PLAYER_WINS = 7,
PLAYER_LOSS = 8
PLAYER_LOSS = 8,
REPAIR_AMOUNT = 9

// Don't forget to update g_nMaximumSteamStatCount and m_Stats!
};
const int g_nMaximumSteamAchievementCount = 11; // Always keep this in sync with the number of achievments in EAchievements!
const int g_nMaximumSteamStatCount = 9; // Always keep this in sync with the number of stats in EStats!
const int g_nMaximumSteamStatCount = 10; // Always keep this in sync with the number of stats in EStats!

// BT - STEAM
// 0 1 2 3 4
Expand Down Expand Up @@ -85,7 +86,8 @@ class CSteamAchievements
"SUM_SCORE",
"PLAYER_RANK",
"PLAYER_WINS",
"PLAYER_LOSS"
"PLAYER_LOSS",
"REPAIR_AMOUNT"
};

bool GetAchievement(EAchievements achievement);
Expand Down Expand Up @@ -115,7 +117,7 @@ class CSteamAchievements
void AwardIGCAchievements(AchievementMask am);
void AwardRecoverTechAchievement();

void AddUserStats(PlayerScoreObject* ppso);
void AddUserStats(PlayerScoreObject* ppso, IshipIGC* pIship);
void UpdateLeaderboard(PlayerScoreObject* ppso);

bool SaveStats();
Expand Down
7 changes: 6 additions & 1 deletion src/FedSrv/FedSrv.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -3653,11 +3653,16 @@ void SendShipUpdates(CFSMission * pfsMission)
pfmShipStatus->status = *pssOld = *pss; //Also update the old status
}

//Xynth Add a periodic check for achievements
//Xynth Add a periodic check for achievements and IGC Score triggers

if (ISPLAYER(pship))
{
CSteamAchievements *pSteamAchievements = pfsShip->GetPlayer()->GetSteamAchievements();
PlayerScoreObject * pso = pfsShip->GetPlayerScoreObject();
if ((pship->GetAchievementMask() & c_achmProbeSpot) > 0)
pso->AddProbeSpot();
if ((pship->GetAchievementMask() & c_achmNewRepair) > 0)
pso->SetRepair(int(pship->GetRepair()));

pSteamAchievements->AwardIGCAchievements(pship->GetAchievementMask());
pship->ClearAchievementMask();
Expand Down
41 changes: 39 additions & 2 deletions src/FedSrv/fsmission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2930,11 +2930,11 @@ void CFSMission::RecordPlayerResults(IshipIGC* pship, CFSPlayer *player, SideID

// BT - STEAM
CSteamAchievements *pSteamAchievements = player->GetSteamAchievements();

IshipIGC *pIship = player->GetIGCShip();
pSteamAchievements->AwardBetaParticipation();

pSteamAchievements->UpdateLeaderboard(ppso);
pSteamAchievements->AddUserStats(ppso);
pSteamAchievements->AddUserStats(ppso, pIship);

pSteamAchievements->SaveStats();

Expand Down Expand Up @@ -3070,6 +3070,43 @@ void CFSMission::ProcessGameOver()

m_flGameDuration = g.timeNow - m_misdef.misparms.timeStart;

//Xynth Determine Rank Ratio and load it into PlayerScoreObjects
{
int sideCount = 0;
ObjectID sideID[3];
int rank[3];
for (SideLinkIGC* psl = m_pMission->GetSides()->first(); psl != NULL && sideCount < 3; psl = psl->next())
{
IsideIGC* pside = psl->data();
sideID[sideCount] = pside->GetObjectID();
rank[sideCount] = GetSideRankSum(pside,false);
sideCount++;
}
if (sideCount == 2) //if more than 2 sides, just use the default 1.0 ratio
{
for (int i = 0; i < 2; i++)
{
if (rank[i] == 0) //avoid divide by zero
rank[i] = 1;
}
float ratio1 = float(rank[0]) / rank[1];
float ratio0 = float(rank[1]) / rank[0];
for (pShiplink = pShips->first(); pShiplink; pShiplink = pShiplink->next())
{
CFSShip * pfsShip = (CFSShip *)pShiplink->data()->GetPrivateData();
if (pfsShip->IsPlayer())
{
PlayerScoreObject* ppso = pfsShip->GetPlayerScoreObject();
if (pfsShip->GetSide()->GetObjectID() == sideID[0])
ppso->SetRankRatio(ratio0);
else
ppso->SetRankRatio(ratio1);
}
}
}

}

//Calculate scores for all players and get a running average of time played.
float totalExperience = 0.0f;
float sideExperience[c_cSidesMax] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
Expand Down
28 changes: 16 additions & 12 deletions src/Igc/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2544,21 +2544,25 @@ void PlayerScoreObject::CalculateScore(ImissionIGC* pmission)


m_fScore = float(m_cWarpsSpotted) * pmission->GetFloatConstant(c_fcidPointsWarp) +
float(m_cAsteroidsSpotted) * pmission->GetFloatConstant(c_fcidPointsAsteroid) +
m_cTechsRecovered * pmission->GetFloatConstant(c_fcidPointsTech) +
(m_cMinerKills * kMax) * pmission->GetFloatConstant(c_fcidPointsMiner) / (m_cMinerKills + kMax) +
(m_cBuilderKills * kMax) * pmission->GetFloatConstant(c_fcidPointsBuilder) / (m_cBuilderKills + kMax) +
(m_cLayerKills * kMax) * pmission->GetFloatConstant(c_fcidPointsLayer) / (m_cLayerKills + kMax) +
(m_cCarrierKills * kMax) * pmission->GetFloatConstant(c_fcidPointsCarrier) / (m_cCarrierKills + kMax) +
m_cPlayerKills * pmission->GetFloatConstant(c_fcidPointsPlayer) +
(m_cBaseKills * kMax) * pmission->GetFloatConstant(c_fcidPointsBaseKill) / (m_cBaseKills + kMax) +
(m_cBaseCaptures * kMax) * pmission->GetFloatConstant(c_fcidPointsBaseCapture) / (m_cBaseCaptures + kMax) +
float(m_cRescues) * pmission->GetFloatConstant(c_fcidPointsRescues) +
float(m_cArtifacts) * pmission->GetFloatConstant(c_fcidPointsArtifacts) +
float(m_cFlags) * pmission->GetFloatConstant(c_fcidPointsFlags);
float(m_cAsteroidsSpotted) * pmission->GetFloatConstant(c_fcidPointsAsteroid) +
m_cTechsRecovered * pmission->GetFloatConstant(c_fcidPointsTech) +
(m_cMinerKills * kMax) * pmission->GetFloatConstant(c_fcidPointsMiner) / (m_cMinerKills + kMax) +
(m_cBuilderKills * kMax) * pmission->GetFloatConstant(c_fcidPointsBuilder) / (m_cBuilderKills + kMax) +
(m_cLayerKills * kMax) * pmission->GetFloatConstant(c_fcidPointsLayer) / (m_cLayerKills + kMax) +
(m_cCarrierKills * kMax) * pmission->GetFloatConstant(c_fcidPointsCarrier) / (m_cCarrierKills + kMax) +
m_cPlayerKills * pmission->GetFloatConstant(c_fcidPointsPlayer) +
(m_cBaseKills * kMax) * pmission->GetFloatConstant(c_fcidPointsBaseKill) / (m_cBaseKills + kMax) +
(m_cBaseCaptures * kMax) * pmission->GetFloatConstant(c_fcidPointsBaseCapture) / (m_cBaseCaptures + kMax) +
float(m_cRescues) * pmission->GetFloatConstant(c_fcidPointsRescues) +
float(m_cArtifacts) * pmission->GetFloatConstant(c_fcidPointsArtifacts) +
float(m_cFlags) * pmission->GetFloatConstant(c_fcidPointsFlags) +
float(m_cProbeSpot) * 10 + //pmission->GetFloatConstant(c_fcidPointsProbeSpot) +
float(m_cRepair) * 0.0006; // pmission->GetFloatConstant(c_fcidPointsRepair);

if (m_bWin)
m_fScore *= 2.0f;

m_fScore *= m_rankRatio;
}

float PlayerScoreObject::GetScore(void) const
Expand Down
26 changes: 26 additions & 0 deletions src/Igc/igc.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ const FloatConstantID c_fcidPlayerCost = 36;
const FloatConstantID c_fcidBaseClusterCost = 37;
const FloatConstantID c_fcidClusterDivisor = 38;

//const FloatConstantID c_fcidPointsProbeSpot = 39;
//const FloatConstantID c_fcidPointsRepair = 40;

const FloatConstantID c_fcidMax = 40;


//
// Note: if you add or change any new ObjectTypes, then please notify
// Mark C or John T so that AGCIDL.idl will be updated.
Expand Down Expand Up @@ -766,6 +770,7 @@ const ExpendableAbilityBitMask c_eabmRescueAny = c_sabmRescueAny; //0x40
typedef short AchievementMask;
const AchievementMask c_achmProbeKill = 0x01;
const AchievementMask c_achmProbeSpot = 0x02;
const AchievementMask c_achmNewRepair = 0x04;

enum ShipControlStateIGC
{
Expand Down Expand Up @@ -5473,6 +5478,8 @@ class PlayerScoreObject
m_cPlayerKills = 0.0f;
m_cBaseKills = 0.0f;
m_cBaseCaptures = 0.0f;
m_cProbeSpot = 0;
m_cRepair = 0;

m_cRescues = 0;

Expand All @@ -5499,10 +5506,16 @@ class PlayerScoreObject
m_bCommandCredit = false;

m_fScore = 0.0f;
m_rankRatio = 1.0f;

assert (!m_bConnected);
}

void SetRankRatio(float rankRatio)
{
m_rankRatio = rankRatio;
}

bool Connected(void) const
{
return m_bConnected;
Expand Down Expand Up @@ -5578,6 +5591,16 @@ class PlayerScoreObject
m_cAsteroidsSpotted++;
}

void AddProbeSpot(void)
{
m_cProbeSpot++;
}
void SetRepair(int repair)
{
m_cRepair += repair;
}


void KillShip(IshipIGC* pship,
float fraction)
{
Expand Down Expand Up @@ -5834,6 +5857,8 @@ class PlayerScoreObject
float m_cPlayerKills;
float m_cBaseKills;
float m_cBaseCaptures;
short m_cProbeSpot;
int m_cRepair;

short m_cTechsRecovered;
short m_cFlags;
Expand All @@ -5854,6 +5879,7 @@ class PlayerScoreObject
float m_fCombatRating;

float m_fScore;
float m_rankRatio;

bool m_bPlayer;
bool m_bConnected;
Expand Down
4 changes: 4 additions & 0 deletions src/Igc/missionigc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2709,6 +2709,8 @@ const float c_pointsBaseCapture = 25.0f;
const float c_pointsFlags = 10.0f;
const float c_pointsArtifacts = 10.0f;
const float c_pointsRescues = 5.0f;
const float c_pointsProbeSpot = 10.0f;
const float c_pointsRepair = 0.02f; //1 point for every 50 health restored

const float c_crAdd = 1.25f;
const float c_crDivide = 100.0f;
Expand Down Expand Up @@ -2761,6 +2763,8 @@ CstaticIGC::CstaticIGC(void)
m_constants.floatConstants[c_fcidPointsFlags] = c_pointsFlags;
m_constants.floatConstants[c_fcidPointsArtifacts] = c_pointsArtifacts;
m_constants.floatConstants[c_fcidPointsRescues] = c_pointsRescues;
//m_constants.floatConstants[c_fcidPointsProbeSpot] = c_pointsProbeSpot;
//m_constants.floatConstants[c_fcidPointsRepair] = c_pointsRepair;
m_constants.floatConstants[c_fcidRatingAdd] = c_crAdd;
m_constants.floatConstants[c_fcidRatingDivide] = c_crDivide;

Expand Down
14 changes: 12 additions & 2 deletions src/Igc/shipIGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,12 +1233,22 @@ DamageResult CshipIGC::ReceiveDamage(DamageTypeID type,
{
//Repair the target's hull
m_fraction -= amount * dtmArmor / maxHP;
if (m_fraction > 1.0f)
m_fraction = 1.0f;
if (m_fraction > 1.0f)
{
amount += (m_fraction - 1.0) * maxHP / dtmArmor; //Set amount to amount that had effect for stat
m_fraction = 1.0f;
}
GetThingSite ()->RemoveDamage (m_fraction);

leakage = 0.0f;
dr = c_drNoDamage;
if (launcher->GetObjectType() == OT_ship && (pside == launcher->GetSide()) || IsideIGC::AlliedSides(pside, launcher->GetSide()))
{

IshipIGC * pIship = ((IshipIGC*)launcher);
pIship->AddRepair(-amount);
pIship->SetAchievementMask(c_achmNewRepair);
}
}
else
{
Expand Down

0 comments on commit eeebccf

Please sign in to comment.