1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
|
/*
===========================================================================
Copyright (C) 2023 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#include "cl_ui.h"
typedef struct {
const char *string;
int value;
} equipment_event_table_t;
static equipment_event_table_t s_equipTable[] = {
{"left", 1 },
{"right", 2 },
{"dual", 4 },
{"use", 8 },
{"none", 16},
{NULL, 0 }
};
Event evi_inv_changesound
(
"inv_changesound",
EV_DEFAULT,
"s",
"soundname",
"Set the sound to play when the inventory changes items"
);
Event evi_inv_selectsound
(
"inv_selectsound",
EV_DEFAULT,
"s",
"soundname",
"Set the sound to play when an inventory item is selected"
);
Event evi_inv_rejectsound
(
"inv_rejectsound",
EV_DEFAULT,
"s",
"soundname",
"Set the sound to play when an invalid inventory item is selected"
);
Event evi_inv_width
(
"inv_width",
EV_DEFAULT,
"i",
"width",
"Specifies the width of each of the main inv buttons"
);
Event evi_inv_height
(
"inv_height",
EV_DEFAULT,
"i",
"height",
"Specifies the height of each of the main inv buttons"
);
Event evi_inv_vertical_offset
(
"inv_vert_offset",
EV_DEFAULT,
"i",
"offset",
"Specifies the vertical offset from the top of the screen for the inventory"
);
Event evi_inv_horizontal_offset
(
"inv_horiz_offset",
EV_DEFAULT,
"i",
"offset",
"Specifies the horizontal offset from the right of the screen for the inventory"
);
Event evi_inv_align
(
"inv_align",
EV_DEFAULT,
"s",
"side",
"Specifies the horizontal offset from the right of the screen for the inventory"
);
Event evi_inv_cascade
(
"inv_cascade",
EV_DEFAULT,
"s",
"side",
"Specifies the side which to cascade inventory items"
);
Event evi_typedef
(
"typedef",
EV_DEFAULT,
"s",
"type",
"Specifies which class of item you're editing"
);
Event evi_openbrace
(
"{", EV_DEFAULT,
NULL,
NULL,
"Open brace, useless"
);
Event evi_closebrace
(
"}", EV_DEFAULT,
NULL,
NULL,
"Close brace, useless"
);
Event evi_button_shader
(
"button_shader",
EV_DEFAULT,
"s",
"shader",
"The shader for the class button"
);
Event evi_hover_shader
(
"hover_shader",
EV_DEFAULT,
"s",
"shader",
"The shader for the class button when hovering"
);
Event evi_sel_shader
(
"sel_shader",
EV_DEFAULT,
"s",
"shader",
"The shader for the class button when selected"
);
Event evi_bg
(
"bg",
EV_DEFAULT,
"s",
"shader",
"Shader for the background of the class submenu"
);
Event evi_bg_tile
(
"bg_tile",
EV_DEFAULT,
NULL,
NULL,
"Specifies to tile the background of the class submenu"
);
Event evi_width
(
"width",
EV_DEFAULT,
"i",
"width",
"The width of the current item, or default width of all items depending on context"
);
Event evi_height
(
"height",
EV_DEFAULT,
"i",
"height",
"The height of the current item, or default width of all items depending on context"
);
Event evi_barwidth
(
"barwidth",
EV_DEFAULT,
"i",
"width",
"The width of the current item's ammo bar or default width of all items bar's depending on context"
);
Event evi_barheight(
"barheight",
EV_DEFAULT,
"i",
"barheight",
"The height of the current item's ammo bar, or default width of all items bar's depending on context"
);
Event evi_baroffsetx
(
"baroffsetx",
EV_DEFAULT,
"i",
"width",
"The x offset used to calculate ammo bar"
);
Event evi_baroffsety
(
"baroffsety",
EV_DEFAULT,
"i",
"width",
"The y offset used to calculate ammo bar"
);
Event evi_item
(
"item",
EV_DEFAULT,
"s",
"item_name",
"The name of the current item"
);
Event evi_ammo
(
"ammo",
EV_DEFAULT,
"s",
"ammo_name",
"The name of the current item's ammo"
);
Event evi_equip
(
"equip",
EV_DEFAULT,
"sSSSSSSSSS",
"use use use use use use use use use use",
"Which ways you can use this item"
);
Event evi_checkammo
(
"checkammo",
EV_DEFAULT,
"b",
"bool",
"Check if the weapon has ammo before using it"
);
Event evi_command
(
"command",
EV_DEFAULT,
"s",
"command",
"Command to execute"
);
Event evi_model
(
"invmodel",
EV_DEFAULT,
"s",
"name",
"Which model this item is"
);
Event evi_anim
(
"invanim",
EV_DEFAULT,
"s",
"anim",
"Which anim this item uses"
);
Event evi_scale
(
"invscale",
EV_DEFAULT,
"f",
"scale",
"How much to scale the model"
);
Event evi_angles
(
"invangles",
EV_DEFAULT,
"v",
"angles",
"The orientation of the model"
);
Event evi_angledeltas
(
"invangledeltas",
EV_DEFAULT,
"v",
"angles",
"How to spin or bob the model"
);
Event evi_move
(
"invmove",
EV_DEFAULT,
"s",
"movetype",
"How to move the model when selected.\n either bob or spin"
);
Event evi_rotateoffset
(
"invrotateoffset",
EV_DEFAULT,
"v",
"offset",
"Offsets the origin of the model for rotation"
);
Event evi_offset
(
"invoffset",
EV_DEFAULT,
"v",
"offset",
"Offsets the origin of the model for moving"
);
Event evi_hudmodel
(
"hudmodel",
EV_DEFAULT,
"s",
"name",
"Which model this item is"
);
Event evi_hudanim
(
"hudanim",
EV_DEFAULT,
"s",
"anim",
"Which anim this item uses"
);
Event evi_hudscale
(
"hudscale",
EV_DEFAULT,
"f",
"scale",
"How much to scale the model"
);
Event evi_hudangles
(
"hudangles",
EV_DEFAULT,
"v",
"angles",
"The orientation of the model"
);
Event evi_hudangledeltas
(
"hudangledeltas",
EV_DEFAULT,
"v",
"angles",
"How to spin or bob the model"
);
Event evi_hudmove
(
"hudmove",
EV_DEFAULT,
"s",
"movetype",
"How to move the model when selected.\n either bob or spin"
);
Event evi_hudcompassangles
(
"hudcompassangles",
EV_DEFAULT,
NULL,
NULL,
"Applies the special case compass angles to the model\n"
);
Event evi_hudcompassneedleangles
(
"hudcompassneedleangles",
EV_DEFAULT,
NULL,
NULL,
"Applies the special case compass needle angles to the model\n"
);
Event evi_hudrotateoffset
(
"hudrotateoffset",
EV_DEFAULT,
"v",
"offset",
"Offsets the origin of the model for rotation"
);
Event evi_hudoffset
(
"hudoffset",
EV_DEFAULT,
"v",
"offset",
"Offsets the origin of the model for moving"
);
Event evi_bgshader
(
"bgshader",
EV_DEFAULT,
"s",
"shader",
"Shader to draw on the background of the item widget"
);
Event evi_barshader
(
"barshader",
EV_DEFAULT,
"s",
"shader",
"Shader to draw on the background of the item widget to display ammo counts"
);
Event evi_selitemshader
(
"selitem_shader",
EV_DEFAULT,
"s",
"shader",
"The shader for an item that is currently selected in the class submenu"
);
Event evi_selitemshaderontop
(
"selitem_shaderontop",
EV_DEFAULT,
NULL,
NULL,
"Whether the sel shader should be rendered after the model"
);
Event evi_modelwindow
(
"modelwindow",
EV_DEFAULT,
"ffff",
"x y width height",
"Specifies the dimensions of the model window for the inventory in normalized coordinates"
);
CLASS_DECLARATION(Listener, invlistener, NULL) {
{&evi_inv_width, &invlistener::InvWidth },
{&evi_inv_height, &invlistener::InvHeight },
{&evi_inv_vertical_offset, &invlistener::InvVertOffset },
{&evi_inv_horizontal_offset, &invlistener::InvHorizOffset },
{&evi_inv_selectsound, &invlistener::InvSelectSound },
{&evi_inv_rejectsound, &invlistener::InvRejectSound },
{&evi_inv_changesound, &invlistener::InvChangeSound },
{&evi_inv_align, &invlistener::InvAlign },
{&evi_inv_cascade, &invlistener::InvCascade },
{&evi_typedef, &invlistener::Typedef },
{&evi_openbrace, &invlistener::OpenBrace },
{&evi_closebrace, &invlistener::CloseBrace },
{&evi_button_shader, &invlistener::ButtonShader },
{&evi_hover_shader, &invlistener::HoverShader },
{&evi_sel_shader, &invlistener::SelShader },
{&evi_bg, &invlistener::Background },
{&evi_bg_tile, &invlistener::BackgroundTile },
{&evi_width, &invlistener::Width },
{&evi_height, &invlistener::Height },
{&evi_barwidth, &invlistener::BarWidth },
{&evi_barheight, &invlistener::BarHeight },
{&evi_baroffsetx, &invlistener::BarOffsetX },
{&evi_baroffsety, &invlistener::BarOffsetY },
{&evi_item, &invlistener::Item },
{&evi_ammo, &invlistener::Ammo },
{&evi_equip, &invlistener::Equip },
{&evi_checkammo, &invlistener::CheckAmmo },
{&evi_command, &invlistener::Command },
{&evi_bgshader, &invlistener::BGShader },
{&evi_barshader, &invlistener::BarShader },
{&evi_selitemshader, &invlistener::SelItemShader },
{&evi_selitemshaderontop, &invlistener::SelItemShaderOnTop },
{&evi_modelwindow, &invlistener::ModelWindow },
{&evi_model, &invlistener::Model },
{&evi_anim, &invlistener::Anim },
{&evi_move, &invlistener::Move },
{&evi_rotateoffset, &invlistener::RotateOffset },
{&evi_offset, &invlistener::Offset },
{&evi_scale, &invlistener::Scale },
{&evi_angles, &invlistener::Angles },
{&evi_angledeltas, &invlistener::AngleDeltas },
{&evi_hudmodel, &invlistener::HudModel },
{&evi_hudanim, &invlistener::HudAnim },
{&evi_hudmove, &invlistener::HudMove },
{&evi_hudcompassangles, &invlistener::HudCompassAngles },
{&evi_hudcompassneedleangles, &invlistener::HudCompassNeedleAngles},
{&evi_hudrotateoffset, &invlistener::HudRotateOffset },
{&evi_hudoffset, &invlistener::HudOffset },
{&evi_hudscale, &invlistener::HudScale },
{&evi_hudangles, &invlistener::HudAngles },
{&evi_hudangledeltas, &invlistener::HudAngleDeltas },
{NULL, NULL }
};
invlistener::invlistener(inventory_t *i)
{
inv = i;
curtype = 0;
}
invlistener::invlistener() {}
void invlistener::verify_curitem(void)
{
if (!curitem) {
throw "no current item";
}
}
void invlistener::verify_curtype(void)
{
if (!curtype) {
throw "no current type";
}
}
void invlistener::verify_one_arg(Event *ev)
{
if (ev->NumArgs() != 1) {
throw "bad arg count";
}
}
bool invlistener::Load(Script& script)
{
str token;
str errortext;
while (script.TokenAvailable(true)) {
token = script.GetToken(true);
if (!token.length() || !ValidEvent(token)) {
throw "invalid token";
}
Event *event = new Event(token);
while (script.TokenAvailable(false)) {
event->AddToken(script.GetToken(false));
}
ProcessEvent(event);
}
return true;
}
bool CL_LoadInventory(const char *filename, inventory_t *inv)
{
Script script;
Com_Printf("Loading inventory...\n");
inv->Clear();
invlistener listener(inv);
// Load the inventory file
script.LoadFile(filename);
return listener.Load(script);
}
inventory_t::inventory_t()
{
typewidth = 64;
typeheight = 64;
horizoffset = 0;
vertoffset = 0;
align = INV_ALIGN_RIGHT;
cascade = INV_CASCADE_LEFT;
}
inventory_t::~inventory_t()
{
Clear();
}
inventory_t::inventory_t(const inventory_t& other)
{
typewidth = other.typewidth;
typeheight = other.typeheight;
horizoffset = other.horizoffset;
vertoffset = other.vertoffset;
align = other.align;
cascade = other.cascade;
rejectsound = other.rejectsound;
selectsound = other.selectsound;
changesound = other.changesound;
types = other.types;
}
inventory_t& inventory_t::operator=(const inventory_t& other)
{
Clear();
typewidth = other.typewidth;
typeheight = other.typeheight;
horizoffset = other.horizoffset;
vertoffset = other.vertoffset;
align = other.align;
cascade = other.cascade;
rejectsound = other.rejectsound;
selectsound = other.selectsound;
changesound = other.changesound;
types = other.types;
return *this;
}
void inventory_t::Clear()
{
types.ClearObjectList();
}
void invlistener::InvAlign(Event *ev)
{
str side;
verify_one_arg(ev);
side = ev->GetString(1);
if (!str::icmp(side, "left")) {
inv->align = INV_ALIGN_LEFT;
} else if (!str::icmp(side, "right")) {
inv->align = INV_ALIGN_RIGHT;
} else {
warning(__FUNCTION__, "Invalid align side '%s'\n", side.c_str());
}
}
void invlistener::InvCascade(Event *ev)
{
str side;
verify_one_arg(ev);
side = ev->GetString(1);
if (!str::icmp(side, "left")) {
inv->cascade = INV_CASCADE_LEFT;
} else if (!str::icmp(side, "right")) {
inv->cascade = INV_CASCADE_RIGHT;
} else {
warning(__FUNCTION__, "Invalid cascade side '%s'\n", side.c_str());
}
}
void invlistener::InvWidth(Event *ev)
{
verify_one_arg(ev);
inv->typewidth = ev->GetInteger(1);
}
void invlistener::InvHeight(Event *ev)
{
verify_one_arg(ev);
inv->typeheight = ev->GetInteger(1);
}
void invlistener::InvVertOffset(Event *ev)
{
verify_one_arg(ev);
inv->vertoffset = ev->GetInteger(1);
}
void invlistener::InvHorizOffset(Event *ev)
{
verify_one_arg(ev);
inv->horizoffset = ev->GetInteger(1);
}
void invlistener::InvSelectSound(Event *ev)
{
verify_one_arg(ev);
inv->selectsound = ev->GetString(1);
}
void invlistener::InvRejectSound(Event *ev)
{
verify_one_arg(ev);
inv->rejectsound = ev->GetString(1);
}
void invlistener::InvChangeSound(Event *ev)
{
verify_one_arg(ev);
inv->changesound = ev->GetString(1);
}
void invlistener::Typedef(Event *ev)
{
str type;
inventory_type_t *t;
verify_one_arg(ev);
type = ev->GetString(1);
t = new inventory_type_t();
t->name = type;
t->bg_tile = false;
curtype = t;
curitem = NULL;
defaultWidth = 0;
defaultHeight = 0;
defaultBarWidth = 0;
defaultBarHeight = 0;
defaultBarOffsetX = 0;
defaultBarOffsetY = 0;
inv->types.AddObject(t);
}
void invlistener::OpenBrace(Event *ev) {}
void invlistener::CloseBrace(Event *ev) {}
void invlistener::ButtonShader(Event *ev)
{
verify_one_arg(ev);
verify_curtype();
curtype->texture = uWinMan.RegisterShader(ev->GetString(1));
}
void invlistener::HoverShader(Event *ev)
{
verify_one_arg(ev);
verify_curtype();
curtype->hoverTexture = uWinMan.RegisterShader(ev->GetString(1));
}
void invlistener::SelShader(Event *ev)
{
verify_one_arg(ev);
verify_curtype();
curtype->selTexture = uWinMan.RegisterShader(ev->GetString(1));
}
void invlistener::Background(Event *ev)
{
verify_one_arg(ev);
verify_curtype();
curtype->bg = uWinMan.RegisterShader(ev->GetString(1));
}
void invlistener::BackgroundTile(Event *ev)
{
verify_one_arg(ev);
verify_curtype();
curtype->bg = uWinMan.RegisterShader(ev->GetString(1));
curtype->bg_tile = true;
}
void invlistener::BGShader(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->bgshader = uWinMan.RegisterShader(ev->GetString(1));
}
void invlistener::SelItemShader(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->selshader = uWinMan.RegisterShader(ev->GetString(1));
}
void invlistener::SelItemShaderOnTop(Event *ev)
{
verify_curitem();
curitem->selShaderOnTop = true;
}
void invlistener::BarShader(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->barshader = uWinMan.RegisterShader(ev->GetString(1));
}
void invlistener::Width(Event *ev)
{
verify_one_arg(ev);
if (curitem) {
curitem->width = ev->GetInteger(1);
} else {
defaultWidth = ev->GetInteger(1);
}
}
void invlistener::Height(Event *ev)
{
verify_one_arg(ev);
if (curitem) {
curitem->height = ev->GetInteger(1);
} else {
defaultHeight = ev->GetInteger(1);
}
}
void invlistener::BarWidth(Event *ev)
{
verify_one_arg(ev);
if (curitem) {
curitem->barwidth = ev->GetInteger(1);
} else {
defaultBarWidth = ev->GetInteger(1);
}
}
void invlistener::BarHeight(Event *ev)
{
verify_one_arg(ev);
if (curitem) {
curitem->barheight = ev->GetInteger(1);
} else {
defaultBarHeight = ev->GetInteger(1);
}
}
void invlistener::BarOffsetY(Event *ev)
{
verify_one_arg(ev);
if (curitem) {
curitem->baroffsetY = ev->GetInteger(1);
} else {
defaultBarOffsetY = ev->GetInteger(1);
}
}
void invlistener::BarOffsetX(Event *ev)
{
verify_one_arg(ev);
if (curitem) {
curitem->baroffsetX = ev->GetInteger(1);
} else {
defaultBarOffsetX = ev->GetInteger(1);
}
}
void invlistener::Item(Event *ev)
{
str type;
inventory_item_t *item;
verify_one_arg(ev);
verify_curtype();
item = new inventory_item_t();
item->name = ev->GetString(1);
item->width = defaultWidth;
item->height = defaultHeight;
item->barwidth = defaultBarWidth;
item->barheight = defaultBarHeight;
item->baroffsetX = defaultBarOffsetX;
item->baroffsetY = defaultBarOffsetY;
item->equip = 8;
curtype->items.AddObject(item);
curitem = curtype->items.ObjectAt(curtype->items.NumObjects());
}
void invlistener::Ammo(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->ammoname = ev->GetString(1);
}
void invlistener::RotateOffset(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->invprops.rotateoffset = ev->GetVector(1);
}
void invlistener::HudRotateOffset(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->hudprops.rotateoffset = ev->GetVector(1);
}
void invlistener::Offset(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->invprops.offset = ev->GetVector(1);
}
void invlistener::HudOffset(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->hudprops.offset = ev->GetVector(1);
}
void invlistener::Command(Event *ev)
{
verify_curitem();
if (ev->NumArgs() <= 0) {
throw "command needs one or more args";
}
curitem->command = ev->GetString(1);
}
void invlistener::CheckAmmo(Event *ev)
{
verify_one_arg(ev);
curitem->checkammo = ev->GetBoolean(1);
}
void invlistener::Equip(Event *ev)
{
int i;
verify_curitem();
if (ev->NumArgs() <= 0) {
throw "command needs one or more args";
}
curitem->equip = 0;
for (i = 1; i <= ev->NumArgs(); i++) {
str equipstr = ev->GetString(i);
int tab;
for (tab = 0; s_equipTable[tab].string; tab++) {
if (equipstr == s_equipTable[tab].string) {
curitem->equip |= s_equipTable[tab].value;
break;
}
}
if (!s_equipTable[tab].string) {
throw "bad equip arguments";
}
}
}
void invlistener::Model(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->invprops.model = ev->GetString(1);
}
void invlistener::ModelWindow(Event *ev)
{
if (ev->NumArgs() != 4) {
throw "ModelWindow: bad arg count";
}
verify_curitem();
curitem->modelWindowX = ev->GetFloat(1);
curitem->modelWindowY = ev->GetFloat(2);
curitem->modelWindowWidth = ev->GetFloat(3);
curitem->modelWindowHeight = ev->GetFloat(4);
}
void invlistener::HudModel(Event *ev)
{
verify_one_arg(ev);
verify_one_arg(ev);
verify_curitem();
curitem->hudprops.model = ev->GetString(1);
}
void invlistener::Anim(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->invprops.anim = ev->GetString(1);
}
void invlistener::HudAnim(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->hudprops.anim = ev->GetString(1);
}
void invlistener::Scale(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->invprops.scale = ev->GetFloat(1);
}
void invlistener::HudScale(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->hudprops.scale = ev->GetFloat(1);
}
void invlistener::Angles(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->invprops.angles = ev->GetVector(1);
}
void invlistener::HudAngles(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->hudprops.angles = ev->GetVector(1);
}
void invlistener::AngleDeltas(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->invprops.angledeltas = ev->GetVector(1);
}
void invlistener::HudAngleDeltas(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
curitem->hudprops.angledeltas = ev->GetVector(1);
}
void invlistener::Move(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
str arg = ev->GetString(1);
if (arg == "bob") {
curitem->invprops.move = INV_MOVE_BOB;
} else if (arg == "spin") {
curitem->invprops.move = INV_MOVE_SPIN;
} else {
throw "bad move arguments";
}
}
void invlistener::HudMove(Event *ev)
{
verify_one_arg(ev);
verify_curitem();
str arg = ev->GetString(1);
if (arg == "bob") {
curitem->hudprops.move = INV_MOVE_BOB;
} else if (arg == "spin") {
curitem->hudprops.move = INV_MOVE_SPIN;
} else {
throw "bad move arguments";
}
}
void invlistener::HudCompassAngles(Event *ev)
{
verify_curitem();
curitem->anglesType = INV_HUDANGLES_COMPASS;
}
void invlistener::HudCompassNeedleAngles(Event *ev)
{
verify_curitem();
curitem->anglesType = INV_HUDANGLES_COMPASS_NEEDLE;
}
inventory_item_t *CL_GetInvItemByName(inventory_t *inv, const char *name)
{
if (!inv) {
return NULL;
}
for (int i = 1; i <= inv->types.NumObjects(); i++) {
const inventory_type_t *type = inv->types.ObjectAt(i);
for (int ii = 1; ii <= type->items.NumObjects(); ii++) {
inventory_item_t *item = type->items.ObjectAt(i);
if (!item) {
return NULL;
}
if (!str::icmp(item->name, name)) {
return item;
}
}
}
return NULL;
}
qboolean CL_HasInventoryItem(const char *name)
{
int i;
for (i = 2; i < 6; i++) {
int index = cl.snap.ps.activeItems[i];
if (index > 0) {
if (!str::icmp(name, CL_ConfigString(CS_WEAPONS + index))) {
return true;
}
}
}
return false;
}
void CL_AmmoCount(const char *name, int *ammo_count, int *max_ammo_count)
{
int i;
*ammo_count = 0;
*max_ammo_count = 0;
for (i = 0; i < ARRAY_LEN(cl.snap.ps.ammo_name_index); i++) {
int index = cl.snap.ps.ammo_name_index[i];
if (index) {
if (!str::icmp(name, CL_ConfigString(CS_WEAPONS + index))) {
*ammo_count = cl.snap.ps.ammo_amount[i];
*max_ammo_count = cl.snap.ps.max_ammo_amount[i];
break;
}
}
}
}
|