]> icculus.org git repositories - btb/d2x.git/blob - main/editor/kgame.c
remove rcs tags
[btb/d2x.git] / main / editor / kgame.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Game Loading editor functions
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "conf.h"
22 #endif
23
24 #include <string.h>
25 #include <stdio.h>
26
27 #include "inferno.h"
28 #include "editor.h"
29 #include "ui.h"
30 #include "game.h"
31 #include "gamesave.h"
32 #include "gameseq.h"
33
34 char game_filename[PATH_MAX] = "*.RL2";
35
36 extern void checkforext( char * f, char *ext );
37
38 void checkforgamext( char * f )
39 {
40         int i;
41
42         for (i=1; i<strlen(f); i++ )
43         {
44                 if (f[i]=='.') return;
45
46                 if ((f[i]==' '||f[i]==0) )
47                 {
48                         f[i]='.';
49                         f[i+1]='L';
50                         f[i+2]= 'V';
51                         f[i+3]= 'L';
52                         f[i+4]=0;
53                         return;
54                 }
55         }
56
57         if (i < 123)
58         {
59                 f[i]='.';
60                 f[i+1]='L';
61                 f[i+2]= 'V';
62                 f[i+3]= 'L';
63                 f[i+4]=0;
64                 return;
65         }
66 }
67
68 //these variables store the "permanant" player position, which overrides
69 //whatever the player's position happens to be when the game is saved
70 int Perm_player_segnum=-1;              //-1 means position not set
71 vms_vector Perm_player_position;
72 vms_matrix Perm_player_orient;
73
74 //set the player's "permanant" position from the current position
75 int SetPlayerPosition()
76 {
77         Perm_player_position = ConsoleObject->pos;
78         Perm_player_orient = ConsoleObject->orient;
79         Perm_player_segnum = ConsoleObject->segnum;
80
81         editor_status("Player initial position set");
82         return 0;
83 }
84
85 // Save game
86 // returns 1 if successful
87 //      returns 0 if unsuccessful
88 int SaveGameData()
89 {
90         char Message[200];
91
92         if (gamestate_not_restored) {
93                 sprintf( Message, "Game State has not been restored...\nContinue?\n");
94                 if (MessageBox( -2, -2, 2, Message, "NO", "Yes" )==1) 
95                         return 0;
96                 }
97                 
98    if (ui_get_filename( game_filename, "*.RL2", "SAVE GAME" )) {
99                 int saved_flag;
100                 vms_vector save_pos = ConsoleObject->pos;
101                 vms_matrix save_orient = ConsoleObject->orient;
102                 int save_segnum = ConsoleObject->segnum;
103
104       checkforgamext(game_filename);
105
106                 if (Perm_player_segnum > Highest_segment_index)
107                         Perm_player_segnum = -1;
108
109                 if (Perm_player_segnum!=-1) {
110                         if (get_seg_masks(&Perm_player_position, Perm_player_segnum, 0, __FILE__, __LINE__).centermask == 0)
111                         {
112                                 ConsoleObject->pos = Perm_player_position;
113                                 obj_relink(OBJECT_NUMBER(ConsoleObject), Perm_player_segnum);
114                                 ConsoleObject->orient = Perm_player_orient;
115                         }
116                         else
117                                 Perm_player_segnum=-1;          //position was bogus
118                 }
119       saved_flag=save_level(game_filename);
120                 if (Perm_player_segnum!=-1) {
121                         int     found_save_segnum;
122
123                         if (save_segnum > Highest_segment_index)
124                                 save_segnum = 0;
125
126                         ConsoleObject->pos = save_pos;
127                         found_save_segnum = find_point_seg(&save_pos,save_segnum);
128                         if (found_save_segnum == -1) {
129                                 compute_segment_center(&save_pos, &(Segments[save_segnum]));
130                                 found_save_segnum = save_segnum;
131                         }
132
133                         obj_relink(OBJECT_NUMBER(ConsoleObject), found_save_segnum);
134                         ConsoleObject->orient = save_orient;
135                 }
136                 if (saved_flag)
137                         return 0;
138                 mine_changed = 0;
139         }
140         return 1;
141 }
142
143 // returns 1 if successful
144 //      returns 0 if unsuccessful
145 int LoadGameData()
146 {
147 if (SafetyCheck())  {
148         if (ui_get_filename( game_filename, "*.RL2", "LOAD GAME" ))
149                 {
150                 checkforgamext(game_filename);
151                 if (load_level(game_filename))
152                         return 0;
153                 Current_level_num = 0;                  //not a real level
154                 gamestate_not_restored = 0;
155                 Update_flags = UF_WORLD_CHANGED;
156                 Perm_player_position = ConsoleObject->pos;
157                 Perm_player_orient = ConsoleObject->orient;
158                 Perm_player_segnum = ConsoleObject->segnum;
159                 }
160         }
161         return 1;
162 }
163
164 //called whenever a new mine is created, so new mine doesn't get name
165 //of last saved mine as default
166 void ResetFilename()
167 {
168         strcpy(game_filename,"*.LVL");
169 }
170