PBeM-Spiele
Aktuelle Zeit: 29.03.2024 00:08

Alle Zeiten sind UTC + 1 Stunde




Ein neues Thema erstellen Auf das Thema antworten  [ 33 Beiträge ]  Gehe zu Seite 1, 2, 3  Nächste
Autor Nachricht
 Betreff des Beitrags: ExtendedCommands für Anfänger
BeitragVerfasst: 12.02.2017 11:18 
Offline
Neuling
Neuling

Registriert: 12.02.2017 10:52
Beiträge: 2
Hallo zusammen,

ich spiele nun seit ein paar Wochen wieder Eressea und möchte langsam mal damit Anfangen, einen Teil meiner Einheiten zu automatisieren. Dazu möchte ich gern die Extended Commands nutzen, habe mich auf den im Wiki verlinkten Seiten und bedingt auch hier im Forum bereits umgesehen und scheitere grad schon daran, die möglichen Klassen, Methoden etc. zu finden.

Die unter Erweiterte Befehle Hilfe aufgeführten links:
magellan.library.*
magellan.library.rules.*
Helper API
http://magellan.log-out.net/javadoc
funktionieren leider nicht mehr.

könnte mir da vielleicht jemand weiter helfen?

(am Rande: meine Java-Kenntnisse sind quasi gleich null, was aber m.M.n. kein Problem darstellen sollte, das man nicht in den Griff bekommt. ;)


Zuletzt geändert von Bjørn am 15.02.2017 16:47, insgesamt 1-mal geändert.

Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: 15.02.2017 10:49 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 396
Wohnort: Karlsruhe
Hi Bjørn,

ich würde Dir empfehlen, doch den Nightly Build von Magellan herunterzuladen, wenn du mit ExtendedCommands arbeiten willst. Dort sind auch die Links richtig. Du kannst auch alle Vorkommen von magellan.log-out.net/javadoc durch magellan.narabi.de/nightly-build/api ersetzen, also
http://magellan.narabi.de/nightly-build ... elper.html
http://magellan.narabi.de/nightly-build/api/

Es gibt aber einige Unterschiede zwischen Stable und Nightly Build. Ob es die API zur "stabilen" Version von Magellan und ExtendedCommands auch noch gibt, kann ich gerade nicht sagen.

Falls Du weitere Fragen hast, stelle sie ruhig hier. Das hilft hoffentlich auch anderen.

_________________
Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: 15.02.2017 16:46 
Offline
Neuling
Neuling

Registriert: 12.02.2017 10:52
Beiträge: 2
Hey Solthar,
vielen Danke für die Hinweise!

nachdem ich mich nun auch schon durch diverse .class-Dateien des Stable Builds gewühlt habe, konnte ich schon den Großteil meiner Vorstellungen umsetzen und mit der API des Nightly Builds hat's dann auch mit dem Rest geklappt. (Deiner Empfehlung folgend, bin ich auch auf den Nightly Build umgestiegen.)

Da meine Partei noch am Anfang ist, hält sich die Komplexität der Befehle in Grenzen. Sollten sich aber künftig Fragen ergeben, stelle ich sie auch gern an dieser Stelle. :)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 16.09.2020 13:27 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
I was really interested in learning Extended Commands, but need the documentation. I tried accessing the links in the nightly build as well as through the links provided by Solthar and they are not working.

Is there anywhere else to get the documentation for Extended Commands?

Thanks


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 22.09.2020 10:26 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 396
Wohnort: Karlsruhe
The documentation is now included locally in the Magellan installation. Download the installer (it's also included in the zip in the folder doc/api), install the version and be sure to check "Api doc" (or whatever it's called) in the installation dialog. Once you open Magellan press Ctrl+4 to open the Extended Commands Dock and press the Help button. You can open it in your browser, too.

_________________
Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 22.09.2020 14:57 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Thank you very much! I could not get the links to work in the extended commands help, but was able to view them in the browser.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 07.10.2020 05:05 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Can someone tell me how I can determine previous turns earnings and costs?

So far I believe I would have to loop through all the region.getMessages() to gather earnings from trade, taxation and entertainment. I would then have to do the same for trade, building maintenance, and expensive skills.

Is there an easier way to gather this information? I haven't found anything in the helper, region, or unit classes, but I am very new to javascript.

