]> icculus.org git repositories - btb/d2x.git/blob - main/editor/kgame.c
use the orientation parameter of g3_draw_bitmap
[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
31
32 char game_filename[PATH_MAX] = "*.RL2";
33
34 extern void checkforext( char * f, char *ext );
35
36 void checkforgamext( char * f )
37 {
38         int i;
39
40         for (i=1; i<strlen(f); i++ )
41         {
42                 if (f[i]=='.') return;
43
44                 if ((f[i]==' '||f[i]==0) )
45                 {
46                         f[i]='.';
47                         f[i+1]='L';
48                         f[i+2]= 'V';
49                         f[i+3]= 'L';
50                         f[i+4]=0;
51                         return;
52                 }
53         }
54
55         if (i < 123)
56         {
57                 f[i]='.';
58                 f[i+1]='L';
59                 f[i+2]= 'V';
60                 f[i+3]= 'L';
61                 f[i+4]=0;
62                 return;
63         }
64 }
65
66 //these variables store the "permanant" player position, which overrides
67 //whatever the player's position happens to be when the game is saved
68 int Perm_player_segnum=-1;              //-1 means position not set
69 vms_vector Perm_player_position;
70 vms_matrix Perm_player_orient;
71
72 //set the player's "permanant" position from the current position
73 int SetPlayerPosition()
74 {
75         Perm_player_position = ConsoleObject->pos;
76         Perm_player_orient = ConsoleObject->orient;
77         Perm_player_segnum = ConsoleObject->segnum;
78
79         editor_status("Player initial position set");
80         return 0;
81 }
82
83 // Save game
84 // returns 1 if successful
85 //      returns 0 if unsuccessful
86 int SaveGameData()
87 {
88         char Message[200];
89
90         if (gamestate_not_restored) {
91                 sprintf( Message, "Game State has not been restored...\nContinue?\n");
92                 if (ui_messagebox( -2, -2, 2, Message, "NO", "Yes" )==1) 
93                         return 0;
94                 }
95                 
96    if (ui_get_filename( game_filename, "*.RL2", "SAVE GAME" )) {
97                 int saved_flag;
98                 vms_vector save_pos = ConsoleObject->pos;
99                 vms_matrix save_orient = ConsoleObject->orient;
100                 int save_segnum = ConsoleObject->segnum;
101
102       checkforgamext(game_filename);
103
104                 if (Perm_player_segnum > Highest_segment_index)
105                         Perm_player_segnum = -1;
106
107                 if (Perm_player_segnum!=-1) {
108                         if (get_seg_masks(&Perm_player_position, Perm_player_segnum, 0, __FILE__, __LINE__).centermask == 0)
109                         {
110                                 ConsoleObject->pos = Perm_player_position;
111                                 obj_relink(OBJECT_NUMBER(ConsoleObject), Perm_player_segnum);
112                                 ConsoleObject->orient = Perm_player_orient;
113                         }
114                         else
115                                 Perm_player_segnum=-1;          //position was bogus
116                 }
117       saved_flag=save_level(game_filename);
118                 if (Perm_player_segnum!=-1) {
119                         int     found_save_segnum;
120
121                         if (save_segnum > Highest_segment_index)
122                                 save_segnum = 0;
123
124                         ConsoleObject->pos = save_pos;
125                         found_save_segnum = find_point_seg(&save_pos,save_segnum);
126                         if (found_save_segnum == -1) {
127                                 compute_segment_center(&save_pos, &(Segments[save_segnum]));
128                                 found_save_segnum = save_segnum;
129                         }
130
131                         obj_relink(OBJECT_NUMBER(ConsoleObject), found_save_segnum);
132                         ConsoleObject->orient = save_orient;
133                 }
134                 if (saved_flag)
135                         return 0;
136                 mine_changed = 0;
137         }
138         return 1;
139 }
140
141 // returns 1 if successful
142 //      returns 0 if unsuccessful
143 int LoadGameData()
144 {
145 if (SafetyCheck())  {
146         if (ui_get_filename( game_filename, "*.RL2", "LOAD GAME" ))
147                 {
148                 checkforgamext(game_filename);
149                 if (load_level(game_filename))
150                         return 0;
151                 Current_level_num = 0;                  //not a real level
152                 gamestate_not_restored = 0;
153                 Update_flags = UF_WORLD_CHANGED;
154                 Perm_player_position = ConsoleObject->pos;
155                 Perm_player_orient = ConsoleObject->orient;
156                 Perm_player_segnum = ConsoleObject->segnum;
157                 }
158         }
159         return 1;
160 }
161
162 //called whenever a new mine is created, so new mine doesn't get name
163 //of last saved mine as default
164 void ResetFilename()
165 {
166         strcpy(game_filename,"*.LVL");
167 }
168