View Javadoc

1   // Object used by cengine
2   //  Generated by LIBERO 2.30 on 31 Jul, 2001, 14:37.
3   //  Schema file used: lrschema.jav.
4   
5   package spellcast.client;
6   
7   abstract public class cenginei {
8       //- Variables used by dialog interpreter --------------------------------
9   
10      private static int _LR_event, //  Event for state transition
11              _LR_state, //  Current dialog state
12              _LR_savest, //  Saved dialog state
13              _LR_index; //  Index of methods function
14  
15      public static int the_next_event, //  Next event from module
16              the_exception_event; //  Exception event from module
17  
18      private static boolean exception_raised; //  TRUE if exception raised
19  
20      //- Symbolic constants and event numbers --------------------------------
21  
22      private static int _LR_STOP = 0xFFFF, _LR_NULL_EVENT = -2;
23  
24      public static int _LR_STATE_after_init = 0, _LR_STATE_not_connected = 1,
25              _LR_STATE_connected = 2, _LR_STATE_defaults = 3,
26              _LR_defaults_state = 3, connect_event = 0, disconnect_event = 1,
27              game_sync_event = 2, game_update_event = 3, io_error_event = 4,
28              message_event = 5, ok_event = 6, stop_event = 7, unknown_event = 8,
29              terminate_event = -1;
30  
31      //- Static areas --------------------------------------------------------
32  
33      private static int _LR_nextst[][] = { { 0, 0, 0, 0, 0, 0, 1, 0, 0 },
34              { 2, 0, 0, 0, 0, 0, 0, 0, 0 }, { 2, 2, 2, 2, 1, 0, 0, 1, 0 },
35              { 0, 0, 0, 0, 0, 3, 0, 0, 3 } };
36  
37      private static int _LR_action[][] = { { 0, 0, 0, 0, 0, 0, 1, 0, 0 },
38              { 2, 0, 0, 0, 0, 0, 0, 0, 0 }, { 4, 5, 6, 3, 7, 0, 0, 1, 0 },
39              { 0, 0, 0, 0, 0, 8, 0, 0, 9 } };
40  
41      private static int _LR_vector[][] = { { 0 }, { _LR_STOP }, { 1, _LR_STOP },
42              { 7, _LR_STOP }, { 0, _LR_STOP }, { 5, _LR_STOP }, { 6, _LR_STOP },
43              { 3, _LR_STOP }, { 2, _LR_STOP }, { 4, _LR_STOP } };
44  
45      private static String _LR_mname[] = { "Add-Connection",
46              "Connect-This-Client", "Display-Message", "Handle-Io-Error",
47              "Handle-Unknown-Event", "Remove-Connection", "Sync-Game",
48              "Update-Game" };
49  
50      private static String _LR_sname[] = { "After-Init", "Not-Connected",
51              "Connected", "Defaults" };
52  
53      private static String _LR_ename[] = { "Connect-Event", "Disconnect-Event",
54              "Game-Sync-Event", "Game-Update-Event", "Io-Error-Event",
55              "Message-Event", "Ok-Event", "Stop-Event", "Unknown-Event" };
56  
57      abstract public void initialise_the_program();
58  
59      abstract public void get_external_event();
60  
61      abstract public void add_connection();
62  
63      abstract public void connect_this_client();
64  
65      abstract public void display_message();
66  
67      abstract public void handle_io_error();
68  
69      abstract public void handle_unknown_event();
70  
71      abstract public void remove_connection();
72  
73      abstract public void sync_game();
74  
75      abstract public void update_game();
76  
77      //- Dialog interpreter starts here --------------------------------------
78  
79      public int execute() {
80          int feedback = 0, index, next_module;
81  
82          _LR_state = 0; //  First state is always zero
83          initialise_the_program();
84          while (the_next_event != terminate_event) {
85              _LR_event = the_next_event;
86              if (_LR_event >= 9 || _LR_event < 0) {
87                  String buffer;
88                  buffer = "State " + _LR_state + " - event " + _LR_event;
89                  buffer += " is out of range";
90                  System.out.println(buffer);
91                  break;
92              }
93              _LR_savest = _LR_state;
94              _LR_index = _LR_action[_LR_state][_LR_event];
95              //  If no action for this event, try the defaults state
96              if (_LR_index == 0) {
97                  _LR_state = _LR_defaults_state;
98                  _LR_index = _LR_action[_LR_state][_LR_event];
99              }
100             System.out.println(_LR_sname[_LR_state] + ':');
101             System.out.println("    (--) " + _LR_ename[_LR_event]);
102             if (_LR_index == 0) {
103                 String buffer;
104                 buffer = "State " + _LR_state + " - event " + _LR_event;
105                 buffer += " is not accepted";
106                 System.out.println(buffer);
107                 break;
108             }
109             the_next_event = _LR_NULL_EVENT;
110             the_exception_event = _LR_NULL_EVENT;
111             exception_raised = false;
112             next_module = 0;
113 
114             for (;;) {
115                 index = _LR_vector[_LR_index][next_module];
116                 if ((index == _LR_STOP) || (exception_raised))
117                     break;
118                 System.out.println("          + " + _LR_mname[index]);
119                 switch (index) {
120                 case 0:
121                     add_connection();
122                     break;
123                 case 1:
124                     connect_this_client();
125                     break;
126                 case 2:
127                     display_message();
128                     break;
129                 case 3:
130                     handle_io_error();
131                     break;
132                 case 4:
133                     handle_unknown_event();
134                     break;
135                 case 5:
136                     remove_connection();
137                     break;
138                 case 6:
139                     sync_game();
140                     break;
141                 case 7:
142                     update_game();
143                     break;
144                 }
145                 next_module++;
146             }
147             if (exception_raised) {
148                 if (the_exception_event != _LR_NULL_EVENT)
149                     _LR_event = the_exception_event;
150                 the_next_event = _LR_event;
151                 System.out.println("    (=>) " + _LR_ename[_LR_event]);
152             } else
153                 _LR_state = _LR_nextst[_LR_state][_LR_event];
154 
155             if (_LR_state == _LR_defaults_state)
156                 _LR_state = _LR_savest;
157             if (the_next_event == _LR_NULL_EVENT) {
158                 get_external_event();
159                 if (the_next_event == _LR_NULL_EVENT) {
160                     String buffer;
161                     buffer = "No event set after event " + _LR_event;
162                     buffer += " in state " + _LR_state;
163                     System.out.println(buffer);
164                     break;
165                 }
166             }
167         }
168         return (feedback);
169     }
170 
171     //- Standard dialog routines --------------------------------------------
172     public void raise_exception(int event) {
173         exception_raised = true;
174         if (event >= 0)
175             the_exception_event = event;
176     }
177 
178 }