Also, is there any class that gives turn/round number?

Thanks!


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 12.10.2020 23:06 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
I am not sure if there is a built in class/method to get previous turn earnings and costs, but I was able to get this by going though region.getMessages() and faction.getMessages()

Still trying to find a way to get the current turn/round number. Haven't figured that one out yet. I thought it would be in world.getDate() but it doesn't appear to be in there.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 14.10.2020 00:33 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 396
Wohnort: Karlsruhe
You mean the total earnings of a faction? There is no simple way to get this.

I believe world.getDate().getDate() should get what you want.

_________________
Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 15.10.2020 13:56 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Zitat:
You mean the total earnings of a faction? There is no simple way to get this.

I was able to get this information by looping through messages and grabbing the appropriate IDs.

Zitat:
world.getDate().getDate()

I tried everything, but getDate() 2 times. Now looking at the docs I understand why it wasn't working. Thank you!

If you feel like answering another question :D how do I access regions by coords?

I know its going to be in world.getRegion(CoordinateID), but I can't figure out how to create() a new Coordinate ID with the correct (x,y) or (x,y,z). Everything I try in CoordinateID returns a magellan/library/CoordinateID$Triplet error. I am probably trying to access it incorrectly.

Code:
CoordinateID test1 = region.getCoordinate();
Region test2 = world.getRegion(test1);
addMessage(unit, test2);

This works fine, so I just need to understand how to access and/or create CoordinateID.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 16.10.2020 21:51 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 396
Wohnort: Karlsruhe
Not sure how you would have encountered the Triplet thing, but CoordinateID.create(x,y) or CoordinateID.create(x,y,z) if you need the astral plane, is what you want.

_________________
Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 18.10.2020 15:08 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
Strange, when I do CoordinateID.create(0,0) it works now. No idea what I was doing wrong before.
UPDATE: I was just able to reprodude the Triplet error. After I get errors trying other changes I then start getting the triplet error. After a restart of Magellan it stops producing the triplet error. No idea why, but a quick restart fixes it.

Of course I do have another question...

I am trying to call a method that is a variable.
Code:
import magellan.library.*;
import magellan.library.rules.*;

test(Unit unit, int a) {
   helper.addOrder(unit, "Success " + a);
}

I have found that I will need to either use:
1. eval() which is supposed to be a bad way to do it from what I read
2. window["name"]
Code:
String str = "test";
int a = 1;
window[str](unit, a);
eval("var cmd = " + str); cmd(unit, a);

