Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
3 | * described in COPYING.txt. |
||
4 | * Portions of this file are copyright Parallax Software and licensed |
||
5 | * according to the Parallax license below. |
||
6 | * See COPYING.txt for license details. |
||
7 | |||
8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * |
||
22 | * Game Loading editor functions |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | |||
27 | #include <string.h> |
||
28 | #include <stdio.h> |
||
29 | |||
30 | #include "inferno.h" |
||
31 | #include "editor.h" |
||
32 | #include "ui.h" |
||
33 | #include "game.h" |
||
34 | #include "gamesave.h" |
||
35 | #include "object.h" |
||
36 | #include "gameseq.h" |
||
37 | #include "gameseg.h" |
||
38 | #include "kdefs.h" |
||
39 | |||
40 | static char game_filename[PATH_MAX] = "*." DXX_LEVEL_FILE_EXTENSION; |
||
41 | |||
42 | static void checkforgamext( char * f ) |
||
43 | { |
||
44 | int i; |
||
45 | |||
46 | for (i=1; f[i]; i++ ) |
||
47 | { |
||
48 | if (f[i]=='.') return; |
||
49 | |||
50 | if ((f[i]==' '||f[i]==0) ) |
||
51 | { |
||
52 | f[i]='.'; |
||
53 | f[i+1]='L'; |
||
54 | f[i+2]= 'V'; |
||
55 | f[i+3]= 'L'; |
||
56 | f[i+4]=0; |
||
57 | return; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | if (i < 123) |
||
62 | { |
||
63 | f[i]='.'; |
||
64 | f[i+1]='L'; |
||
65 | f[i+2]= 'V'; |
||
66 | f[i+3]= 'L'; |
||
67 | f[i+4]=0; |
||
68 | return; |
||
69 | } |
||
70 | } |
||
71 | |||
72 | //these variables store the "permanant" player position, which overrides |
||
73 | //whatever the player's position happens to be when the game is saved |
||
74 | segnum_t Perm_player_segnum=segment_none; //-1 means position not set |
||
75 | vms_vector Perm_player_position; |
||
76 | vms_matrix Perm_player_orient; |
||
77 | |||
78 | //set the player's "permanant" position from the current position |
||
79 | int SetPlayerPosition() |
||
80 | { |
||
81 | Perm_player_position = ConsoleObject->pos; |
||
82 | Perm_player_orient = ConsoleObject->orient; |
||
83 | Perm_player_segnum = ConsoleObject->segnum; |
||
84 | |||
85 | editor_status("Player initial position set"); |
||
86 | return 0; |
||
87 | } |
||
88 | |||
89 | // Save game |
||
90 | // returns 1 if successful |
||
91 | // returns 0 if unsuccessful |
||
92 | int SaveGameData() |
||
93 | { |
||
94 | auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
||
95 | auto &Objects = LevelUniqueObjectState.Objects; |
||
96 | auto &Vertices = LevelSharedVertexState.get_vertices(); |
||
97 | auto &vmobjptr = Objects.vmptr; |
||
98 | auto &vmobjptridx = Objects.vmptridx; |
||
99 | if (gamestate == editor_gamestate::unsaved) { |
||
100 | if (ui_messagebox(-2, -2, 2, "Game State has not been saved...\nContinue?\n", "NO", "Yes") == 1) |
||
101 | return 0; |
||
102 | } |
||
103 | |||
104 | if (ui_get_filename( game_filename, "*." DXX_LEVEL_FILE_EXTENSION, "Save Level" )) { |
||
105 | int saved_flag; |
||
106 | vms_vector save_pos = ConsoleObject->pos; |
||
107 | vms_matrix save_orient = ConsoleObject->orient; |
||
108 | auto save_segnum = ConsoleObject->segnum; |
||
109 | |||
110 | checkforgamext(game_filename); |
||
111 | |||
112 | if (Perm_player_segnum > Highest_segment_index) |
||
113 | Perm_player_segnum = segment_none; |
||
114 | |||
115 | auto &vcvertptr = Vertices.vcptr; |
||
116 | if (Perm_player_segnum!=segment_none) { |
||
117 | if (get_seg_masks(vcvertptr, Perm_player_position, vcsegptr(Perm_player_segnum), 0).centermask == 0) |
||
118 | { |
||
119 | ConsoleObject->pos = Perm_player_position; |
||
120 | ConsoleObject->orient = Perm_player_orient; |
||
121 | obj_relink(vmobjptr, vmsegptr, vmobjptridx(ConsoleObject), vmsegptridx(Perm_player_segnum)); |
||
122 | } |
||
123 | else |
||
124 | Perm_player_segnum=segment_none; //position was bogus |
||
125 | } |
||
126 | saved_flag = save_level( |
||
127 | #if defined(DXX_BUILD_DESCENT_II) |
||
128 | LevelSharedSegmentState.DestructibleLights, |
||
129 | #endif |
||
130 | game_filename); |
||
131 | if (Perm_player_segnum!=segment_none) { |
||
132 | |||
133 | if (save_segnum > Highest_segment_index) |
||
134 | save_segnum = 0; |
||
135 | |||
136 | ConsoleObject->pos = save_pos; |
||
137 | const auto &&save_segp = vmsegptridx(save_segnum); |
||
138 | auto found_save_segnum = find_point_seg(LevelSharedSegmentState, LevelUniqueSegmentState, save_pos, save_segp); |
||
139 | if (found_save_segnum == segment_none) { |
||
140 | found_save_segnum = save_segp; |
||
141 | auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
||
142 | auto &Vertices = LevelSharedVertexState.get_vertices(); |
||
143 | auto &vcvertptr = Vertices.vcptr; |
||
144 | compute_segment_center(vcvertptr, save_pos, save_segp); |
||
145 | } |
||
146 | |||
147 | obj_relink(vmobjptr, vmsegptr, vmobjptridx(ConsoleObject), found_save_segnum); |
||
148 | ConsoleObject->orient = save_orient; |
||
149 | } |
||
150 | if (saved_flag) |
||
151 | return 0; |
||
152 | mine_changed = 0; |
||
153 | gamestate = editor_gamestate::none; |
||
154 | } |
||
155 | return 1; |
||
156 | } |
||
157 | |||
158 | // returns 1 if successful |
||
159 | // returns 0 if unsuccessful |
||
160 | int LoadGameData() |
||
161 | { |
||
162 | if (SafetyCheck()) { |
||
163 | if (ui_get_filename( game_filename, "*." DXX_LEVEL_FILE_EXTENSION, "Load Level" )) |
||
164 | { |
||
165 | checkforgamext(game_filename); |
||
166 | if (load_level( |
||
167 | #if defined(DXX_BUILD_DESCENT_II) |
||
168 | LevelSharedSegmentState.DestructibleLights, |
||
169 | #endif |
||
170 | game_filename)) |
||
171 | return 0; |
||
172 | Current_level_num = 1; // assume level 1 |
||
173 | gamestate = editor_gamestate::none; |
||
174 | Update_flags = UF_WORLD_CHANGED; |
||
175 | Perm_player_position = ConsoleObject->pos; |
||
176 | Perm_player_orient = ConsoleObject->orient; |
||
177 | Perm_player_segnum = ConsoleObject->segnum; |
||
178 | } |
||
179 | } |
||
180 | return 1; |
||
181 | } |
||
182 | |||
183 | //called whenever a new mine is created, so new mine doesn't get name |
||
184 | //of last saved mine as default |
||
185 | void ResetFilename() |
||
186 | { |
||
187 | strcpy(game_filename,"*.LVL"); |
||
188 | } |
||
189 |