]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add achievements
authorAriosJentu <darthpoezd@gmail.com>
Fri, 23 Aug 2019 11:32:13 +0000 (21:32 +1000)
committerAriosJentu <darthpoezd@gmail.com>
Fri, 23 Aug 2019 11:32:13 +0000 (21:32 +1000)
qcsrc/common/_all.inc
qcsrc/common/_mod.inc
qcsrc/common/_mod.qh
qcsrc/common/achievements.qc [new file with mode: 0644]
qcsrc/common/achievements.qh [new file with mode: 0644]
qcsrc/server/client.qc

index 9d7c68a8eea3f58bdfb771e62b0df73e34bd20c6..8586e795cd32fe36137b724d3176078ac2c821ec 100644 (file)
@@ -50,3 +50,5 @@ noref float autocvar_net_connecttimeout = 30;
 
 #include "mutators/_mod.inc"
     #include "gamemodes/_mod.inc"
+
+#include "achievements.qc"
index 0ac07a19aa1e86e7e7b8682c5ff33687892b00b7..4ccd5c21afd4484d862e6ad6468dea45a523448b 100644 (file)
@@ -12,3 +12,4 @@
 #include <common/util.qc>
 #include <common/viewloc.qc>
 #include <common/wepent.qc>
+#include <common/achievements.qc>
index 3e16f9cbe8e4c024b45dc8e3f252f6e7b42fff5e..420db8e71bf49d6ad2f5520b9667d87680a8a143 100644 (file)
@@ -12,3 +12,4 @@
 #include <common/util.qh>
 #include <common/viewloc.qh>
 #include <common/wepent.qh>