I have been unsuccessful in either approach getting different errors, but both return a encountered ( at line 1 error with code above. I am wondering if I am in a different namespace then window.

I just ran into another question. Is there a way to access the building maintenance cost via region.buildings()? When I access an individual building I can get name, size, type, and such, but getCost() returns 0. I was able to do this creating a List and looking up the type, but was just curious if there was a way to grab the information directly.

Thanks again for all your help :D


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 20.10.2020 15:05 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 396
Wohnort: Karlsruhe
I still have no idea what causes that "triplet" error and I'm frankly not sure if I want to. ;)

bonzai911 hat geschrieben:
I am trying to call a method that is a variable. [...]
Code:
String str = "test";
int a = 1;
window[str](unit, a);
eval("var cmd = " + str); cmd(unit, a);


None of this is valid Java code. It looks like you might be trying to use Javascript. This will not work. Java and Javascript have similarities, but are two completely different things.

It's hard to give you any advice, because I don't know what you are actually trying to achieve. You can't pass methods as parameters in Java. The closest thing is using functional interfaces. Something along these lines:
Code:
interface Doer {
  public void do(Unit u, int a);
}
...
class MyAdder implements Doer {
  public void do(Unit u, int a) {
    {
        helper.addOrder(unit, "Success " + a);
    }
}
...
  public void doThingsWithDoer(Doer doer) {
     ...
     Unit unit = ...
     doer.do(unit, 5);
  }
... 
  public void variableCallerOfDoThings() {
    ...
    doThingsWithDoer(new MyAdder());
  }

There is also a way to write this more elegantly using lambda expressions. If you'd like to fall into that rabbit hole, try looking that up.


Building.getCost() ist not used any more. A long time ago, the server provided a cost for every building, but nowadays it's done via building types, so you have to access
getBuildingType().getMaintenanceItems() or possibly getMaintenance(EresseaConstants.I_USILVER).

_________________
Bild

--> Fehlermeldungen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 20.10.2020 21:54 
Offline
Frischling
Frischling

Registriert: 05.07.2020 14:21
Beiträge: 17
I am writing this before I have tried your suggestion as I won't be at my computer for awhile and wanted to explain what I am trying to do in case I am going down the wrong path :shock:
Zitat:
None of this is valid Java code. It looks like you might be trying to use Javascript. This will not work. Java and Javascript have similarities, but are two completely different things.
Haha, I've never used java or javascript before a few weeks ago when I decided to try and use extended commands and everything I have learned is from you and google :? Not sure I can tell the difference in them. I have self taught myself pieces of many different languages over the years. I know a little about lots of different languages, but I am a Master of none of them :lol: I have been able to write 1700 lines of java so far in this project. :D

Zitat:
It's hard to give you any advice, because I don't know what you are actually trying to achieve. You can't pass methods as parameters in Java. The closest thing is using functional interfaces. Something along these lines:
Basically I have multiple methods I want to call that are stored in a List. I am doing this as I want them to run in a certain order. I can write the code to check for the name of the method and then call it, but I would need to add one for every method. I just thought if I could call the method name with a variable I would only need to write the code once for any number of methods.

For instance: (Code not tested, just quickly wrote)
Code:
List myList = new ArrayList();
myList.add(new String[] { "test", "something", "more something" });
myList.add(new String[] { "learn", "something", "more something" });
for (i=0; i<myList.size(); i++) {
  String cmd = myList.get(i)[0]; //this would be the method that I want to run
  String arg1 = my list.get(i)[1]; //this would be an argument
  String arg2 = my list.get(i)[2]; //this would be an argument
  cmd(arg1, arg2); // This is what I want to run
}
Some methods have more args. I could make all methods the same number of arguments easily.
String cmd could be any number of different methods

It looks like I will need to put all the methods in a class and use an interface or something of the sort.

Hopefully that makes sense :?

I am still calling them methods only until I figure the correct way to do it :lol:

Zitat:
Building.getCost() ist not used any more. A long time ago, the server provided a cost for every building, but nowadays it's done via building types, so you have to access
getBuildingType().getMaintenanceItems() or possibly getMaintenance(EresseaConstants.I_USILVER).
I just played with this a little and I can get it to return "silver", but haven't been able to find the silver amount yet. I'll keep playing with it when I have time.
UPDATE: I got this working after a little trial and error.
While looping through all the buildings in the region I run:
Code:
int VARmaintAmount = 0;
if (helper.getBuilding(VARbldgID).getOwnerUnit().getFaction().getID().equals(world.getOwnerFaction())) {
  for (Item item : DICTbuildings.get(i).getBuildingType().getMaintenanceItems()) {
    if (item.getName().equals("silver")) {
      VARmaintAmount = item.getAmount();
    }
  }
}
Not sure if it can be done an easier way, but this returns the silver maint on a building.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: ExtendedCommands für Anfänger
BeitragVerfasst: 21.10.2020 13:19 
Offline
Forumheld
Forumheld
Benutzeravatar

Registriert: 08.02.2005 16:41
Beiträge: 396
Wohnort: Karlsruhe
bonzai911 hat geschrieben:
Not sure if it can be done an easier way, but this returns the silver maint on a building.

That seems about right. getBuildingType.getMaintenance((EresseaConstants.I_USILVER).getAmount is a little more concise.


This could be a way to approach it:

Code:
interface Interpreter {
   public void accept(String [] parameters);
}

class TestInterpreter implements Interpreter {
  public void accept(String[] parameters) {
     // do stuff
  }
}

...

Map<String, Interpreter> interpreters = new HashMap<String, Interpreter>();
interpreters.put("test", new TestInterpreter());
interpreters.put("improvise", new Interpreter() {
  public void accept(String [] parameters) {
      // do other stuff
  }
}
interpreters.put("lambdaexpression", (parameters) -> {
 // do cool stuff
}
);

...

interpreters.get("test").accept(new String[] {"something", "other"});


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 33 Beiträge ]  Gehe zu Seite 1, 2, 3  Nächste

Alle Zeiten sind UTC + 1 Stunde


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 63 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
Webhosting by sunrise design ohg