The online racing simulator
#1 - w126
Receiving IS_NPL/IS_PLL when playing SPR possible?
I'm trying to detect a car model of the currently viewed car in a single player replay. I am able to get the state changes with id of the viewed player. However, the only way of mapping this id to a car model (that I know of) is through the data received earlier in IS_NPL packets (new player joining). These packets don't seem to reflect what is happening in a SPR being played, I only get them during an actual race.
Request them with TINY
#3 - w126
I am requesting them once at the beginning and it seems to work except in SPRs (I haven't checked MPRs yet).
Should I request them at other times/events?

Here is my current code (using JInSim):

public class MyInSimTest implements InSimListener {

static String hostname;
static int port;
static String adminPassword;

SimpleClient client;

private String track;
private String layout;
private String camera;
private short flags;
private float replaySpeed;
private int viewedPlayerId;
private int raceInProgress;
private Map<Integer, Car> playerCars = new HashMap<>();
private Map<Integer, Byte> playerPassengers = new HashMap<>();

public static void main(String[] args) {
new MyInSimTest(args);
}

public MyInSimTest(String[] args) {
hostname = args[0];
port = Integer.parseInt(args[1]);
if (args.length > 2) {
adminPassword = args[2];
}

client = new SimpleClient();
try {
client.connect(new TCPChannel(hostname, port), adminPassword, "MyInSimTest",
(short)(InitRequest.LOCAL | InitRequest.RECEIVE_MULTI_CAR_INFO | 512),
1000, 0);
// #define ISF_AXM_LOAD 512 // bit 9 : receive AXM when loading a layout
client.send(new TinyRequest(Tiny.SEND_STATE_INFO));
client.send(new TinyRequest(Tiny.AUTOCROSS_LAYOUT));
client.send(new TinyRequest(Tiny.ALL_PLAYERS));
} catch (IOException e) {
e.printStackTrace();
}
client.addListener(this);
}

@Override
public void packetReceived(InSimResponse response) {
if (response instanceof StateResponse) {
StateResponse stateResponse = (StateResponse) response;
String curTrack = stateResponse.getTrack().getShortname();
if (! curTrack.equals(track)) {
System.out.println("Track changed: " + track + " --> " + curTrack);
track = curTrack;
try {
client.send(new TinyRequest(Tiny.AUTOCROSS_LAYOUT));
} catch (IOException e) {
e.printStackTrace();
}
}
String curCamera = stateResponse.getCameraString();
if (! curCamera.equals(camera)) {
System.out.println("Camera changed: " + camera + " --> " + curCamera);
camera = curCamera;
}
short curFlags = stateResponse.getFlags();
if (curFlags != flags) {
Integer.toBinaryString(flags);
System.out.println(
"Flags changed: " + toFlagsString(flags) + " -->\n" +
" " + toFlagsString(curFlags));
flags = curFlags;
}
float curReplaySpeed = stateResponse.getReplaySpeed();
if (curReplaySpeed != replaySpeed) {
System.out.println("Replay speed changed: " + replaySpeed + " --> " + curReplaySpeed);
replaySpeed = curReplaySpeed;
}
int curViewedPlayerId = stateResponse.getPlayer();
if (curViewedPlayerId != viewedPlayerId) {
System.out.println("Viewed player id changed: " + viewedPlayerId + " --> " + curViewedPlayerId);
viewedPlayerId = curViewedPlayerId;
System.out.println("Current car: " + playerCars.get(viewedPlayerId));
System.out.println("Current passengers byte: " + playerPassengers.get(viewedPlayerId));
}
int curRaceInProgress = stateResponse.getRaceInProgress();
if (curRaceInProgress != raceInProgress) {
System.out.println("Race in progress changed: " + raceInProgress + " --> " + curRaceInProgress);
raceInProgress = curRaceInProgress;
}
}
if (response instanceof AutocrossLayoutResponse) {
AutocrossLayoutResponse layoutResponse = (AutocrossLayoutResponse) response;
String curLayout = layoutResponse.getName();
if (! curLayout.equals(layout)) {
System.out.println("Layout changed: " + layout + " --> " + curLayout);
layout = curLayout;
}
}
if (response instanceof NewPlayerResponse) {
NewPlayerResponse newPlayerResponse = (NewPlayerResponse) response;
int playerId = newPlayerResponse.getPlayerId();
playerCars.put(playerId, newPlayerResponse.getCar());
playerPassengers.put(playerId, (byte) newPlayerResponse.getPassengers());
System.out.println("New player: " + playerId);
}
if (response instanceof PlayerLeavingResponse) {
PlayerLeavingResponse playerLeavingResponse = (PlayerLeavingResponse) response;
int playerId = playerLeavingResponse.getPlayerId();
playerCars.remove(playerId);
playerPassengers.remove(playerId);
System.out.println("Player leaving: " + playerId);
}
}

private static String[] flagsMeaning = { "gam", "spr", "pau", "shu", "suh", "suf", "sun",
"s2d", "fre", "mul", "msu", "win", "mut", "vor", "ibv"};

public static String toFlagsString(short flags) {
StringBuilder result = new StringBuilder();
int powerOf2 = 1;
for (String meaning : flagsMeaning) {
if ((flags & powerOf2) != 0)
result.append(meaning);
else
result.append("---");
result.append(" ");
powerOf2 *= 2;
}
return result.toString();
}

}

In my program I request them on IS_RST and it seems to work fine.
#5 - w126
Thanks a lot. Much better now. Smile

Receiving IS_NPL/IS_PLL when playing SPR possible?
(5 posts, started )
FGED GREDG RDFGDR GSFDG