]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add achievements for match place and most damage
authorAriosJentu <darthpoezd@gmail.com>
Mon, 26 Aug 2019 11:51:18 +0000 (21:51 +1000)
committerAriosJentu <darthpoezd@gmail.com>
Mon, 26 Aug 2019 11:51:18 +0000 (21:51 +1000)
qcsrc/common/achievements.qc
qcsrc/common/achievements.qh
qcsrc/server/g_world.qc

index e9f3abacfc7e4098aabc6c6338310c664c2b704f..51be86530e571563e2a07e013a5396cb8beb7182 100644 (file)
@@ -23,6 +23,10 @@ void Achievements_set_achievement_value(entity this, string achieve, int value)
        if (achieve == "armageddon") this.armageddon = value;
 
        if (achieve == "firstblood") this.firstblood = value;
+       if (achieve == "firstplace") this.firstplace = value;
+       if (achieve == "secondplace") this.secondplace = value;
+       if (achieve == "thirdplace") this.thirdplace = value;
+       if (achieve == "mostdamage") this.mostdamage = value;
 
        if (achieve == "airshot") this.airshot = value;
        if (achieve == "amazing") this.amazing = value;
@@ -50,6 +54,10 @@ int Achievements_get_achievement_value(entity this, string achieve) {
        if (achieve == "armageddon") return this.armageddon;
 
        if (achieve == "firstblood") return this.firstblood;
+       if (achieve == "firstplace") return this.firstplace;
+       if (achieve == "secondplace") return this.secondplace;
+       if (achieve == "thirdplace") return this.thirdplace;
+       if (achieve == "mostdamage") return this.mostdamage;
 
        if (achieve == "airshot") return this.airshot;
        if (achieve == "amazing") return this.amazing;
@@ -77,6 +85,10 @@ string Achievements_get_achievement_title(string achieve) {
        if (achieve == "armageddon") return "Armageddon!";
 
        if (achieve == "firstblood") return "First Blood!";
+       if (achieve == "firstplace") return "First Place!";
+       if (achieve == "secondplace") return "Second Place!";
+       if (achieve == "thirdplace") return "Third Place!";
+       if (achieve == "mostdamage") return "Most Damage!";
 
        if (achieve == "airshot") return "Air Shot!";
        if (achieve == "amazing") return "Amazing!";
index 87f1588159ee1aca4608b172043372e6142a728a..a916b26d0001e53e4c87b4582a6fec2ac033a6e5 100644 (file)
@@ -15,6 +15,10 @@ CLASS(Achievements, Object)
 
        //Boolean achievements (can be set only once)
        ATTRIB(Achievements, firstblood, bool, 0);
+       ATTRIB(Achievements, firstplace, bool, 0);
+       ATTRIB(Achievements, secondplace, bool, 0);
+       ATTRIB(Achievements, thirdplace, bool, 0);
+       ATTRIB(Achievements, mostdamage, bool, 0);
 
        //Notificated achievements
        ATTRIB(Achievements, airshot, int, 0);
@@ -30,6 +34,7 @@ CLASS(Achievements, Object)
        ATTRIB(Achievements, pointblank, int, 0);
        ATTRIB(Achievements, selfimmolation, int, 0);
 
+
        //Getters and setters for achievements  
        METHOD(Achievements, set_achievement_value, void(Achievements this, string achieve, int value));
        METHOD(Achievements, get_achievement_value, int(Achievements this, string achieve));
index 8680b83a58b596665d6052d2003f3317310a8aab..119dc59e519415c5accc76a36d8389f508fe11fa 100644 (file)
@@ -1573,6 +1573,11 @@ void FixIntermissionClient(entity e)
        }
 }
 
+void increase_achieve(entity player, string name) {
+       player.achievements.inc_achievement(player.achievements, name);
+       player.achievements.announce(player.achievements, player, name);
+}
+
 /*
 go to the next level for deathmatch
 only called if a time or frag limit has expired
@@ -1626,6 +1631,46 @@ void NextLevel()
        MUTATOR_CALLHOOK(MatchEnd);
 
        localcmd("\nsv_hook_gameend\n");
+
+
+       //Achievements
+       entity firstplace = spawn();
+       entity secondplace = spawn();
+       entity thirdplace = spawn();
+       entity mostdamage = spawn();
+
+       FOREACH_CLIENT(IS_PLAYER(it), {
+
+               if (!firstplace) {
+                       firstplace = it;
+               }
+
+               if (!mostdamage) {
+                       mostdamage = it;
+               }
+               
+               float itaverage = PlayerScore_Get(it, SP_KILLS) / PlayerScore_Get(it, SP_SUICIDES);
+               float plaverage = PlayerScore_Get(firstplace, SP_KILLS) / PlayerScore_Get(firstplace, SP_SUICIDES);
+               bool cond = (firstplace.totalfrags == it.totalfrags && itaverage > plaverage);
+               
+               if (it.totalfrags > firstplace.totalfrags || cond) {
+                       thirdplace = secondplace;
+                       secondplace = firstplace;
+                       firstplace = it;
+               }
+
+               if (PlayerScore_Get(it, SP_DMG) > PlayerScore_Get(mostdamage, SP_DMG)) {
+                       mostdamage = it;
+               }
+
+       });
+
+       if (IS_PLAYER(firstplace)) increase_achieve(firstplace, "firstplace");
+       if (IS_PLAYER(secondplace)) increase_achieve(secondplace, "secondplace");
+       if (IS_PLAYER(thirdplace)) increase_achieve(thirdplace, "thirdplace");
+       if (IS_PLAYER(mostdamage)) increase_achieve(mostdamage, "mostdamage");
+
+
 }