You need the xml interface only in the topmost objet, diplomaticstatus, and you have to declare it in the list of classes that the parser recognizes (in FileInput.java or ScenarioFiles.java or both, I don't know exactly which one is used - should check it when I have some time).Originally posted by vovansim
So, I guess I wil describe the data structure first. There is a class called DiplomaticStatuses. It contains all of the diplomatic statuses for the game. Inside, it has a setStatus() method, that takes in two civilizations, and a StatusStrength object. Now, status strength itself is an abstract class. But the acceptable values for the value to pass in are the children of the class, static classes: War, Peace, and Alliance.
Sooo, I suppose the XML should then look like this (on an example of delenda scenario):
??Code:<diplomaticstatuses> <status> <civilization>Rome</civilization> <civilization>Carthage</civilization> <diplomaticstrength> <war /> </diplomaticstrength> </status> </diplomaticstatuses>
Given that I include the xml interface and the appropriate static function in classes DiplomaticStatuses, and all of the subclasses of DiplomaticStrength. Is that how it is supposed to work, or am I missing something?
So you don't need it in DiplomaticStatus subclasses (you can look at ElementArchetype/ElementCost in the military moel for an example: ElementCost is an object inside ElementArchetype but has no getXML() method, everything is done by reflexion).
To get your example working, you need the getXML method declared for diplomaticstatus class, and a public setStatus method, which takes a Status object as an input, and nothing else (again, you can look at ElementArchetype.setCost method).
The Status object needs a setCivilization (or addCivilization) method (both set and add are OK, add would be better here since you add several). Note hte method names needed can be in any case as the parser doesn't worry about setCost or setcost or setcosT (though setCost is better IMO) for instance.
Instead of a
<diplomaticstrength>
<war />
</diplomaticstrength>
I'd suggest only a <war /> tag, with the corresponding setWar() method (as an example, you have the militia tag in ElementArchetype). That forces you to have several setWar, setPeace... methods. You can bypass that by using
<diplomaticstrength>war</diplomaticstrength>
and having a single setDiplomaticStrength(String) method instead.
That's about how it works: getXML() for root tags, then reflexion only. In order for reflexion to work, you need public no-arg constructors in the classes that will be created by the parser, and either setXXX public methods or (but I don't like that) public data members XXX.



Reply With Quote

) So, what we do, is just basically e-mail everyone the changes we make to the code, and say in the e-mail which files we changed so that it is easier to keep track of the stuff. Also, if you are going to change something that you think other people might be working on, just e-mail everybody in advance about the changes you are about to make. If somebody is indeed working on the same class, they will contact you and coordinate the efforts.


Bookmarks