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