]> jfr.im git - irc/gameservirc.git/commitdiff
Added toplist.cpp and toplist.h which will allow a top x list of players to be held...
authorkainazzzo <redacted>
Thu, 2 Nov 2006 01:50:25 +0000 (01:50 +0000)
committerkainazzzo <redacted>
Thu, 2 Nov 2006 01:50:25 +0000 (01:50 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@461 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/Makefile.in
gameserv/TODO
gameserv/do_attack.cpp
gameserv/gameserv.cpp
gameserv/player.cpp
gameserv/player.h
gameserv/toplist.cpp [new file with mode: 0644]
gameserv/toplist.h [new file with mode: 0644]
gameserv/toplist.o [new file with mode: 0644]

index 72d2149619fe56b975fed7312819ba237ab8c321..a06b814888f4ffb0d2eb34edee78846c8b59d688 100644 (file)
@@ -34,7 +34,8 @@ TSRCS =       aClient.cpp \
        pouch.cpp \
        player.cpp \
        script.cpp \
-       sockhelp.cpp
+       sockhelp.cpp \
+       toplist.cpp
 
 CONSOLESRCS = $(TSRCS) $(CONSOLEDRIVER)
 SRCS = $(TSRCS) $(DRIVER)
index e6fe3abd70a0e4064d86f7fcf6e1188c86fbe210..3e39a08fffe880f7caed736e13afe4303f8a789b 100644 (file)
@@ -3,8 +3,6 @@
 X = Finished
 C = Cancelled
 
-* Output player list in an includable PHP file - TDC
-
 * Add a top player list - thelizno
 
 * Make GameServ tell the channel when two players are in a duel and who wins - DjSlash
@@ -166,3 +164,6 @@ X Add a title to people when they beat the dragon - Tsukasa
 C Put some limits on what players can gain per level - Steve
 
 X Make config file accept hostnames not just ips
+
+X Output player list in an includable PHP file - TDC
+
index 17137c5053d9261eb09593308abd11604b79d852..be2f14e3a28d0c29abe35b6597b7ccee0291ff4a 100644 (file)
@@ -266,6 +266,7 @@ void do_attack(char *u)
                        {
                          if (hit > 0)
                                battle->stats->subtractHP(hit);
+
                          clearYourTurn(ni->stats);
                          setYourTurn(battle->stats);
                          display_players(battle);
index 8bb30b2833ac377b6eacfd929aeb5dd59da93fb2..64987fa6ece76e216a9b5f930043109cf9a97f4b 100644 (file)
@@ -3596,6 +3596,8 @@ void timeOutEvent(Player *p)
                                 "sit there!", p->getBattle()->stats->getName().c_str());
                  logout(p->getBattle());
                  logout(p->getClient());
+                 clearYourTurn(p);
+                 clearYourTurn(p->getBattle()->stats);
                  return;
                }
     }
index 70572a5200b083d685c79eb70a3176b78af1881c..0f1c8007410bf4a66eba45dba84c1f8437e1ae45 100644 (file)
@@ -510,3 +510,22 @@ void Player::delBattle()
   battle = NULL;
 }
 
+bool Player::operator <(Player &right)
+{
+  if (getLevel() < right.getLevel())
+       {
+         return true;
+       }
+  else if (getExp() < right.getExp())
+       {
+         return true;
+       }
+  else if (getStrength() < right.getStrength() && getDefense() < right.getDefense())
+       {
+         return true;
+       }
+  else
+       {
+         return false;
+       }
+}
index f4b1bba3354acc2abd4682b5fad64e8654c0bd2f..1450a1396fe1c5d813bc7638267a54f7bd969aac 100644 (file)
@@ -2,6 +2,7 @@
 #define PLAYER_H
 
 #include <string>
+#include "script.h"
 
 using namespace std;
 
@@ -111,6 +112,7 @@ public:
   long int lastcommand;        // timestamp for the last command typed
   long int lastlogin;          // timestamp for the last login
 
+  bool operator <(Player &right);
   
 private:
   string name;         // Player's Name
diff --git a/gameserv/toplist.cpp b/gameserv/toplist.cpp
new file mode 100644 (file)
index 0000000..c3a82ab
--- /dev/null
@@ -0,0 +1,60 @@
+#include "toplist.h"
+#include "player.h"
+#include <list>
+
+using namespace std;
+
+toplist::toplist()
+{
+  myList.clear();
+  count = 10;
+}
+
+toplist::toplist(int c)
+{
+  myList.clear();
+  count = c;
+}
+
+toplist::~toplist()
+{
+  myList.clear();
+  count = 10;
+}
+
+void toplist::insertPlayer(Player *p)
+{
+  myList.push_front(*p);
+  sort();
+  prune();
+}
+
+void toplist::setCount(int c)
+{
+  count = c;
+}
+
+void toplist::sort()
+{
+  myList.sort();
+}
+
+void toplist::prune()
+{
+  list<Player>::iterator it;
+  it = myList.begin();
+
+  for (int x = 0; it != myList.end(); x++, it++)
+       {
+         if (x > count)
+               {
+                 // Delete this player from the top list, because they're over the count
+                 myList.erase(it);
+               }
+       }
+}
+
+list<Player>::iterator toplist::top()
+{
+  return myList.begin();
+}
diff --git a/gameserv/toplist.h b/gameserv/toplist.h
new file mode 100644 (file)
index 0000000..acd5aa9
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef TOPLIST_H
+#define TOPLIST_H
+
+#include <list>
+
+using namespace std;
+
+// Forward declaration
+class Player;
+
+class toplist {
+public:
+  // Default Constructor
+  toplist();
+
+  // Constructor with a parameter for the count
+  toplist(int);
+
+  // Destructor
+  ~toplist();
+
+  // Insert the player into the top list if they make it
+  void insertPlayer(Player *);
+
+  // Set how many players should be in the toplist
+  void setCount(int);
+  int getCount() { return count; };
+
+  // Sort the list
+  void sort();
+
+  // Prune the list so it's not larger than the count
+  void prune();
+
+  list<Player>::iterator top();
+
+private:
+
+  // The actual list of players
+  list<Player> myList;
+
+  // The number of players to keep in the list
+  int count;
+};
+#endif
diff --git a/gameserv/toplist.o b/gameserv/toplist.o
new file mode 100644 (file)
index 0000000..546222c
Binary files /dev/null and b/gameserv/toplist.o differ