+#include <common/achievements.qh>
diff --git a/qcsrc/common/achievements.qc b/qcsrc/common/achievements.qc
new file mode 100644 (file)
index 0000000..3b96e40
--- /dev/null
@@ -0,0 +1,75 @@
+#include "achievements.qh"
+
+void Achievements_attach(entity this) {
+       this.achievements = NEW(Achievements, this);
+}
+
+void Achievements_detach(entity this) {
+       if (this.achievements) {
+               this.achievements = NULL;
+               delete(this.achievements);
+       }
+       return;
+}
+
+void Achievements_set_achievement_value(entity this, string achieve, int value) {
+
+       if (achieve == "triple_kill") { this.triple_kill = value; }
+       if (achieve == "rage") { this.rage = value; }
+       if (achieve == "massacre") { this.massacre = value; }
+       if (achieve == "mayhem") { this.mayhem = value; }
+       if (achieve == "berserker") { this.berserker = value; }
+       if (achieve == "carnage") { this.carnage = value; }
+       if (achieve == "armageddon") { this.armageddon = value; }
+
+       if (achieve == "firstblood") { this.firstblood = value; }
+
+       if (achieve == "airshot") { this.airshot = value; }
+       if (achieve == "amazing") { this.amazing = value; }
+       if (achieve == "awesome") { this.awesome = value; }
+       if (achieve == "botlike") { this.botlike = value; }
+       if (achieve == "electrobitch") { this.electrobitch = value; }
+       if (achieve == "impressive") { this.impressive = value; }
+       if (achieve == "flyingyoda") { this.flyingyoda = value; }
+       if (achieve == "multirailed") { this.multirailed = value; }
+
+       return;
+}
+
+int Achievements_get_achievement_value(entity this, string achieve) {
+
+       if (achieve == "triple_kill") { return this.triple_kill; }
+       if (achieve == "rage") { return this.rage; }
+       if (achieve == "massacre") { return this.massacre; }
+       if (achieve == "mayhem") { return this.mayhem; }
+       if (achieve == "berserker") { return this.berserker; }
+       if (achieve == "carnage") { return this.carnage; }
+       if (achieve == "armageddon") { return this.armageddon; }
+
+       if (achieve == "firstblood") { return this.firstblood; }
+
+       if (achieve == "airshot") { return this.airshot; }
+       if (achieve == "amazing") { return this.amazing; }
+       if (achieve == "awesome") { return this.awesome; }
+       if (achieve == "botlike") { return this.botlike; }
+       if (achieve == "electrobitch") { return this.electrobitch; }
+       if (achieve == "impressive") { return this.impressive; }
+       if (achieve == "flyingyoda") { return this.flyingyoda; }
+       if (achieve == "multirailed") { return this.multirailed; }
+
+       return 0;
+}
+
+void Achievements_add_achievement_value(entity this, string achieve, int value) {
+       Achievements_set_achievement_value(this, achieve, Achievements_get_achievement_value(this, achieve)+value);
+}
+
+void Achievements_inc_achievement(entity this, string achieve) {
+       return Achievements_add_achievement_value(this, achieve, 1);
+}
+
+void Achievements_announce(Achievements this, entity whom, string title, string achieve) {
+       #ifdef SVQC
+               centerprint(whom, strcat(title, " [", ftos(this.get_achievement_value(this, achieve)), "]"));
+       #endif
+}
\ No newline at end of file
diff --git a/qcsrc/common/achievements.qh b/qcsrc/common/achievements.qh
new file mode 100644 (file)
index 0000000..a2afc1a
--- /dev/null
@@ -0,0 +1,46 @@
+#pragma once
+
+CLASS(Achievements, Object)
+
+       ATTRIB(Achievements, player, entity);
+       
+       //Kill achievements
+       ATTRIB(Achievements, triple_kill, int, 0);
+       ATTRIB(Achievements, rage, int, 0);
+       ATTRIB(Achievements, massacre, int, 0);
+       ATTRIB(Achievements, mayhem, int, 0);
+       ATTRIB(Achievements, berserker, int, 0);
+       ATTRIB(Achievements, carnage, int, 0);
+       ATTRIB(Achievements, armageddon, int, 0);
+
+       //Boolean achievements (can be set only once)
+       ATTRIB(Achievements, firstblood, bool, 0);
+
+       //Notificated achievements
+       ATTRIB(Achievements, airshot, int, 0);
+       ATTRIB(Achievements, amazing, int, 0);
+       ATTRIB(Achievements, awesome, int, 0);
+       ATTRIB(Achievements, botlike, int, 0);
+       ATTRIB(Achievements, electrobitch, int, 0);
+       ATTRIB(Achievements, impressive, int, 0);
+       ATTRIB(Achievements, flyingyoda, int, 0); //In Yoda maybe incorrect conditions
+       ATTRIB(Achievements, multirailed, int, 0);
+
+       METHOD(Achievements, set_achievement_value, void(Achievements this, string achieve, int value));
+       METHOD(Achievements, get_achievement_value, int(Achievements this, string achieve));
+       METHOD(Achievements, add_achievement_value, void(Achievements this, string achieve, int value));
+       METHOD(Achievements, inc_achievement, void(Achievements this, string achieve));
+       METHOD(Achievements, announce, void(Achievements this, entity whom, string title, string achieve));
+
+       CONSTRUCTOR(Achievements, entity aplayer) 
+       {
+               CONSTRUCT(Achievements);
+               this.player = aplayer;
+       }
+
+ENDCLASS(Achievements)
+
+.Achievements achievements;
+
+void Achievements_attach(entity this);
+void Achievements_detach(entity this);
index 0034c2dd9ee3b687a0b600eee0b850cc056dfb89..c0680d87566e37ef35601e056cfd21ba004be8a4 100644 (file)
@@ -73,6 +73,8 @@
 
 #include <common/mutators/mutator/overkill/oknex.qh>
 
+#include <common/achievements.qh>
+
 STATIC_METHOD(Client, Add, void(Client this, int _team))
 {
     ClientConnect(this);
@@ -1101,6 +1103,8 @@ void ClientConnect(entity this)
 
        PlayerStats_GameReport_AddEvent(sprintf("kills-%d", this.playerid));
 
+       Achievements_attach(this);
+
        // always track bots, don't ask for cl_allow_uidtracking
        if (IS_BOT_CLIENT(this))
                PlayerStats_GameReport_AddPlayer(this);
@@ -1240,6 +1244,8 @@ void ClientDisconnect(entity this)
        ReadyCount();
        if (vote_called && IS_REAL_CLIENT(this)) VoteCount(false);
 
+       Achievements_detach(this);
+
        ONREMOVE(this);
 }