1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Structure of a client/server game, based on turns, events, orders and rules
16 module framework
is serialize
21 # Main game object containing the world, players and tanks
23 # The game object is shared by both the client and the server.
24 # So a method using the game object as visitor is to be executed client-side.
27 # `Story`, or rule book, with all the stats for this game
30 # `Clock` timing the elapsed time between turns
31 private var clock
= new Clock is noserialize
33 # Tick count of the last turn (The first turn as a tick of 0)
36 # Execute the next turn and return it as a `TTurn`
38 # This is to be executed server-side only.
44 var turn
= new TTurn(self, tick
, dt
, ((dt-dt
.floor
)*1000.0).to_i
)
48 # Apply `turn` locally by updating `tick` and applying all events
50 # This is to be executed client-side only.
51 fun apply_turn
(turn
: TTurn)
54 for event
in turn
.events
do event
.apply
self
58 # A single turn of a `TGame`
60 # The turn object is created and populated by the server (using `TGame::do_turn`).
61 # It is transmitted to the client but it cannot modify it.
62 # So methods using the turn object as visitor are to be executed server-side.
65 # `TGame` of which `self` is part of
71 # Elapsed seconds since previous turn (as a `Float`)
74 # Elapsed milliseconds since previous turn (as a `Int`)
77 # `TEvent` that happened during this turn
79 # Events are added using `add`.
80 # This information is used to apply the turn client-side to update its game object.
81 # It is also used by effects on the UI and could be used by an AI.
82 var events
: SequenceRead[TEvent] = new Array[TEvent]
84 # Add an `event` to `events` and apply it right away server-side
85 fun add
(event
: TEvent)
88 events
.as(Array[TEvent]).add event
92 # Game event sent from the server to the client
95 # Executed client-side to apply this event on the `game`
96 fun apply
(game
: TGame) do end
99 # An order sent from the client to the server
102 # Apply order server-side on `turn`, usually spawns `GameEvent`
103 fun apply
(turn
: TTurn) do end
106 # An entity acting on each turn
110 fun do_turn
(turn
: TTurn) do end
113 # A collection of `Rule` guiding the game
115 # Changing the story could (in theory) be enough to completely change the context of the game.
116 # In _Tinks!_ however, we use this class lightly and fill it with static content.
120 # Metadata of in game `Ruled` entities, keep their stats and assets in a single place
123 # `Story` to which `self` belongs
127 # A game entity with metadata in its `rule`
130 # Kind of `Rule` for `rule`
133 # Metadata of this entity
137 # Should the game show more information for debugging?
138 fun debug
: Bool do return false