{$MODE OBJFPC} { -*- delphi -*- } {$INCLUDE settings.inc} unit shipbits; interface uses storable, rpc, callbacks, actors, facilities; type TThrusterMode = (tmOff, tmFiring); TThrusters = class(TFacility) // @RegisterFacilityClass protected FThrusterMode: TThrusterMode; procedure HandleThrusterControl(var Message: TMessage); message 'thruster-control'; class function GetHasPhysicalProperty(): Boolean; override; public constructor Read(Stream: TReadStream); override; procedure Write(Stream: TWriteStream); override; procedure UpdatePhysicalProperties(Target: PPhysicalProperties); override; published procedure Navigate(var Arguments: TNavigationArguments); // @RegisterMethod property ThrusterMode: TThrusterMode read FThrusterMode; end; implementation uses exceptions, methodregistry, gravity; constructor TThrusters.Read(Stream: TReadStream); begin inherited; FThrusterMode := TThrusterMode(Stream.ReadCardinal()); end; procedure TThrusters.Write(Stream: TWriteStream); begin inherited; Stream.WriteCardinal(Cardinal(FThrusterMode)); end; class function TThrusters.GetHasPhysicalProperty(): Boolean; begin Result := True; end; procedure TThrusters.UpdatePhysicalProperties(Target: PPhysicalProperties); begin XXX; end; procedure TThrusters.HandleThrusterControl(var Message: TMessage); var Mode: TThrusterMode; ModeString: UTF8String; ConversionResult: Integer; Ancestor, Penultimate: TAbstractTreeNode; begin // XXX check ownership ModeString := Message.Stream.ReadString(); Val(ModeString, Mode, ConversionResult); if ((ConversionResult = 0) and (Message.Stream.ReadEnd())) then begin if (((Mode = tmOff) or (Mode = tmFiring)) and (Mode <> FThrusterMode)) then begin Message.Reply(True).Close(); FThrusterMode := Mode; if ((Mode = tmFiring) and FindAncestor(TGravitationalSystem, Ancestor, Penultimate)) then begin Assert(Self is TFacility); Assert(Penultimate is TChildActor); Assert(Ancestor is TGravitationalSystem); if (Penultimate <> Parent) then begin (Ancestor as TGravitationalSystem).Launch(Parent as TChildActor, Penultimate as TChildActor, Random() * 2.0 * Pi); end; end; MarkDirty([dfNeedNotifications, dfNeedSave, dfPhysicalPropertiesChanged]); end else begin Message.Reply(False).Close(); end; end; end; procedure TThrusters.Navigate(var Arguments: TNavigationArguments); begin XXX end; initialization {$INCLUDE registrations/shipbits.inc} end.