trivial atlantik patch, please review though

Rob Kaper cap at capsi.com
Wed Oct 23 16:28:39 BST 2002


Some changes in the monopd API were absolutely necessary to keep future
compatibility. I'd rather fix this in time for 3.1 than to break it later,
without these patches Atlantik won't work anyway. :-/

But as the policy goes, please review.

The patch is pretty trivial, most of it is simply reading different
attributes from XML, app logic hasn't changed.

Rob
-- 
Rob Kaper     | Gimme some love, gimme some skin,
cap at capsi.com | if we ain't got that then we ain't got much
www.capsi.com | and we ain't got nothing, nothing! -- "Nothing" by A
-------------- next part --------------
Index: TODO
===================================================================
RCS file: /home/kde/kdegames/atlantik/TODO,v
retrieving revision 1.143
diff -u -3 -d -p -r1.143 TODO
--- TODO	2002/10/23 00:31:46	1.143
+++ TODO	2002/10/23 15:23:37
@@ -2,18 +2,6 @@
 ^ in progress
 v implemented
 
-monopd API changes (break behavior, fix)
-------------------
-
-- API: replaced joinedgame with correct use of <gameupdate> tag
-- API: clientid in client message is now playerid, playerid no longer reset
-  at game startup, so a game does not necessarily have players 0 through n.
-- API: clientid in updateplayerlist message is also merged into playerid
-- API: group attribute in estateupdate sends groupid now, not name, groupid
-  attribute added to estategroupupdate
-- API: merged estatedisplay with display
-- API: moved newturn message to playerupdate attribute hasturn
-
 monopd API changes (features)
 ------------------
 
@@ -38,8 +26,8 @@ For 0.5.0
 
 v fixed dangling pointer for removeGUI(Trade *) in AtlanticCore
 v player name change doesn't make it to trade money items
-v API: replaced joinedgame with correct use of <gameupdate> tag
 v fixed token positioning on game start
+v fixes to work with monopd 0.6.0 API
 
 For 0.6.0
 ---------
Index: libatlantic/atlantic_core.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantic/atlantic_core.cpp,v
retrieving revision 1.13
diff -u -3 -d -p -r1.13 atlantic_core.cpp
--- libatlantic/atlantic_core.cpp	2002/07/29 19:09:49	1.13
+++ libatlantic/atlantic_core.cpp	2002/10/23 15:23:37
@@ -56,9 +56,9 @@ QPtrList<EstateGroup> AtlanticCore::esta
 	return m_estateGroups;
 }
 
-EstateGroup *AtlanticCore::newEstateGroup(QString name)
+EstateGroup *AtlanticCore::newEstateGroup(const int id)
 {
-	EstateGroup *estateGroup = new EstateGroup(name);
+	EstateGroup *estateGroup = new EstateGroup(id);
 	m_estateGroups.append(estateGroup);
 	return estateGroup;
 }
@@ -103,18 +103,4 @@ void AtlanticCore::delAuction(Auction *a
 {
 	m_auctions.remove(auction);
 	delete auction;
-}
-
-void AtlanticCore::setCurrentTurn(Player *player)
-{
-	Player *p;
-	for (QPtrListIterator<Player> i(m_players); *i; ++i)
-	{
-		p = dynamic_cast<Player *>(*i);
-		if (p)
-		{
-			p->setHasTurn(p==player);
-			p->update();
-		}
-	}
 }
Index: libatlantic/atlantic_core.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantic/atlantic_core.h,v
retrieving revision 1.12
diff -u -3 -d -p -r1.12 atlantic_core.h
--- libatlantic/atlantic_core.h	2002/07/29 19:09:49	1.12
+++ libatlantic/atlantic_core.h	2002/10/23 15:23:37
@@ -40,7 +40,7 @@ public:
 	Estate *newEstate(int estateId);
 
 	QPtrList<EstateGroup> estateGroups();
-	EstateGroup *newEstateGroup(QString name);
+	EstateGroup *newEstateGroup(const int id);
 
 	QPtrList<Trade> trades();
 	Trade *newTrade(int tradeId);
@@ -49,8 +49,6 @@ public:
 	QPtrList<Auction> auctions();
 	Auction *newAuction(int auctionId, Estate *estate);
 	void delAuction(Auction *auction);
-
-	void setCurrentTurn(Player *player);
 
 signals:
 	void removeGUI(Trade *trade);
Index: libatlantic/estategroup.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantic/estategroup.cpp,v
retrieving revision 1.3
diff -u -3 -d -p -r1.3 estategroup.cpp
--- libatlantic/estategroup.cpp	2002/04/23 17:02:55	1.3
+++ libatlantic/estategroup.cpp	2002/10/23 15:23:37
@@ -17,9 +17,9 @@
 #include "estategroup.h"
 #include "estategroup.moc"
 
-EstateGroup::EstateGroup(const QString name) : QObject()
+EstateGroup::EstateGroup(const int id) : QObject()
 {
-	m_name = name;
+	m_id = id;
 }
 
 void EstateGroup::setName(const QString name)
Index: libatlantic/estategroup.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantic/estategroup.h,v
retrieving revision 1.3
diff -u -3 -d -p -r1.3 estategroup.h
--- libatlantic/estategroup.h	2002/04/23 17:02:55	1.3
+++ libatlantic/estategroup.h	2002/10/23 15:23:37
@@ -24,7 +24,7 @@ class EstateGroup : public QObject
 Q_OBJECT
 
 public:
-	EstateGroup(const QString name);
+	EstateGroup(const int id);
 	void setName(const QString name);
 	QString name() const { return m_name; }
 	void update(bool force = false);
@@ -33,6 +33,7 @@ signals:
 	void changed();
 
 private:
+	int m_id;
 	bool m_changed;
 	QString m_name;
 };
