I have been having "fun" rescripting the boat.src and have encountered a strange thing. After a world wrap there is about a 2 minute delay before the boat continues on it's course. Now I have looked and just can't find out where this delay is introduced. There are no items in the hold and my Admin character is the only mobile on the boat. So I'm pretty sure the delay isn't from object moves.
This delay exists in the "virgin" POL 95 boat.src script as well as my modified one.
ANy help would be appreciated.
Thanks.
Boats and world wrap
OK did a test and it seems that a speech event of any kind, whether recognized by the tillerman or not, stops the delay.
[Edit] Found the problem. It's in the stationary state handler. There's a ev := wait_for_event(120) line.
Now maybe someone could tell me if there would be a performance drop if I lowered that to maybe 30 instead of 120.
[Edit] Found the problem. It's in the stationary state handler. There's a ev := wait_for_event(120) line.
Now maybe someone could tell me if there would be a performance drop if I lowered that to maybe 30 instead of 120.
That's what I want it to do but either I'm dense or I just keep missing it.
The odd thing is that it does go back to moving on it's own but apparently, for some reason, it starts in stationary after a wrap. I think it has to do with the fact that the boat is being recreated and we start with a new boat. Ther variable "state" is still set to STATE_MOVING after the new boat is created but some how it drops into stationary and times out then starts back moving again.
I'm going to go back and look at it again.
BTW Maud, I am sailing the stars!!!
*grins*
The odd thing is that it does go back to moving on it's own but apparently, for some reason, it starts in stationary after a wrap. I think it has to do with the fact that the boat is being recreated and we start with a new boat. Ther variable "state" is still set to STATE_MOVING after the new boat is created but some how it drops into stationary and times out then starts back moving again.
I'm going to go back and look at it again.
BTW Maud, I am sailing the stars!!!
*grins*
OK Maud maybe you can see why it's happening.
Here is the main while loop from boat.src in POL 95 Distro:
Now here is Worldwrap function from same:
I placed a Broadcast ("State = " + state) command at the end of the function and the state is reported as being 1 (STATE_MOVING) but for some reason, upon leaving Worldwrap, the script gets locked into the STATE_STATIONARY switch for the case statement in the main loop. I know this is where it gets caught because I have changed the 120 in that statement to 15 and it only pauses for 15 seconds.
Here is the main while loop from boat.src in POL 95 Distro:
Code: Select all
while(boat)
if(GetObjProperty(boat.hold, "#speed"))
state := STATE_MOVING;
ms_delay_between_moves := GetObjProperty(boat.hold, "#speed");
relative_direction := GetObjProperty(boat.hold, "#relativedir");
eraseobjproperty(boat.hold, "#speed");
eraseobjproperty(boat.hold, "#relativedir");
endif
decay := getobjproperty(boat.tillerman,"decay");
if((decay) and(!getobjproperty(tillerman,"nodecay")))
if(ReadGameClock() > decay)
PrintTextAbove(tillerman, "Arrrrrgh! She's going down, Captain! Abandon ship!");
sleep(4);
foreach item in EnumerateItemsInContainer( boat.hold )
DestroyItem(item);
endforeach
foreach mob in(boat.items)
DestroyItem(mob);
endforeach
foreach mob in(boat.mobiles)
MoveCharacterToLocation(mob, 1487, 1869, 0, MOVECHAR_FORCELOCATION );
SendSysMessage(mob, "Your ship, badly in need of maintenance, sinks beneath the waves!");
SendSysMessage(mob, "You awake on a distant shore...");
endforeach
if(boat.has_offline_mobiles)
foreach mob in(boat.offline_mobiles)
MoveCharacterToLocation(mob, 1487, 1869, 0, MOVECHAR_FORCELOCATION );
endforeach
endif
DestroyMulti(boat);
endif
endif
case(state)
STATE_MOVING: if(ReadGameClock() > nextsound)
PlayBoatSounds();
nextsound := ReadGameClock()+5;
endif
x := boat.x;
y := boat.y;
MoveBoatRelative(boat, relative_direction);
if(boat.x == 6 or boat.x == 5097 or boat.y == 6 or boat.y == 4089)
WorldWrap();
endif
if((x == boat.x) &&(y == boat.y))
ms_delay_between_moves := 1000;
state := STATE_DRIFTING;
PrintTextAbove(tillerman, "Aaargh! We've run ashore!");
//SmackEveryone();
endif
sleepms(ms_delay_between_moves);
if(ReadGameClock() > nextencounter)
DoEncounter();
nextencounter := ReadGameClock()+120;
endif
while(events_waiting())
process_event(wait_for_event(0));
endwhile
STATE_DRIFTING: if(ReadGameClock() > nextsound)
PlayBoatSounds();
nextsound := ReadGameClock()+5;
endif
if(driftcounter > 15)
MoveBoatRelative(boat, RandomInt(8));
driftcounter := 1;
else
driftcounter := driftcounter + 1;
endif
sleepms(1000);
while(events_waiting())
process_event(wait_for_event(0));
endwhile
STATE_STATIONARY: var ev := wait_for_event(120);
if(ev)
process_event(ev);
endif
/*NOTE NEW BOAT STATE*/
STATE_FOLLOWING_COURSE:
x := boat.x;
y := boat.y;
BoatFollowCourse(boat);
sleepms(ms_delay_between_moves);
while(events_waiting())
process_event(wait_for_event(0));
endwhile
/*END NEW BOAT STATE*/
endcase
if(ReadGameClock() > nextencounter)
checkres();
nextencounter := ReadGameClock()+120;
endif
endwhile
endprogram
Code: Select all
function WorldWrap()
var newx := boat.x;
var newy := boat.y;
if(boat.y <= 6)
newy := 4088;
elseif(boat.y >= 4089)
newy := 6;
endif
if(boat.x <= 6)
newx := 5096;
elseif(boat.x >= 5097)
newx := 6;
endif
var lockid := GetObjProperty(boat.hold, "lockid");
var owner := GetObjProperty(boat.hold, "owner");
var shiptype := boat.objtype;
var shipfacing, created;
case(tillerman.graphic)
0x3e4e: shipfacing := CRMULTI_FACING_NORTH;
0x3e55: shipfacing := CRMULTI_FACING_EAST;
0x3e4b: shipfacing := CRMULTI_FACING_SOUTH;
0x3e50: shipfacing := CRMULTI_FACING_WEST;
default: shipfacing := "Error!";
endcase
if(shipfacing == "Error!")
syslog( "[ERROR] [boat.src] Couldn't tell which way the ship was facing for the worldwrap!");
endif
created := CreateMultiAtLocation( newx, newy, -5, shiptype, shipfacing);
if(!created)
syslog( "[ERROR] [boat.src] New ship couldn't be created for worldwrap!");
return;
endif
var oldshiphold := boat.hold;
var newshiphold := created.hold;
foreach item in EnumerateItemsInContainer( oldshiphold )
if(item.container == oldshiphold)
MoveItemToContainer(item, newshiphold);
endif
endforeach
foreach item in EnumerateItemsInContainer( oldshiphold )
MoveItemToContainer(item, newshiphold);
endforeach
foreach mob in(boat.mobiles)
MoveCharacterToLocation(mob,(mob.x-boat.x)+created.x,(mob.y-boat.y)+created.y, -2, MOVECHAR_FORCELOCATION );
endforeach
if(boat.has_offline_mobiles)
foreach mob in(boat.offline_mobiles)
MoveCharacterToLocation(mob,(mob.x-boat.x)+created.x,(mob.y-boat.y)+created.y, -2, MOVECHAR_FORCELOCATION );
endforeach
endif
foreach mob in(boat.items)
MoveitemToLocation(mob,(mob.x-boat.x)+created.x,(mob.y-boat.y)+created.y, -2,0 );
endforeach
var newtillerman := created.tillerman;
newtillerman.name := tillerman.name;
SetObjProperty( created.starboardplank, "lockid", lockid);
SetObjProperty( created.portplank, "lockid", lockid);
SetObjProperty( created.ship.starboardplank, "owner", owner );
SetObjProperty( created.ship.portplank, "owner", owner );
SetObjProperty( created.ship.starboardplank, "tillermanid", newtillerman.serial );
SetObjProperty( created.ship.portplank, "tillermanid", newtillerman.serial );
SetObjProperty( created.hold, "lockid", lockid);
SetObjProperty( created.hold, "owner", owner);
SetObjProperty( created.tillerman, "owner", owner);
SetObjProperty( created.tillerman, "shipserial", created.serial);
SetObjProperty( created.tillerman, "lockid", lockid);
SetObjProperty( created.tillerman, "decay", decay);
if(boat.starboardplank.locked == 1)
created.starboardplank.locked := 1;
endif
if(boat.portplank.locked == 1)
created.portplank.locked := 1;
endif
if(boat.hold.locked == 1)
created.hold.locked := 1;
endif
SetObjProperty( created.hold, "#relativedir", relative_direction);
SetObjProperty( created.hold, "#speed", ms_delay_between_moves);
created.tillerman.usescript := ":boat:tillerman";
if(!DestroyMulti(boat))
DestroyItem(boat.tillerman);
syslog( "[ERROR] [boat.src] Old ship at " +(boat.x-1) +","+ boat.y +","+ boat.z + " couldn't be destroyed during worldwrap!");
endif
endfunction
Not a core bug.. I wrote one tonight in the 097 distro and there were no delay issues at all when wrapped (take a look at it, pretty different from whats been done)
http://svn.sourceforge.net/viewvc/pol-d ... iew=markup
http://svn.sourceforge.net/viewvc/pol-d ... iew=markup