Thread Rating:
  • 6 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API Knowledgebase Questionthread
Author Message
PEEU Offline
Junior Member
**

Posts: 35
Joined: Feb 2012
Post: #21
RE: API Knowledgebase Questionthread
Hi,
I want to calculate distance between bases but for far bases I can not get X,Y information.

Code:
var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
ownCity.get_X();

var curCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
curCity.get_X();
This code returns X coordinate but only for close bases. Can you allow to get this information for any base on the map?
13-10-2012 07:43 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #22
RE: API Knowledgebase Questionthread
(13-10-2012 07:43 PM)PEEU Wrote:  Hi,
I want to calculate distance between bases but for far bases I can not get X,Y information.

Code:
var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
ownCity.get_X();

var curCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
curCity.get_X();
This code returns X coordinate but only for close bases. Can you allow to get this information for any base on the map?

Hi the problem is that the current city is normally set when clicking on it on the region map. But i think there is a range limit if the real Data.City gets send down or not.

So if you want calculate the Distance between your CurrentOwnCity and a region city use the Vis.Region.RegionCity instead.

try:
Code:
var visObject = ClientLib.Vis.VisMain.GetInstance().get_SelectedObject();
if (visObject != null && visObject.get_VisObjectType() == ClientLib.Vis.VisObject.EObjectType.RegionCityType)
{
   var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
    var pixelX = visObject.get_X();
    var pixelY = visObject.get_Y();
    var coordX = visObject.get_RawX();
    var coordY = visObject.get_RawY();

    var distance = ClientLib.Base.Util.CalculateDistance(city.get_X(), city.get_Y(), coordX, coordY);
}
14-10-2012 11:24 AM
 Search   Quote 
PEEU Offline
Junior Member
**

Posts: 35
Joined: Feb 2012
Post: #23
RE: API Knowledgebase Questionthread
Thank you Topper42.

That is great!!
var visObject = ClientLib.Vis.VisMain.GetInstance().get_SelectedObject();

That is what I was looking for.

I will filter some objects throught
ClientLib.Vis.VisObject.EObjectType.XXXXXXXX

THX very much.
14-10-2012 11:09 PM
 Search   Quote 
PEEU Offline
Junior Member
**

Posts: 35
Joined: Feb 2012
Post: #24
RE: API Knowledgebase Questionthread
Hi,
...Continuation

How to rise event when selected object has changed?

ClientLib.Vis.VisMain.GetInstance().add_SelectionChange ??

If it is right function how to implement it?

The second question is how can I implement

OnRightButtonClicked

var visObject = ClientLib.Vis.VisMain.GetInstance().get_SelectedObject();
visObject.OnRightButtonClicked()


THX
(This post was last modified: 15-10-2012 10:33 PM by PEEU.)
15-10-2012 09:23 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #25
RE: API Knowledgebase Questionthread
(15-10-2012 09:23 PM)PEEU Wrote:  Hi,
...Continuation

How to rise event when selected object has changed?

ClientLib.Vis.VisMain.GetInstance().add_SelectionChange ??

If it is right function how to implement it?

This ist already answered in the Api Knowledgebase Issue 3:
http://forum.alliances.commandandconquer...?tid=14134

(15-10-2012 09:23 PM)PEEU Wrote:  The second question is how can I implement

OnRightButtonClicked

var visObject = ClientLib.Vis.VisMain.GetInstance().get_SelectedObject();
visObject.OnRightButtonClicked()


THX

Why do you want to implement that function? As far as i know this is never used in the game, because right click is normally not well supported by browsers.
(This post was last modified: 16-10-2012 10:46 AM by Topper42.)
16-10-2012 10:46 AM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #26
RE: API Knowledgebase Questionthread
When will the new API be launched?
22-10-2012 07:14 PM
 Search   Quote 
PEEU Offline
Junior Member
**

Posts: 35
Joined: Feb 2012
Post: #27
RE: API Knowledgebase Questionthread
OK,

I implemented Distance.

One week ago I have found useful API to get Buildings,Defs,Offs lists.
Code:
get_Buildings
get_DefenseUnits
get_OffenseUnits

city= ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
cb= city.get_CityBuildingsData().get_Buildings();
cd= city.get_CityUnitsData().get_DefenseUnits();
co= city.get_CityUnitsData().get_OffenseUnits();

I switched off my autodeobfuscator, and you just removed these functions:
get_Buildings
get_DefenseUnits
get_OffenseUnits

???????????????????
I was happy that you gave me API for my script...
Now you made me sad Sad

Is it possible to bring it back?

Take a look to compare your proposition with code before:
BEFORE:
Code:
cbl= city.get_CityBuildingsData().get_Buildings().l;
console.log('All buildings',cbl,cbl.length);

NOW:
Code:
cbl=[];
for(k in ClientLib.Base.ETechName) {
  bl = city.get_CityBuildingsData().GetAllBuildingsByTechName(ClientLib.Base.ETechName[k]).l;
  if(bl.length>0) {
    for(m in bl) cbl.push(bl[m]);
  }
}
console.log('All buildings',cbl,cbl.length);

OR:
Code:
cbl= city.get_CityBuildingsData()[b.keys.Buildings].l;
console.log('All buildings',cbl,cbl.length);

And as you analize your GetAllBuildingsByTechName you will see that that function uses city building list !!! and check it all.
That means it takes lots of more calculations to bring units/buildings list back.

Is it possible to bring those functions back?
It would be very kind.

Regards
PEEU

EDIT:
I see it is not list now. But any way it could return object of buildings/units.
Code:
cbd= city.get_CityBuildingsData()[b.keys.Buildings].d;
console.log('All buildings',cbd,Object.keys(cbd).length);
(This post was last modified: 24-10-2012 11:00 AM by PEEU.)
23-10-2012 12:13 PM
 Search   Quote 
hades8840 Offline
Junior Member
**

Posts: 21
Joined: Dec 2011
Post: #28
RE: API Knowledgebase Questionthread
none of the scripts seem to be working on closed beta1 now are the authors still even active as nothing on userscripts from them
23-10-2012 05:56 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #29
RE: API Knowledgebase Questionthread
@Topper,

On regular worlds webfrontend.gui.PlayArea.PlayArea.modes from combat reply window gives me an object with all the EModes, which lets me return to the EMode_CombatSetupDefense.

Currently on beta worlds I only see the EMode_CombatReplay.
This removes my ability to return from combat simulator window to setup window.

What is the reason for that?

If it's about to stay, is there a way around it?

Kind regards,
Deyhak.
24-10-2012 09:52 AM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #30
RE: API Knowledgebase Questionthread
(24-10-2012 09:52 AM)Deyhak Wrote:  @Topper,

On regular worlds webfrontend.gui.PlayArea.PlayArea.modes from combat reply window gives me an object with all the EModes, which lets me return to the EMode_CombatSetupDefense.

Currently on beta worlds I only see the EMode_CombatReplay.
This removes my ability to return from combat simulator window to setup window.

What is the reason for that?

If it's about to stay, is there a way around it?

Kind regards,
Deyhak.

Hi

it just changed its place to:
ClientLib.Data.PlayerAreaViewMode

pavmNone
pavmPlayerBase
pavmPlayerDefense
pavmPlayerOffense
pavmCombatSetupBase
pavmCombatSetupDefense
pavmCombatAttacker
pavmCombatDefender
pavmCombatViewerAttacker
pavmCombatViewerDefender
pavmCombatReplay
pavmCombatSimulation
pavmWorldMap


The old enum is just there for our published simulation code.
24-10-2012 04:05 PM
 Search   Quote 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)