Index: libatlantikclient/atlantik_network.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikclient/atlantik_network.cpp,v
retrieving revision 1.61
diff -u -3 -d -p -r1.61 atlantik_network.cpp
--- libatlantikclient/atlantik_network.cpp	2002/09/11 03:49:59	1.61
+++ libatlantikclient/atlantik_network.cpp	2002/10/23 15:23:37
@@ -38,7 +38,7 @@ AtlantikNetwork::AtlantikNetwork(Atlanti
 {
 	m_atlanticCore = atlanticCore;
 	m_parent = parent;
-	m_clientId = m_playerId = -1;
+	m_playerId = -1;
 
 	QObject::connect(this, SIGNAL(readyRead()), this, SLOT(slotRead()));
 }
@@ -270,31 +270,6 @@ void AtlantikNetwork::processNode(QDomNo
 			}
 			else if (e.tagName() == "display")
 			{
-				QString caption = e.attributeNode(QString("name")).value();
-				QString description = e.attributeNode(QString("description")).value();
-				
-				if (caption.isEmpty() && description.isEmpty())
-					emit displayDefault();
-				else
-				{
-					emit displayText(caption, description);
-
-					bool hasButtons = false;
-					for(QDomNode nButtons = n.firstChild() ; !nButtons.isNull() ; nButtons = nButtons.nextSibling() )
-					{
-						QDomElement eButton = nButtons.toElement();
-						if (!eButton.isNull() && eButton.tagName() == "button")
-						{
-							emit addCommandButton(eButton.attributeNode(QString("command")).value(), eButton.attributeNode(QString("caption")).value(), eButton.attributeNode(QString("enabled")).value().toInt());
-							hasButtons = true;
-						}
-					}
-					if (!hasButtons)
-						emit addCloseButton();
-				}
-			}
-			else if (e.tagName() == "estatedisplay")
-			{
 				int estateId = -1;
 
 				a = e.attributeNode(QString("estateid"));
@@ -305,6 +280,8 @@ void AtlantikNetwork::processNode(QDomNo
 					if ((estate = m_estates[a.value().toInt()]))
 					{
 						emit displayEstate(estate);
+						// TODO: merge into displayEstate, or statusbar
+						emit msgInfo(e.attributeNode(QString("text")).value());
 
 						bool hasButtons = false;
 						for( QDomNode nButtons = n.firstChild() ; !nButtons.isNull() ; nButtons = nButtons.nextSibling() )
@@ -323,6 +300,8 @@ void AtlantikNetwork::processNode(QDomNo
 						if (!hasButtons)
 							emit addCloseButton();
 					}
+					else
+						displayDefault();
 				}
 			}
 			else if (e.tagName() == "updategamelist")
@@ -362,22 +341,11 @@ void AtlantikNetwork::processNode(QDomNo
 					if (!e_player.isNull() && e_player.tagName() == "player")
 					{
 						if (type=="del")
-							emit playerListDel(e_player.attributeNode(QString("clientid")).value());
+							emit playerListDel(e_player.attributeNode(QString("playerid")).value());
 						else if (type=="edit")
-							emit playerListEdit(e_player.attributeNode(QString("clientid")).value(), e_player.attributeNode(QString("name")).value(), e_player.attributeNode(QString("host")).value());
+							emit playerListEdit(e_player.attributeNode(QString("playerid")).value(), e_player.attributeNode(QString("name")).value(), e_player.attributeNode(QString("host")).value());
 						else if (type=="add" || type=="full")
-						{
-							int playerId = -1;
-							a = e_player.attributeNode(QString("playerid"));
-							if (!a.isNull())
-								playerId = a.value().toInt();
-
-							a = e_player.attributeNode(QString("clientid"));
-							if (!a.isNull() && a.value().toInt() == m_clientId)
-								m_playerId = playerId;
-							
 							emit playerListAdd(e_player.attributeNode(QString("clientid")).value(), e_player.attributeNode(QString("name")).value(), e_player.attributeNode(QString("host")).value());
-						}
 					}
 					n_player = n_player.nextSibling();
 				}
@@ -385,21 +353,14 @@ void AtlantikNetwork::processNode(QDomNo
 			}
 			else if (e.tagName() == "client")
 			{
-				a = e.attributeNode(QString("clientid"));
+				a = e.attributeNode(QString("playerid"));
 				if (!a.isNull())
 				{
-					m_clientId = a.value().toInt();
+					m_playerId = a.value().toInt();
 					// TODO: move to Atlantik::slotNetworkConnected(), not needed on auto-join
 					cmdGamesList();
 				}
 			}
-			else if (e.tagName() == "newturn")
-			{
-				Player *player = m_playerMap[e.attributeNode(QString("player")).value().toInt()];
-				if (player)
-					// Update *all* objects
-					m_atlanticCore->setCurrentTurn(player);
-			}
 			else if (e.tagName() == "configupdate")
 			{
 				int gameId = -1;
@@ -473,6 +434,10 @@ void AtlantikNetwork::processNode(QDomNo
 					if (player && !a.isNull())
 						player->setMoney(a.value().toInt());
 
+					a = e.attributeNode(QString("hasturn"));
+					if (player && !a.isNull())
+						player->setHasTurn(a.value().toInt());
+
 					// Update whether player can roll
 					a = e.attributeNode(QString("can_roll"));
 					if (player && !a.isNull())
@@ -520,21 +485,27 @@ void AtlantikNetwork::processNode(QDomNo
 			}
 			else if (e.tagName() == "estategroupupdate")
 			{
-				a = e.attributeNode(QString("name"));
+				a = e.attributeNode(QString("estategroupid"));
 				if (!a.isNull())
 				{
+					int groupId = a.value().toInt();
+
 					EstateGroup *estateGroup;
 					bool b_newEstateGroup = false;
 					
-					if (!(estateGroup = m_estateGroups[a.value()]))
+					if (!(estateGroup = m_estateGroups[groupId]))
 					{
 						// Create EstateGroup object
-						estateGroup = m_atlanticCore->newEstateGroup(a.value());
-						m_estateGroups[a.value()] = estateGroup;
+						estateGroup = m_atlanticCore->newEstateGroup(a.value().toInt());
+						m_estateGroups[groupId] = estateGroup;
 
 						b_newEstateGroup = true;
 					}
 
+					a = e.attributeNode(QString("name"));
+					if (estateGroup && !a.isNull())
+						estateGroup->setName(a.value());
+
 					// Emit signal so GUI implementations can create view(s)
 					// TODO:  port to atlanticcore and create view there
 					if (estateGroup)
@@ -605,7 +576,7 @@ void AtlantikNetwork::processNode(QDomNo
 					a = e.attributeNode(QString("group"));
 					if (!a.isNull())
 					{
-						EstateGroup *estateGroup = m_estateGroups[a.value()];
+						EstateGroup *estateGroup = m_estateGroups[a.value().toInt()];
 						if (estate)
 							estate->setEstateGroup(estateGroup);
 					}
Index: libatlantikclient/atlantik_network.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/libatlantikclient/atlantik_network.h,v
retrieving revision 1.32
diff -u -3 -d -p -r1.32 atlantik_network.h
--- libatlantikclient/atlantik_network.h	2002/09/11 03:46:37	1.32
+++ libatlantikclient/atlantik_network.h	2002/10/23 15:23:37
@@ -167,13 +167,13 @@ private:
 	QObject *m_parent;
 	QDomDocument msg;
 
-	int m_clientId, m_playerId;
+	int m_playerId;
 
 	QMap<int, Player *> m_playerMap;
 	QMap<Player *, int> m_playerRevMap;
 	QMap<Player *, int> m_playerLocationMap;
 	QMap<int, Estate *> m_estates;
-	QMap<QString, EstateGroup *> m_estateGroups;
+	QMap<int, EstateGroup *> m_estateGroups;
 	QMap<int, Trade *> m_trades;
 	QMap<int, Auction *> m_auctions;
 };


More information about the kde-core-devel mailing list