| 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 |
* Dialog box to edit robot properties. |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#include <stdlib.h> |
| 27 |
#include <stdio.h> |
| 28 |
#include <math.h> |
| 29 |
#include <string.h> |
| 30 |
|
| 31 |
#include "inferno.h" |
| 32 |
#include "segment.h" |
| 33 |
#include "event.h" |
| 34 |
#include "editor.h" |
| 35 |
#include "editor/esegment.h" |
| 36 |
#include "editor/medmisc.h" |
| 37 |
#include "timer.h" |
| 38 |
#include "objpage.h" |
| 39 |
#include "maths.h" |
| 40 |
#include "dxxerror.h" |
| 41 |
#include "kdefs.h" |
| 42 |
#include "object.h" |
| 43 |
#include "robot.h" |
| 44 |
#include "game.h" |
| 45 |
#include "powerup.h" |
| 46 |
#include "ai.h" |
| 47 |
#include "eobject.h" |
| 48 |
#include "medwall.h" |
| 49 |
#include "medrobot.h" |
| 50 |
#include "eswitch.h" |
| 51 |
#include "ehostage.h" |
| 52 |
#include "key.h" |
| 53 |
#include "centers.h" |
| 54 |
#include "bm.h" |
| 55 |
#include "u_mem.h" |
| 56 |
|
| 57 |
#include "compiler-range_for.h" |
| 58 |
#include "d_levelstate.h" |
| 59 |
#include "d_enumerate.h" |
| 60 |
#include <memory> |
| 61 |
|
| 62 |
static int GoodyNextID(); |
| 63 |
static int GoodyPrevID(); |
| 64 |
|
| 65 |
namespace { |
| 66 |
|
| 67 |
static contained_object_parameters Cur_goody = { |
| 68 |
.type = contained_object_type::powerup, |
| 69 |
.id = contained_object_id{ |
| 70 |
.powerup = powerup_type_t::POW_EXTRA_LIFE |
| 71 |
}, |
| 72 |
.count = 0, |
| 73 |
}; |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
//------------------------------------------------------------------------- |
| 78 |
// Variables for this module... |
| 79 |
//------------------------------------------------------------------------- |
| 80 |
namespace dsx { |
| 81 |
|
| 82 |
namespace { |
| 83 |
|
| 84 |
struct robot_dialog : UI_DIALOG |
| 85 |
{ |
| 86 |
using UI_DIALOG::UI_DIALOG; |
| 87 |
std::unique_ptr<UI_GADGET_USERBOX> robotViewBox, containsViewBox; |
| 88 |
std::unique_ptr<UI_GADGET_BUTTON> quitButton, prev_powerup_type, next_powerup_type, prev_powerup_id, next_powerup_id, prev_powerup_count, next_powerup_count, prev_robot_type, next_robot_type, next_segment, prev_object, next_object, delete_object, new_object, set_path; |
| 89 |
std::array<std::unique_ptr<UI_GADGET_RADIO>, 6> initialMode; // Number of boxes, AI modes |
| 90 |
fix64 time; |
| 91 |
vms_angvec angles{}, goody_angles{}; |
| 92 |
int old_object; |
| 93 |
virtual window_event_result callback_handler(const d_event &) override; |
| 94 |
}; |
| 95 |
|
| 96 |
static robot_dialog *MainWindow; |
| 97 |
|
| 98 |
static void call_init_ai_object(const d_robot_info_array &Robot_info, vmobjptridx_t objp, ai_behavior behavior) |
| 99 |
{ |
| 100 |
segnum_t hide_segment; |
| 101 |
|
| 102 |
if (behavior == ai_behavior::AIB_STATION) |
| 103 |
hide_segment = Cursegp; |
| 104 |
else { |
| 105 |
if (Markedsegp != segment_none) |
| 106 |
hide_segment = Markedsegp; |
| 107 |
else |
| 108 |
hide_segment = Cursegp; |
| 109 |
} |
| 110 |
|
| 111 |
init_ai_object(Robot_info, objp, behavior, hide_segment); |
| 112 |
} |
| 113 |
|
| 114 |
//------------------------------------------------------------------------- |
| 115 |
// Called when user presses "Next Type" button. This only works for polygon |
| 116 |
// objects and it just selects the next polygon model for the current object. |
| 117 |
//------------------------------------------------------------------------- |
| 118 |
static int RobotNextType() |
| 119 |
{ |
| 120 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 121 |
auto &vmobjptridx = Objects.vmptridx; |
| 122 |
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; |
| 123 |
if (Cur_object_index != object_none ) { |
| 124 |
const auto &&obj = vmobjptridx(Cur_object_index); |
| 125 |
if (obj->type == OBJ_ROBOT) |
| 126 |
{ |
| 127 |
obj->id++; |
| 128 |
if (obj->id >= LevelSharedRobotInfoState.N_robot_types) |
| 129 |
obj->id = 0; |
| 130 |
|
| 131 |
//Set polygon-object-specific data |
| 132 |
obj->rtype.pobj_info.model_num = Robot_info[get_robot_id(obj)].model_num; |
| 133 |
obj->rtype.pobj_info.subobj_flags = 0; |
| 134 |
//set Physics info |
| 135 |
obj->mtype.phys_info.flags |= (PF_LEVELLING); |
| 136 |
obj->shields = Robot_info[get_robot_id(obj)].strength; |
| 137 |
call_init_ai_object(Robot_info, obj, ai_behavior::AIB_NORMAL); |
| 138 |
|
| 139 |
Cur_object_id = underlying_value(get_robot_id(obj)); |
| 140 |
} |
| 141 |
} |
| 142 |
Update_flags |= UF_WORLD_CHANGED; |
| 143 |
return 1; |
| 144 |
} |
| 145 |
|
| 146 |
//------------------------------------------------------------------------- |
| 147 |
// Called when user presses "Prev Type" button. This only works for polygon |
| 148 |
// objects and it just selects the prev polygon model for the current object. |
| 149 |
//------------------------------------------------------------------------- |
| 150 |
static int RobotPrevType() |
| 151 |
{ |
| 152 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 153 |
auto &vmobjptridx = Objects.vmptridx; |
| 154 |
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; |
| 155 |
if (Cur_object_index != object_none ) { |
| 156 |
const auto &&obj = vmobjptridx(Cur_object_index); |
| 157 |
if (obj->type == OBJ_ROBOT) |
| 158 |
{ |
| 159 |
if (obj->id == 0 ) |
| 160 |
obj->id = LevelSharedRobotInfoState.N_robot_types - 1; |
| 161 |
else |
| 162 |
obj->id--; |
| 163 |
|
| 164 |
//Set polygon-object-specific data |
| 165 |
obj->rtype.pobj_info.model_num = Robot_info[get_robot_id(obj)].model_num; |
| 166 |
obj->rtype.pobj_info.subobj_flags = 0; |
| 167 |
//set Physics info |
| 168 |
obj->mtype.phys_info.flags |= (PF_LEVELLING); |
| 169 |
obj->shields = Robot_info[get_robot_id(obj)].strength; |
| 170 |
call_init_ai_object(Robot_info, obj, ai_behavior::AIB_NORMAL); |
| 171 |
|
| 172 |
Cur_object_id = underlying_value(get_robot_id(obj)); |
| 173 |
} |
| 174 |
} |
| 175 |
Update_flags |= UF_WORLD_CHANGED; |
| 176 |
return 1; |
| 177 |
} |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
//------------------------------------------------------------------------- |
| 184 |
// Dummy function for Mike to write. |
| 185 |
//------------------------------------------------------------------------- |
| 186 |
static int med_set_ai_path() |
| 187 |
{ |
| 188 |
return 1; |
| 189 |
} |
| 190 |
|
| 191 |
// #define OBJ_NONE 255 //unused object |
| 192 |
// #define OBJ_WALL 0 //A wall... not really an object, but used for collisions |
| 193 |
// #define OBJ_FIREBALL 1 //a fireball, part of an explosion |
| 194 |
// #define OBJ_ROBOT 2 //an evil enemy |
| 195 |
// #define OBJ_HOSTAGE 3 //a hostage you need to rescue |
| 196 |
// #define OBJ_PLAYER 4 //the player on the console |
| 197 |
// #define OBJ_WEAPON 5 //a laser, missile, etc |
| 198 |
// #define OBJ_CAMERA 6 //a camera to slew around with |
| 199 |
// #define OBJ_POWERUP 7 //a powerup you can pick up |
| 200 |
// #define OBJ_DEBRIS 8 //a piece of robot |
| 201 |
// #define OBJ_CNTRLCEN 9 //the control center |
| 202 |
// #define OBJ_FLARE 10 //the control center |
| 203 |
// #define MAX_OBJECT_TYPES 11 |
| 204 |
|
| 205 |
|
| 206 |
#define GOODY_TYPE_MAX MAX_OBJECT_TYPES |
| 207 |
#define GOODY_X 6 |
| 208 |
#define GOODY_Y 132 |
| 209 |
|
| 210 |
//#define GOODY_ID_MAX_ROBOT 6 |
| 211 |
//#define GOODY_ID_MAX_POWERUP 9 |
| 212 |
#define GOODY_COUNT_MAX 4 |
| 213 |
|
| 214 |
static void update_goody_info(void) |
| 215 |
{ |
| 216 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 217 |
auto &vmobjptr = Objects.vmptr; |
| 218 |
if (Cur_object_index != object_none ) { |
| 219 |
auto &obj = *vmobjptr(Cur_object_index); |
| 220 |
if (obj.type == OBJ_ROBOT) |
| 221 |
{ |
| 222 |
obj.contains = Cur_goody; |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
// #define OBJ_WALL 0 //A wall... not really an object, but used for collisions |
| 228 |
// #define OBJ_FIREBALL 1 //a fireball, part of an explosion |
| 229 |
// #define OBJ_ROBOT 2 //an evil enemy |
| 230 |
// #define OBJ_HOSTAGE 3 //a hostage you need to rescue |
| 231 |
// #define OBJ_PLAYER 4 //the player on the console |
| 232 |
// #define OBJ_WEAPON 5 //a laser, missile, etc |
| 233 |
// #define OBJ_CAMERA 6 //a camera to slew around with |
| 234 |
// #define OBJ_POWERUP 7 //a powerup you can pick up |
| 235 |
// #define OBJ_DEBRIS 8 //a piece of robot |
| 236 |
// #define OBJ_CNTRLCEN 9 //the control center |
| 237 |
// #define OBJ_FLARE 10 //the control center |
| 238 |
// #define MAX_OBJECT_TYPES 11 |
| 239 |
|
| 240 |
static void GoodyClampIDLower(const contained_object_type type) |
| 241 |
{ |
| 242 |
switch (type) |
| 243 |
{ |
| 244 |
case contained_object_type::robot: |
| 245 |
if (underlying_value(Cur_goody.id.robot) >= LevelSharedRobotInfoState.N_robot_types) |
| 246 |
Cur_goody.id.robot = {}; |
| 247 |
break; |
| 248 |
case contained_object_type::powerup: |
| 249 |
if (underlying_value(Cur_goody.id.powerup) >= N_powerup_types) |
| 250 |
Cur_goody.id.powerup = {}; |
| 251 |
break; |
| 252 |
default: |
| 253 |
break; |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
static void GoodyClampIDUpper(const contained_object_type type) |
| 258 |
{ |
| 259 |
switch (type) |
| 260 |
{ |
| 261 |
case contained_object_type::robot: |
| 262 |
if (const auto N_robot_types{LevelSharedRobotInfoState.N_robot_types}; underlying_value(Cur_goody.id.robot) >= N_robot_types) |
| 263 |
Cur_goody.id.robot = static_cast<robot_id>(N_robot_types - 1); |
| 264 |
break; |
| 265 |
case contained_object_type::powerup: |
| 266 |
if (const auto n{N_powerup_types}; underlying_value(Cur_goody.id.powerup) >= n) |
| 267 |
Cur_goody.id.powerup = static_cast<powerup_type_t>(n - 1); |
| 268 |
break; |
| 269 |
default: |
| 270 |
break; |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
static int GoodyToggleType() |
| 275 |
{ |
| 276 |
Cur_goody.type = (Cur_goody.type == contained_object_type::robot) ? contained_object_type::powerup : contained_object_type::robot; |
| 277 |
GoodyClampIDLower(Cur_goody.type); |
| 278 |
|
| 279 |
update_goody_info(); |
| 280 |
return 1; |
| 281 |
} |
| 282 |
|
| 283 |
int GoodyNextID() |
| 284 |
{ |
| 285 |
Cur_goody.id.robot = static_cast<robot_id>(underlying_value(Cur_goody.id.robot) + 1); |
| 286 |
GoodyClampIDLower(Cur_goody.type); |
| 287 |
update_goody_info(); |
| 288 |
return 1; |
| 289 |
} |
| 290 |
|
| 291 |
int GoodyPrevID() |
| 292 |
{ |
| 293 |
Cur_goody.id.robot = static_cast<robot_id>(underlying_value(Cur_goody.id.robot) - 1); |
| 294 |
GoodyClampIDUpper(Cur_goody.type); |
| 295 |
|
| 296 |
update_goody_info(); |
| 297 |
return 1; |
| 298 |
} |
| 299 |
|
| 300 |
static int GoodyNextCount() |
| 301 |
{ |
| 302 |
Cur_goody.count = Cur_goody.count > GOODY_COUNT_MAX ? 0 : (Cur_goody.count + 1); |
| 303 |
update_goody_info(); |
| 304 |
return 1; |
| 305 |
} |
| 306 |
|
| 307 |
static int GoodyPrevCount() |
| 308 |
{ |
| 309 |
Cur_goody.count = Cur_goody.count == 0 ? GOODY_COUNT_MAX : (Cur_goody.count - 1); |
| 310 |
update_goody_info(); |
| 311 |
return 1; |
| 312 |
} |
| 313 |
|
| 314 |
static int is_legal_type(int the_type) |
| 315 |
{ |
| 316 |
return (the_type == OBJ_ROBOT) || (the_type == OBJ_CLUTTER); |
| 317 |
} |
| 318 |
|
| 319 |
static int is_legal_type_for_this_window(const imobjidx_t objnum) |
| 320 |
{ |
| 321 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 322 |
auto &vmobjptr = Objects.vmptr; |
| 323 |
if (objnum == object_none) |
| 324 |
return 1; |
| 325 |
else |
| 326 |
return is_legal_type(vmobjptr(objnum)->type); |
| 327 |
} |
| 328 |
|
| 329 |
static int LocalObjectSelectNextinSegment(void) |
| 330 |
{ |
| 331 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 332 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 333 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 334 |
auto &vmobjptr = Objects.vmptr; |
| 335 |
int rval, first_obj; |
| 336 |
|
| 337 |
rval = ObjectSelectNextinSegment(); |
| 338 |
first_obj = Cur_object_index; |
| 339 |
|
| 340 |
if (Cur_object_index != object_none) { |
| 341 |
while (!is_legal_type_for_this_window(Cur_object_index)) { |
| 342 |
rval = ObjectSelectNextinSegment(); |
| 343 |
if (first_obj == Cur_object_index) |
| 344 |
break; |
| 345 |
} |
| 346 |
|
| 347 |
const auto &&objp = vmobjptr(Cur_object_index); |
| 348 |
if (auto &c = objp->contains.count; c > GOODY_COUNT_MAX) |
| 349 |
c = 0; |
| 350 |
Cur_goody = objp->contains; |
| 351 |
} |
| 352 |
|
| 353 |
if (Cur_object_index != first_obj) |
| 354 |
{ |
| 355 |
auto &vcvertptr = Vertices.vcptr; |
| 356 |
set_view_target_from_segment(vcvertptr, Cursegp); |
| 357 |
} |
| 358 |
|
| 359 |
return rval; |
| 360 |
} |
| 361 |
|
| 362 |
static int LocalObjectSelectNextinMine(void) |
| 363 |
{ |
| 364 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 365 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 366 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 367 |
auto &vmobjptr = Objects.vmptr; |
| 368 |
int rval, first_obj; |
| 369 |
|
| 370 |
rval = ObjectSelectNextInMine(); |
| 371 |
|
| 372 |
first_obj = Cur_object_index; |
| 373 |
|
| 374 |
if (Cur_object_index != object_none) { |
| 375 |
while (!is_legal_type_for_this_window(Cur_object_index)) { |
| 376 |
ObjectSelectNextInMine(); |
| 377 |
if (Cur_object_index == first_obj) |
| 378 |
break; |
| 379 |
} |
| 380 |
|
| 381 |
const auto &&objp = vmobjptr(Cur_object_index); |
| 382 |
if (auto &c = objp->contains.count; c > GOODY_COUNT_MAX) |
| 383 |
c = 0; |
| 384 |
Cur_goody = objp->contains; |
| 385 |
} |
| 386 |
|
| 387 |
if (Cur_object_index != first_obj) |
| 388 |
{ |
| 389 |
auto &vcvertptr = Vertices.vcptr; |
| 390 |
set_view_target_from_segment(vcvertptr, Cursegp); |
| 391 |
} |
| 392 |
|
| 393 |
return rval; |
| 394 |
} |
| 395 |
|
| 396 |
static int LocalObjectSelectPrevinMine(void) |
| 397 |
{ |
| 398 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 399 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 400 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 401 |
auto &vmobjptr = Objects.vmptr; |
| 402 |
int rval, first_obj; |
| 403 |
|
| 404 |
rval = ObjectSelectPrevInMine(); |
| 405 |
|
| 406 |
first_obj = Cur_object_index; |
| 407 |
|
| 408 |
if (Cur_object_index != object_none) { |
| 409 |
while (!is_legal_type_for_this_window(Cur_object_index)) { |
| 410 |
ObjectSelectPrevInMine(); |
| 411 |
if (first_obj == Cur_object_index) |
| 412 |
break; |
| 413 |
} |
| 414 |
|
| 415 |
const auto &&objp = vmobjptr(Cur_object_index); |
| 416 |
if (auto &c = objp->contains.count; c > GOODY_COUNT_MAX) |
| 417 |
c = 0; |
| 418 |
Cur_goody = objp->contains; |
| 419 |
} |
| 420 |
|
| 421 |
if (Cur_object_index != first_obj) |
| 422 |
{ |
| 423 |
auto &vcvertptr = Vertices.vcptr; |
| 424 |
set_view_target_from_segment(vcvertptr, Cursegp); |
| 425 |
} |
| 426 |
|
| 427 |
return rval; |
| 428 |
} |
| 429 |
|
| 430 |
static int LocalObjectDelete(void) |
| 431 |
{ |
| 432 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 433 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 434 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 435 |
auto &vcobjptr = Objects.vcptr; |
| 436 |
int rval; |
| 437 |
|
| 438 |
rval = ObjectDelete(); |
| 439 |
|
| 440 |
if (Cur_object_index != object_none) { |
| 441 |
auto &objp = *vcobjptr(Cur_object_index); |
| 442 |
Cur_goody = objp.contains; |
| 443 |
} |
| 444 |
|
| 445 |
auto &vcvertptr = Vertices.vcptr; |
| 446 |
set_view_target_from_segment(vcvertptr, Cursegp); |
| 447 |
|
| 448 |
return rval; |
| 449 |
} |
| 450 |
|
| 451 |
static int LocalObjectPlaceObject(void) |
| 452 |
{ |
| 453 |
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
| 454 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 455 |
auto &Vertices = LevelSharedVertexState.get_vertices(); |
| 456 |
auto &vmobjptr = Objects.vmptr; |
| 457 |
int rval; |
| 458 |
|
| 459 |
if (Cur_object_type != OBJ_ROBOT) |
| 460 |
{ |
| 461 |
Cur_object_type = OBJ_ROBOT; |
| 462 |
Cur_object_id = 3; // class 1 drone |
| 463 |
Num_object_subtypes = LevelSharedRobotInfoState.N_robot_types; |
| 464 |
} |
| 465 |
|
| 466 |
Cur_goody.count = 0; |
| 467 |
|
| 468 |
rval = ObjectPlaceObject(); |
| 469 |
if (rval == -1) |
| 470 |
return -1; |
| 471 |
|
| 472 |
const auto &&objp = vmobjptr(Cur_object_index); |
| 473 |
objp->contains = Cur_goody; |
| 474 |
|
| 475 |
auto &vcvertptr = Vertices.vcptr; |
| 476 |
set_view_target_from_segment(vcvertptr, Cursegp); |
| 477 |
|
| 478 |
return rval; |
| 479 |
} |
| 480 |
|
| 481 |
void close_all_windows(void) |
| 482 |
{ |
| 483 |
close_trigger_window(); |
| 484 |
close_wall_window(); |
| 485 |
close_centers_window(); |
| 486 |
#if DXX_BUILD_DESCENT == 1 |
| 487 |
hostage_close_window(); |
| 488 |
#endif |
| 489 |
robot_close_window(); |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
//------------------------------------------------------------------------- |
| 494 |
// Called from the editor... does one instance of the robot dialog box |
| 495 |
//------------------------------------------------------------------------- |
| 496 |
int do_robot_dialog() |
| 497 |
{ |
| 498 |
// Only open 1 instance of this window... |
| 499 |
if ( MainWindow != NULL ) return 0; |
| 500 |
|
| 501 |
// Close other windows |
| 502 |
close_all_windows(); |
| 503 |
Cur_goody.count = 0; |
| 504 |
|
| 505 |
// Open a window with a quit button |
| 506 |
MainWindow = window_create<robot_dialog>(TMAPBOX_X + 20, TMAPBOX_Y + 20, 765 - TMAPBOX_X, 545 - TMAPBOX_Y, DF_DIALOG); |
| 507 |
return 1; |
| 508 |
} |
| 509 |
|
| 510 |
static window_event_result robot_dialog_created(robot_dialog *const r) |
| 511 |
{ |
| 512 |
r->quitButton = ui_add_gadget_button(*r, 20, 286, 40, 32, "Done", NULL); |
| 513 |
r->prev_powerup_type = ui_add_gadget_button(*r, GOODY_X+50, GOODY_Y-3, 25, 22, "<<", GoodyToggleType); |
| 514 |
r->next_powerup_type = ui_add_gadget_button(*r, GOODY_X+80, GOODY_Y-3, 25, 22, ">>", GoodyToggleType); |
| 515 |
r->prev_powerup_id = ui_add_gadget_button(*r, GOODY_X+50, GOODY_Y+21, 25, 22, "<<", GoodyPrevID); |
| 516 |
r->next_powerup_id = ui_add_gadget_button(*r, GOODY_X+80, GOODY_Y+21, 25, 22, ">>", GoodyNextID); |
| 517 |
r->prev_powerup_count = ui_add_gadget_button(*r, GOODY_X+50, GOODY_Y+45, 25, 22, "<<", GoodyPrevCount); |
| 518 |
r->next_powerup_count = ui_add_gadget_button(*r, GOODY_X+80, GOODY_Y+45, 25, 22, ">>", GoodyNextCount); |
| 519 |
r->initialMode[0] = ui_add_gadget_radio(*r, 6, 58, 16, 16, 0, "Hover"); |
| 520 |
r->initialMode[1] = ui_add_gadget_radio(*r, 76, 58, 16, 16, 0, "Normal"); |
| 521 |
r->initialMode[2] = ui_add_gadget_radio(*r, 6, 78, 16, 16, 0, "(hide)"); |
| 522 |
r->initialMode[3] = ui_add_gadget_radio(*r, 76, 78, 16, 16, 0, "Avoid"); |
| 523 |
r->initialMode[4] = ui_add_gadget_radio(*r, 6, 98, 16, 16, 0, "Follow"); |
| 524 |
r->initialMode[5] = ui_add_gadget_radio(*r, 76, 98, 16, 16, 0, "Station"); |
| 525 |
// The little box the robots will spin in. |
| 526 |
r->robotViewBox = ui_add_gadget_userbox(*r, 155, 5, 150, 125); |
| 527 |
// The little box the robots will spin in. |
| 528 |
r->containsViewBox = ui_add_gadget_userbox(*r, 10, 202, 100, 80); |
| 529 |
// A bunch of buttons... |
| 530 |
int i{135}; |
| 531 |
r->prev_robot_type = ui_add_gadget_button(*r, 190, i, 53, 26, "<<Typ", RobotPrevType); |
| 532 |
r->next_robot_type = ui_add_gadget_button(*r, 247, i, 53, 26, "Typ>>", RobotNextType); i += 29; |
| 533 |
r->next_segment = ui_add_gadget_button(*r, 190, i, 110, 26, "Next in Seg", LocalObjectSelectNextinSegment); i += 29; |
| 534 |
r->prev_object = ui_add_gadget_button(*r, 190, i, 53, 26, "<<Obj", LocalObjectSelectPrevinMine); |
| 535 |
r->next_object = ui_add_gadget_button(*r, 247, i, 53, 26, ">>Obj", LocalObjectSelectNextinMine); i += 29; |
| 536 |
r->delete_object = ui_add_gadget_button(*r, 190, i, 110, 26, "Delete", LocalObjectDelete); i += 29; |
| 537 |
r->new_object = ui_add_gadget_button(*r, 190, i, 110, 26, "Create New", LocalObjectPlaceObject); i += 29; |
| 538 |
r->set_path = ui_add_gadget_button(*r, 190, i, 110, 26, "Set Path", med_set_ai_path); |
| 539 |
r->time = timer_query(); |
| 540 |
r->old_object = -2; // Set to some dummy value so everything works ok on the first frame. |
| 541 |
if ( Cur_object_index == object_none) |
| 542 |
LocalObjectSelectNextinMine(); |
| 543 |
return window_event_result::handled; |
| 544 |
} |
| 545 |
|
| 546 |
void robot_close_window() |
| 547 |
{ |
| 548 |
if ( MainWindow!=NULL ) { |
| 549 |
ui_close_dialog(*std::exchange(MainWindow, nullptr)); |
| 550 |
} |
| 551 |
|
| 552 |
} |
| 553 |
|
| 554 |
namespace dsx { |
| 555 |
|
| 556 |
namespace { |
| 557 |
|
| 558 |
window_event_result robot_dialog::callback_handler(const d_event &event) |
| 559 |
{ |
| 560 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 561 |
auto &vcobjptr = Objects.vcptr; |
| 562 |
auto &vmobjptr = Objects.vmptr; |
| 563 |
auto &vmobjptridx = Objects.vmptridx; |
| 564 |
switch(event.type) |
| 565 |
{ |
| 566 |
case event_type::window_created: |
| 567 |
return robot_dialog_created(this); |
| 568 |
case event_type::window_close: |
| 569 |
MainWindow = NULL; |
| 570 |
return window_event_result::ignored; |
| 571 |
default: |
| 572 |
break; |
| 573 |
} |
| 574 |
fix DeltaTime; |
| 575 |
fix64 Temp; |
| 576 |
int first_object_index; |
| 577 |
int keypress{0}; |
| 578 |
window_event_result rval = window_event_result::ignored; |
| 579 |
if (event.type == event_type::key_command) |
| 580 |
keypress = event_key_get(event); |
| 581 |
Assert(MainWindow != NULL); |
| 582 |
|
| 583 |
first_object_index = Cur_object_index; |
| 584 |
while (!is_legal_type_for_this_window(Cur_object_index)) { |
| 585 |
LocalObjectSelectNextinMine(); |
| 586 |
if (first_object_index == Cur_object_index) { |
| 587 |
break; |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
//------------------------------------------------------------ |
| 592 |
// Call the ui code.. |
| 593 |
//------------------------------------------------------------ |
| 594 |
ui_button_any_drawn = 0; |
| 595 |
|
| 596 |
//------------------------------------------------------------ |
| 597 |
// If we change objects, we need to reset the ui code for all |
| 598 |
// of the radio buttons that control the ai mode. Also makes |
| 599 |
// the current AI mode button be flagged as pressed down. |
| 600 |
//------------------------------------------------------------ |
| 601 |
if (old_object != Cur_object_index ) { |
| 602 |
range_for (auto &i, initialMode) |
| 603 |
ui_radio_set_value(*i, 0); |
| 604 |
if ( Cur_object_index != object_none ) { |
| 605 |
auto &behavior = vmobjptr(Cur_object_index)->ctype.ai_info.behavior; |
| 606 |
switch (behavior) |
| 607 |
{ |
| 608 |
case ai_behavior::AIB_STILL: |
| 609 |
case ai_behavior::AIB_NORMAL: |
| 610 |
case ai_behavior::AIB_RUN_FROM: |
| 611 |
case ai_behavior::AIB_STATION: |
| 612 |
#if DXX_BUILD_DESCENT == 1 |
| 613 |
case ai_behavior::AIB_HIDE: |
| 614 |
case ai_behavior::AIB_FOLLOW_PATH: |
| 615 |
#elif DXX_BUILD_DESCENT == 2 |
| 616 |
case ai_behavior::AIB_BEHIND: |
| 617 |
case ai_behavior::AIB_SNIPE: |
| 618 |
case ai_behavior::AIB_FOLLOW: |
| 619 |
#endif |
| 620 |
break; |
| 621 |
default: |
| 622 |
behavior = ai_behavior::AIB_NORMAL; |
| 623 |
break; |
| 624 |
} |
| 625 |
ui_radio_set_value(*initialMode[static_cast<std::size_t>(behavior) - MIN_BEHAVIOR], 1); |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
//------------------------------------------------------------ |
| 630 |
// If any of the radio buttons that control the mode are set, then |
| 631 |
// update the cooresponding AI state. |
| 632 |
//------------------------------------------------------------ |
| 633 |
for (auto &&[i, im] : enumerate(initialMode)) |
| 634 |
{ |
| 635 |
if (GADGET_PRESSED(im.get())) |
| 636 |
{ |
| 637 |
const auto b = static_cast<ai_behavior>(MIN_BEHAVIOR + i); |
| 638 |
const auto &&objp = vmobjptridx(Cur_object_index); |
| 639 |
auto &behavior = objp->ctype.ai_info.behavior; |
| 640 |
if (behavior != b) { |
| 641 |
behavior = b; // Set the ai_state to the cooresponding radio button |
| 642 |
call_init_ai_object(LevelSharedRobotInfoState.Robot_info, objp, b); |
| 643 |
rval = window_event_result::handled; |
| 644 |
} |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
//------------------------------------------------------------ |
| 649 |
// Redraw the object in the little 64x64 box |
| 650 |
//------------------------------------------------------------ |
| 651 |
if (event.type == event_type::ui_dialog_draw) |
| 652 |
{ |
| 653 |
// A simple frame time counter for spinning the objects... |
| 654 |
Temp = timer_query(); |
| 655 |
DeltaTime = Temp - time; |
| 656 |
time = Temp; |
| 657 |
|
| 658 |
gr_set_current_canvas(robotViewBox->canvas); |
| 659 |
if (Cur_object_index != object_none ) { |
| 660 |
const auto &&obj = vmobjptr(Cur_object_index); |
| 661 |
|
| 662 |
draw_object_picture(*grd_curcanv, obj->id, angles, obj->type); |
| 663 |
angles.h += fixmul(0x1000, DeltaTime ); |
| 664 |
} else { |
| 665 |
// no object, so just blank out |
| 666 |
gr_clear_canvas(*grd_curcanv, CGREY); |
| 667 |
|
| 668 |
// LocalObjectSelectNextInMine(); |
| 669 |
} |
| 670 |
|
| 671 |
//------------------------------------------------------------ |
| 672 |
// Redraw the contained object in the other little box |
| 673 |
//------------------------------------------------------------ |
| 674 |
gr_set_current_canvas(containsViewBox->canvas); |
| 675 |
if (Cur_object_index != object_none && Cur_goody.count > 0) |
| 676 |
{ |
| 677 |
draw_object_picture(*grd_curcanv, underlying_value(Cur_goody.id.robot), goody_angles, underlying_value(Cur_goody.type)); |
| 678 |
goody_angles.h += fixmul(0x1000, DeltaTime ); |
| 679 |
} else { |
| 680 |
// no object, so just blank out |
| 681 |
gr_clear_canvas(*grd_curcanv, CGREY); |
| 682 |
|
| 683 |
// LocalObjectSelectNextInMine(); |
| 684 |
} |
| 685 |
//------------------------------------------------------------ |
| 686 |
// If anything changes in the ui system, redraw all the text that |
| 687 |
// identifies this robot. |
| 688 |
//------------------------------------------------------------ |
| 689 |
|
| 690 |
const char *id_text; |
| 691 |
const char *type_text; |
| 692 |
|
| 693 |
if (Cur_object_index != object_none) { |
| 694 |
auto &&obj = *vmobjptr(Cur_object_index); |
| 695 |
if (auto &c = obj.contains.count; c > GOODY_COUNT_MAX) |
| 696 |
c = 0; |
| 697 |
Cur_goody = obj.contains; |
| 698 |
} |
| 699 |
|
| 700 |
ui_dputs_at(MainWindow, GOODY_X, GOODY_Y, " Type:"); |
| 701 |
ui_dputs_at(MainWindow, GOODY_X, GOODY_Y+24, " ID:"); |
| 702 |
ui_dputs_at(MainWindow, GOODY_X, GOODY_Y+48, "Count:"); |
| 703 |
|
| 704 |
switch (Cur_goody.type) { |
| 705 |
case contained_object_type::robot: |
| 706 |
type_text = "Robot "; |
| 707 |
id_text = Robot_names[Cur_goody.id.robot].data(); |
| 708 |
break; |
| 709 |
default: |
| 710 |
editor_status_fmt("Illegal contained object type (%i), changing to powerup.", underlying_value(std::exchange(Cur_goody.type, contained_object_type::powerup))); |
| 711 |
Cur_goody.id.powerup = {}; |
| 712 |
[[fallthrough]]; |
| 713 |
case contained_object_type::powerup: |
| 714 |
type_text = "Powerup"; |
| 715 |
id_text = Powerup_names[Cur_goody.id.powerup].data(); |
| 716 |
break; |
| 717 |
} |
| 718 |
|
| 719 |
ui_dputs_at( MainWindow, GOODY_X+108, GOODY_Y, type_text); |
| 720 |
ui_dprintf_at( MainWindow, GOODY_X+108, GOODY_Y+24, "%-8s", id_text); |
| 721 |
ui_dprintf_at(MainWindow, GOODY_X+108, GOODY_Y+48, "%u", Cur_goody.count); |
| 722 |
|
| 723 |
if ( Cur_object_index != object_none ) { |
| 724 |
const auto id = get_robot_id(vcobjptr(Cur_object_index)); |
| 725 |
|
| 726 |
ui_dprintf_at( MainWindow, 12, 6, "Robot: %3d ", Cur_object_index ); |
| 727 |
ui_dprintf_at( MainWindow, 12, 22, " Id: %3d", underlying_value(id)); |
| 728 |
ui_dprintf_at( MainWindow, 12, 38, " Name: %-8s", Robot_names[id].data()); |
| 729 |
|
| 730 |
} else { |
| 731 |
ui_dputs_at(MainWindow, 12, 6, "Robot: none"); |
| 732 |
ui_dputs_at(MainWindow, 12, 22, " Type: ?"); |
| 733 |
ui_dputs_at(MainWindow, 12, 38, " Name: ________"); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
if (ui_button_any_drawn || (old_object != Cur_object_index) ) |
| 738 |
Update_flags |= UF_WORLD_CHANGED; |
| 739 |
if (GADGET_PRESSED(quitButton.get()) || keypress == KEY_ESC) |
| 740 |
{ |
| 741 |
return window_event_result::close; |
| 742 |
} |
| 743 |
|
| 744 |
old_object = Cur_object_index; |
| 745 |
return rval; |
| 746 |
} |
| 747 |
|
| 748 |
} |
| 749 |
|
| 750 |
} |
| 751 |
|
| 752 |
// -------------------------------------------------------------------------------------------------------------------------- |
| 753 |
#define NUM_MATT_THINGS 2 |
| 754 |
|
| 755 |
#define MATT_LEN 20 |
| 756 |
|
| 757 |
namespace { |
| 758 |
|
| 759 |
struct object_dialog : UI_DIALOG |
| 760 |
{ |
| 761 |
explicit object_dialog(short x, short y, short w, short h, enum dialog_flags flags, object &obj); |
| 762 |
struct creation_context |
| 763 |
{ |
| 764 |
vmobjptr_t obj; |
| 765 |
creation_context(vmobjptr_t o) : |
| 766 |
obj(o) |
| 767 |
{ |
| 768 |
} |
| 769 |
}; |
| 770 |
std::unique_ptr<UI_GADGET_INPUTBOX> xtext, ytext, ztext; |
| 771 |
std::array<std::unique_ptr<UI_GADGET_RADIO>, 2> initialMode; |
| 772 |
std::unique_ptr<UI_GADGET_BUTTON> quitButton; |
| 773 |
virtual window_event_result callback_handler(const d_event &) override; |
| 774 |
}; |
| 775 |
|
| 776 |
static object_dialog *MattWindow; |
| 777 |
|
| 778 |
} |
| 779 |
|
| 780 |
void object_close_window() |
| 781 |
{ |
| 782 |
if ( MattWindow!=NULL ) { |
| 783 |
ui_close_dialog(*std::exchange(MattWindow, nullptr)); |
| 784 |
} |
| 785 |
|
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
//------------------------------------------------------------------------- |
| 790 |
// Called from the editor... does one instance of the object dialog box |
| 791 |
//------------------------------------------------------------------------- |
| 792 |
int do_object_dialog() |
| 793 |
{ |
| 794 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 795 |
auto &vmobjptr = Objects.vmptr; |
| 796 |
if (Cur_object_index == object_none) |
| 797 |
Cur_object_index = object_first; |
| 798 |
|
| 799 |
auto obj = vmobjptr(Cur_object_index); |
| 800 |
if (obj->type == OBJ_ROBOT) //don't do this for robots |
| 801 |
return 0; |
| 802 |
|
| 803 |
// Only open 1 instance of this window... |
| 804 |
if ( MattWindow != NULL ) |
| 805 |
return 0; |
| 806 |
|
| 807 |
Cur_goody.count = 0; |
| 808 |
|
| 809 |
// Open a window with a quit button |
| 810 |
MattWindow = window_create<object_dialog>(TMAPBOX_X + 20, TMAPBOX_Y + 20, 765 - TMAPBOX_X, 545 - TMAPBOX_Y, DF_DIALOG, *obj); |
| 811 |
return 1; |
| 812 |
} |
| 813 |
|
| 814 |
object_dialog::object_dialog(short x, short y, short w, short h, enum dialog_flags flags, object &obj) : |
| 815 |
UI_DIALOG(x, y, w, h, flags) |
| 816 |
{ |
| 817 |
quitButton = ui_add_gadget_button(*this, 20, 286, 40, 32, "Done", NULL ); |
| 818 |
quitButton->hotkey = KEY_ENTER; |
| 819 |
// These are the radio buttons for each mode |
| 820 |
initialMode[0] = ui_add_gadget_radio(*this, 10, 50, 16, 16, 0, "None" ); |
| 821 |
initialMode[1] = ui_add_gadget_radio(*this, 80, 50, 16, 16, 0, "Spinning" ); |
| 822 |
initialMode[obj.movement_source == object::movement_type::spinning ? 1 : 0]->flag = 1; |
| 823 |
char message[MATT_LEN]; |
| 824 |
snprintf(message, sizeof(message), "%.2f", f2fl(obj.mtype.spin_rate.x)); |
| 825 |
xtext = ui_add_gadget_inputbox<MATT_LEN>(*this, 30, 132, message); |
| 826 |
snprintf(message, sizeof(message), "%.2f", f2fl(obj.mtype.spin_rate.y)); |
| 827 |
ytext = ui_add_gadget_inputbox<MATT_LEN>(*this, 30, 162, message); |
| 828 |
snprintf(message, sizeof(message), "%.2f", f2fl(obj.mtype.spin_rate.z)); |
| 829 |
ztext = ui_add_gadget_inputbox<MATT_LEN>(*this, 30, 192, message); |
| 830 |
ui_gadget_calc_keys(*this); |
| 831 |
keyboard_focus_gadget = initialMode[0].get(); |
| 832 |
} |
| 833 |
|
| 834 |
window_event_result object_dialog::callback_handler(const d_event &event) |
| 835 |
{ |
| 836 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 837 |
auto &vmobjptr = Objects.vmptr; |
| 838 |
switch(event.type) |
| 839 |
{ |
| 840 |
case event_type::window_close: |
| 841 |
MattWindow = NULL; |
| 842 |
return window_event_result::ignored; |
| 843 |
default: |
| 844 |
break; |
| 845 |
} |
| 846 |
const auto &&obj = vmobjptr(Cur_object_index); |
| 847 |
int keypress{0}; |
| 848 |
window_event_result rval = window_event_result::ignored; |
| 849 |
if (event.type == event_type::key_command) |
| 850 |
keypress = event_key_get(event); |
| 851 |
//------------------------------------------------------------ |
| 852 |
// Call the ui code.. |
| 853 |
//------------------------------------------------------------ |
| 854 |
ui_button_any_drawn = 0; |
| 855 |
|
| 856 |
|
| 857 |
if (event.type == event_type::ui_dialog_draw) |
| 858 |
{ |
| 859 |
ui_dputs_at(this, 10, 132, "&X:"); |
| 860 |
ui_dputs_at(this, 10, 162, "&Y:"); |
| 861 |
ui_dputs_at(this, 10, 192, "&Z:"); |
| 862 |
} |
| 863 |
if (GADGET_PRESSED(quitButton.get()) || keypress == KEY_ESC) |
| 864 |
{ |
| 865 |
if (initialMode[0]->flag) |
| 866 |
obj->movement_source = object::movement_type::None; |
| 867 |
if (initialMode[1]->flag) |
| 868 |
obj->movement_source = object::movement_type::spinning; |
| 869 |
|
| 870 |
obj->mtype.spin_rate.x = fl2f(atof(xtext->text.get())); |
| 871 |
obj->mtype.spin_rate.y = fl2f(atof(ytext->text.get())); |
| 872 |
obj->mtype.spin_rate.z = fl2f(atof(ztext->text.get())); |
| 873 |
return window_event_result::close; |
| 874 |
} |
| 875 |
return rval; |
| 876 |
} |