Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.37 KB | None | 0 0
  1. const HDCONST_BPMAX=1000;
  2. class HDGearCrate : HDBackpack
  3. {
  4. int index;
  5.  
  6. array<string> nicenames;
  7. array<string> refids;
  8. array<string> invclasses;
  9.  
  10. array<string> amounts;
  11. default{
  12. //$Category "Items/Hideous Destructor/Gear"
  13. //$Title "Gear Crate"
  14. //$Sprite "BPAKA0"
  15.  
  16. -inventory.invbar +weapon.wimpy_weapon
  17. +weapon.no_auto_switch
  18. +hdweapon.droptranslation
  19. -hdweapon.fitsinbackpack
  20. +hdweapon.alwaysshowstatus
  21. weapon.selectionorder 1010;
  22. inventory.icon "GRCRB0";
  23. inventory.pickupmessage "Picked up a backpack to help fill your life with ammo!";
  24. inventory.pickupsound "weapons/pocket";
  25.  
  26. tag "gearcrate";
  27. hdweapon.refid HDLD_GERCRTE;
  28. }
  29. override void DropOneAmmo(int amt){
  30. if(owner){
  31. RemoveFromBackpack(index,false);
  32. if(
  33. havenone(index)
  34. &&(
  35. !findinventory(invclasses[index])
  36. ||(
  37. hdweapon(findinventory(invclasses[index]))
  38. &&!hdweapon(findinventory(invclasses[index])).bfitsinbackpack
  39. )
  40. )
  41. )updatemessage(index+1);
  42. }
  43. }
  44.  
  45. int bpindex;
  46. int maxindex;
  47. override void InitializeWepStats(bool idfa){
  48. if(idfa)return;
  49. nicenames.clear();
  50. refids.clear();
  51. invclasses.clear();
  52. for(int i=0;i<allactorclasses.size();i++){
  53. class<actor> reff=allactorclasses[i];
  54. string ref="";
  55. string nnm="";
  56. if(reff is "HDPickup"){
  57. let gdb=getdefaultbytype((class<hdpickup>)(reff));
  58. if(gdb.bfitsinbackpack){
  59. nnm=gdb.gettag();
  60. if(nnm==gdb.getclassname())nnm="";
  61. ref=gdb.refid;
  62. }
  63. }else if(reff is "HDWeapon"){
  64. let gdb=getdefaultbytype((class<hdweapon>)(reff));
  65. if(gdb.bfitsinbackpack){
  66. nnm=gdb.gettag();
  67. if(nnm==gdb.getclassname())nnm="";
  68. ref=gdb.refid;
  69. }
  70. }
  71. if(nnm!=""){
  72. invclasses.push(reff.getclassname());
  73. nicenames.push(nnm);
  74. refids.push(ref);
  75. amounts.push("");
  76. }
  77. }
  78. bpindex=invclasses.find(getclassname());
  79. maxindex=invclasses.size()-1;
  80. }
  81. void initializeamount(string loadlist){
  82. array<string> whichitem;whichitem.clear();
  83. array<string> howmany;howmany.clear();
  84. loadlist.replace(" ","");
  85. loadlist.split(whichitem,",");
  86. for(int i=0;i<whichitem.size();i++){
  87. howmany.push((whichitem[i].mid(3,whichitem[i].length())));
  88. whichitem[i]=whichitem[i].left(3);
  89. }
  90. string weapondefaults="";
  91. if(owner&&owner.player)weapondefaults=hdweapon.getdefaultcvar(owner.player);
  92. for(int i=0;i<whichitem.size();i++){
  93. string ref=whichitem[i].makelower();
  94. if(ref=="")continue;
  95. int refindex=refids.find(ref);
  96. if(refindex>=refids.size())continue;
  97.  
  98. let wep=(class<hdweapon>)(invclasses[refindex]);
  99. let mag=(class<hdmagammo>)(invclasses[refindex]);
  100. let pkgv=(class<hdpickupgiver>)(invclasses[refindex]);
  101. let pkup=(class<hdpickup>)(invclasses[refindex]);
  102.  
  103. int howmanyi=max(1,howmany[i].toint());
  104. if(wep||mag){
  105. for(int j=0;j<howmanyi;j++){
  106. inventory iii=inventory(spawn(invclasses[refindex],pos,ALLOW_REPLACE));
  107. if(hdweapongiver(iii)){
  108. hdweapongiver(iii).spawnactualweapon();
  109. let newwep=hdweapongiver(iii).actualweapon;
  110. itemtobackpack(newwep);
  111. }else{
  112. if(wep){
  113. hdweapon(iii).loadoutconfigure(weapondefaults);
  114. hdweapon(iii).loadoutconfigure(howmany[i]);
  115. A_Log(howmany[i].." "..hdweapon(iii).bfitsinbackpack);
  116. }
  117. itemtobackpack(iii);
  118. }
  119. if(iii)iii.destroy();
  120. }
  121. }else if(pkgv){
  122. for(int j=0;j<howmanyi;j++){
  123. inventory iii=inventory(spawn(invclasses[refindex],pos,ALLOW_REPLACE));
  124. hdpickupgiver(iii).spawnactualitem();
  125. itemtobackpack(hdpickupgiver(iii).actualitem);
  126. if(iii)iii.destroy();
  127. }
  128. }else if(pkup){
  129. let iii=spawn(invclasses[refindex],pos,ALLOW_REPLACE);
  130. if(iii){
  131. iii.destroy();
  132. double bulkmax=(HDCONST_BPMAX-bulk)/max(1,getdefaultbytype(pkup).bulk);
  133. int addamt=max(1,min(bulkmax,howmanyi));
  134. if(addamt>0){
  135. int amt=amounts[refindex].toint(10);
  136. amounts[refindex]=""..amt+addamt;
  137. updatemessage(index);
  138. }
  139. }
  140. }
  141. }
  142. }
  143.  
  144. double bulk;
  145. override double weaponbulk(){
  146. double blk=0;
  147. for(int i=0;i<invclasses.size();i++){
  148. if(havenone(i))continue;
  149. class<actor> reff=invclasses[i];
  150. array<string> theseamounts;
  151. theseamounts.clear();
  152. if(((class<hdmagammo>)(reff))){
  153. amounts[i].split(theseamounts," ");
  154. let mmm=getdefaultbytype((class<hdmagammo>)(reff));
  155. bool armour=!!((class<HDArmour>)(reff));
  156. bool usemagbulk=(mmm.magbulk>0||mmm.roundbulk>0);
  157. for(int j=0;j<theseamounts.size();j++){
  158. int thamt=theseamounts[j].toint();
  159. if(armour)blk+=thamt>=1000?ENC_BATTLEARMOUR:ENC_GARRISONARMOUR;
  160. else{
  161. if(usemagbulk)blk+=mmm.magbulk+thamt*mmm.roundbulk;
  162. else blk+=mmm.bulk;
  163. }
  164. }
  165. if(!blk)blk=mmm.bulk*theseamounts.size();
  166. }else if(((class<hdweapon>)(reff))){
  167. amounts[i].split(theseamounts," ");
  168. for(int j=0;j<theseamounts.size();j++){
  169. if(!((j+1)%9))blk+=theseamounts[j].toint();
  170. }
  171. }else if(((class<hdpickup>)(reff))){
  172. let classref=((class<hdpickup>)(reff));
  173. //presets required for default ammos because of One Man Army
  174. double unitbulk;
  175. if(classref is "HDShellAmmo")unitbulk=ENC_SHELL;
  176. else if(classref is "FourMilAmmo")unitbulk=ENC_426;
  177. else if(classref is "SevenMilAmmo")unitbulk=ENC_776;
  178. else if(classref is "HDPistolAmmo")unitbulk=ENC_9;
  179. else if(classref is "HDRocketAmmo")unitbulk=ENC_ROCKET;
  180. else if(classref is "HDBattery")unitbulk=ENC_BATTERY;
  181. else if(classref is "BrontornisRound")unitbulk=ENC_BRONTOSHELL;
  182. else if(classref is "HEATAmmo")unitbulk=ENC_HEATROCKET;
  183. else if(classref is "HDFragGrenadeAmmo")unitbulk=ENC_FRAG;
  184. else unitbulk=getdefaultbytype(classref).bulk;
  185. blk+=amounts[i].toint()*unitbulk;
  186. }
  187. }
  188. bulk=blk;
  189. return max(blk*0.7,100);
  190. }
  191.  
  192. int GetAmount(class<inventory> type){
  193. int thisindex=invclasses.find(type.getclassname());
  194. if(thisindex>=invclasses.size())return 0;
  195. if(amounts[thisindex]=="")return 0;
  196. let wep=(class<hdweapon>)(type);
  197. let mag=(class<hdmagammo>)(type);
  198. let pkup=(class<hdpickup>)(type);
  199. if(wep||mag){
  200. array<string>amts;
  201. amounts[thisindex].split(amts," ");
  202. if(wep)return amts.size()/9;
  203. else return amts.size();
  204. }
  205. return amounts[thisindex].toint();
  206. }
  207. void AddAmount(class<inventory> type,int amt,int magamount=-1){
  208. let wep=(class<hdweapon>)(type);
  209. let mag=(class<hdmagammo>)(type);
  210. let pkup=(class<hdpickup>)(type);
  211. if((wep||mag)&&amt<1)return; //non-positive input for simple items only
  212. int thisindex=invclasses.find(type.getclassname());
  213. if(wep){
  214. for(int i=0;i<amt;i++){
  215. let itb=inventory(spawn(wep));
  216. itemtobackpack(itb);
  217. }
  218. return;
  219. }
  220. if(mag){
  221. if(magamount<0)magamount=getdefaultbytype(mag).maxperunit;
  222. else magamount=min(magamount,getdefaultbytype(mag).maxperunit);
  223. for(int i=0;i<amt;i++){
  224. string newamts=amounts[thisindex];
  225. if(havenone(thisindex))newamts=newamts.." ";
  226. newamts=newamts..magamount;
  227. amounts[thisindex]=newamts;
  228. }
  229. return;
  230. }
  231. if(pkup){
  232. int newamt=amounts[thisindex].toint()+amt;
  233. if(newamt<1)amounts[thisindex]="";
  234. else amounts[thisindex]=""..newamt;
  235. }
  236. }
  237.  
  238. int showindices[4];
  239. int selectedinbackpack;int selectedininventory;
  240. ui textureid,vector2 BPInvIcon(int which){
  241. let item=getdefaultbytype((class<inventory>),(invclasses[which]));
  242. let ddi=item.icon;
  243. vector2 ddv=(1.,1.);
  244.  
  245. //static virtuals aren't a thing, so any other exceptions will be going here :(
  246. string specicon="";
  247. if((HDArmour)(item)){
  248. specicon=amounts[which].toint()>=1000?"ARMCA0":"ARMSA0";
  249. }else if((HDWeapon)(item)){
  250. array<string> wepstatus;
  251. amounts[which].split(wepstatus," ");
  252. if(wepstatus.size()>=9){
  253. if((HDPistol)(item)){
  254. specicon=(wepstatus[0].toint()&PISF_SELECTFIRE)?"PISTC0":"PISTA0";
  255. }else if((ZM66AssaultRifle)(item)){
  256. string fr=(wepstatus[ZM66S_MAG].toint()<0)?"D":"A";
  257. int st=wepstatus[0].toint();
  258. if(!(st&ZM66F_NOLAUNCHER)){
  259. if(st&ZM66F_NOFIRESELECT)specicon="RIGS";
  260. else specicon="RIGL";
  261. }else if(st&ZM66F_NOFIRESELECT)specicon="RIFS";
  262. else specicon="RIFL";
  263. specicon=specicon..fr..0;
  264. }else if((LiberatorRifle)(item)){
  265. bool ul=(wepstatus[LIBS_MAG].toint()<0);
  266. int st=wepstatus[0].toint();
  267. if(st&LIBF_NOLAUNCHER)specicon=ul?"BRFLC0":"BRFLA0";
  268. else specicon=ul?"BRFLD0":"BRFLB0";
  269. }else if((HDSMG)(item)){
  270. specicon=(wepstatus[SMGS_MAG].toint()<0)?"SMGNB0":"SMGNA0";
  271. }
  272. }
  273. }
  274. if(specicon!="")ddi=texman.checkfortexture(specicon,texman.type_any);
  275.  
  276. if(!ddi){
  277. let dds=item.spawnstate;
  278. if(dds!=null)ddi=dds.GetSpriteTexture(0);
  279. }
  280. if(ddi){
  281. vector2 dds=texman.getscaledsize(ddi);
  282. if(min(dds.x,dds.y)<8.){
  283. ddv*=(8./min(dds.x,dds.y));
  284. }
  285. }
  286. return ddi,ddv;
  287. }
  288. override string,double getpickupsprite(){return "BPAKA0",1.;}
  289. override void DrawHUDStuff(HDStatusBar sb,HDWeapon hdw,HDPlayerPawn hpl){
  290. for(int i=0;i<4;i++){
  291. if(showindices[i]>=0){
  292. textureid bpi;vector2 bps;
  293. [bpi,bps]=BPInvIcon(showindices[i]);
  294. int xofs=-80;
  295. switch(i){
  296. case 1:xofs=-40;break;
  297. case 2:xofs=40;break;
  298. case 3:xofs=80;break;
  299. default:break;
  300. }
  301. if(bpi&&showindices[0]>=0)sb.drawtexture(bpi,(xofs,0),
  302. sb.DI_ITEM_CENTER|sb.DI_SCREEN_CENTER,
  303. alpha:amounts[showindices[0]]==""?0.3:0.6,
  304. scale:bps
  305. );
  306. }
  307. }
  308. //if(index>=0&&index<invclasses.size()){
  309. if(index>=0&&index<invclasses.size()){
  310. textureid bpi;vector2 bps;
  311. [bpi,bps]=BPInvIcon(index);
  312. if(bpi)sb.drawtexture(bpi,(0,0),
  313. sb.DI_ITEM_CENTER_BOTTOM|sb.DI_SCREEN_CENTER,
  314. alpha:amounts[index]==""?0.6:1.,
  315. scale:bps
  316. );
  317. sb.drawstring(
  318. sb.pSmallFont,nicenames[index],
  319. (0,18),sb.DI_SCREEN_CENTER|sb.DI_TEXT_ALIGN_CENTER,
  320. font.CR_FIRE
  321. );
  322. sb.drawstring(
  323. sb.pSmallFont,"In Backpack: "..selectedinbackpack,
  324. (-44,30),sb.DI_SCREEN_CENTER|sb.DI_TEXT_ALIGN_LEFT,
  325. selectedinbackpack?font.CR_BROWN:font.CR_DARKBROWN
  326. );
  327. sb.drawstring(
  328. sb.pSmallFont,"On Person: "..selectedininventory,
  329. (-44,38),sb.DI_SCREEN_CENTER|sb.DI_TEXT_ALIGN_LEFT,
  330. selectedininventory?font.CR_WHITE:font.CR_DARKGRAY
  331. );
  332. }
  333. }
  334. override string gethelptext(){
  335. return
  336. WEPHELP_FIRE.."/"..WEPHELP_ALTFIRE.." Previous/Next item\n"
  337. ..WEPHELP_FIREMODE.."+"..WEPHELP_UPDOWN.." Scroll through items\n"
  338. ..WEPHELP_RELOAD.." Insert\n"
  339. ..WEPHELP_UNLOAD.." Remove\n"
  340. ..WEPHELP_DROPONE.." Remove and drop\n"
  341. ..WEPHELP_ALTRELOAD.." Dump\n"
  342. ;
  343. }
  344. void UpdateMessage(int num){
  345. if(!owner)return;
  346. //set index as necessary
  347. int nnsiz=nicenames.size();
  348. if(num==index)weaponbulk();
  349. if(num!=index&&owner){
  350. int toadd=num>index?1:-1;
  351. do{
  352. index+=toadd;
  353. if(index>maxindex)index=0;
  354. else if(index<0)index=maxindex;
  355. }while(
  356. index!=bpindex
  357. &&havenone(index)
  358. &&(
  359. !owner.countinv(invclasses[index])
  360. ||(
  361. hdweapon(owner.findinventory(invclasses[index]))
  362. &&!hdweapon(owner.findinventory(invclasses[index])).bfitsinbackpack
  363. )
  364. )
  365. );
  366. }else if(max(0-num,num-nnsiz)<maxindex){
  367. while(num<0)num+=nnsiz;
  368. while(num>maxindex)num-=nnsiz;
  369. index=num;
  370. }
  371.  
  372. showindices[0]=-1;showindices[1]=-1;showindices[2]=-1;showindices[3]=-1;
  373. int bpindex=invclasses.find(getclassname());
  374. for(int i=1;i<nnsiz;i++){
  375. int plusi=index+i;
  376. if(plusi>=nnsiz)plusi-=nnsiz;
  377. if(
  378. !havenone(plusi)
  379. ||(
  380. owner.countinv(invclasses[plusi])
  381. &&(
  382. !hdweapon(owner.findinventory(invclasses[plusi]))
  383. ||hdweapon(owner.findinventory(invclasses[plusi])).bfitsinbackpack
  384. )
  385. )
  386. ){
  387. if(showindices[2]<0)showindices[2]=plusi;
  388. else if(showindices[3]<0)showindices[3]=plusi;
  389. }
  390.  
  391. plusi=index-i;
  392. if(plusi<0)plusi+=nnsiz;
  393. if(
  394. !havenone(plusi)
  395. ||(
  396. owner.countinv(invclasses[plusi])
  397. &&(
  398. !hdweapon(owner.findinventory(invclasses[plusi]))
  399. ||hdweapon(owner.findinventory(invclasses[plusi])).bfitsinbackpack
  400. )
  401. )
  402. ){
  403. if(showindices[1]<0)showindices[1]=plusi;
  404. else if(showindices[0]<0)showindices[0]=plusi;
  405. }
  406. }
  407. let thisinv=(class<inventory>)(invclasses[index]);
  408. selectedinbackpack=getamount(thisinv);
  409. selectedininventory=owner.countinv(thisinv);
  410.  
  411. //display selected item name and amounts carried
  412. wepmsg="\cs[] [] [] \cbBackpack \cs[] [] []\nfiremode=fast scroll unload/reload=take/insert\n\n"
  413. .."\n\nTotal Bulk: \cf"..int(bulk);
  414. }
  415. //generic code for inserting into backpack
  416. //return 1 to indicate a FAILED pickup
  417. int ItemToBackpack(inventory item){
  418. if(item==self&&amount<2)return 1;
  419. let wep=HDWeapon(item);
  420. let mag=HDMagAmmo(item);
  421. let pkup=HDPickup(item);
  422. if(!wep&&!pkup)return 1;
  423. if(
  424. (wep&&!wep.bfitsinbackpack)
  425. ||(pkup&&!pkup.bfitsinbackpack)
  426. )return 1;
  427. int newindex=invclasses.find(item.getclassname());
  428. if(newindex>=invclasses.size())return 1;
  429. index=newindex;
  430. UpdateMessage(newindex);
  431. if(wep){
  432. if(wep is "HDBackpack"&&HDBackpack(wep).bulk>0){
  433. if(owner)owner.A_Log("Empty this backpack first.",true);
  434. return 1;
  435. }
  436. if(wep.owner)wep=HDWeapon(owner.dropinventory(wep));
  437. string newwep=
  438. wep.weaponstatus[0].." "..
  439. wep.weaponstatus[1].." "..
  440. wep.weaponstatus[2].." "..
  441. wep.weaponstatus[3].." "..
  442. wep.weaponstatus[4].." "..
  443. wep.weaponstatus[5].." "..
  444. wep.weaponstatus[6].." "..
  445. wep.weaponstatus[7].." "..
  446. int(wep.weaponbulk())..
  447. (amounts[index]==""?"":" ");
  448. amounts[index]=newwep..amounts[index];
  449. if(hd_debug){
  450. A_Log(nicenames[index]..": "..wep.getclassname().." "..newwep);
  451. A_Log(amounts[index]);
  452. }
  453. wep.amount--;if(wep.amount<1)wep.destroy();
  454. weaponbulk();
  455. UpdateMessage(index);
  456. return 12;
  457. }
  458. int tookmag=mag.TakeMag(false);if(item.amount<1)item.destroy();
  459. if(amounts[index]=="")amounts[index]=""..tookmag;
  460. else amounts[index]=tookmag.." "..amounts[index];
  461. }else{
  462. int units=item.owner?1:item.amount;
  463. amounts[index]=""..max(0,amounts[index].toint())+units;
  464. item.amount-=units;if(item.amount<1)item.destroy();
  465. }
  466. weaponbulk();
  467. UpdateMessage(index);
  468. if(pkup.bmultipickup)return 4;else return 10;
  469. }
  470. //returns whether empty
  471. bool havenone(int which){
  472. return(
  473. amounts[which]==""
  474. ||(
  475. amounts[which].toint()<1
  476. &&!((class<HDMagAmmo>)(invclasses[which]))
  477. &&!((class<HDWeapon>)(invclasses[which]))
  478. )
  479. );
  480. }
  481. //generic code for removing from backpack
  482. int RemoveFromBackpack(int which=-1,bool trytopocket=true){
  483. if(which<0||which>=invclasses.size())which=index;
  484. if(havenone(which))return 1;
  485. array<string>tempamounts;
  486. bool basicpickup=false;
  487. amounts[which].split(tempamounts," ");
  488. if(tempamounts.size()<1)return 1;
  489. int ticks=0;
  490. let hdp=hdplayerpawn(owner);
  491. let wepth=(class<hdweapon>)(invclasses[which]);
  492. let thisclass=(class<hdpickup>)(invclasses[which]);
  493. if(wepth){
  494. let newp=HDWeapon(spawn(wepth,owner.pos+(0,0,owner.height-12),ALLOW_REPLACE));
  495. newp.angle=owner.angle;newp.A_ChangeVelocity(1,1,1,CVF_RELATIVE);
  496. for(int i=0;i<9;i++){
  497. if(i<newp.weaponstatus.size())newp.weaponstatus[i]=tempamounts[0].toint();
  498. tempamounts.delete(0);
  499. }
  500. if(trytopocket&&owner.countinv(wepth)<getdefaultbytype(wepth).maxamount){
  501. newp.actualpickup(owner);
  502. ticks=12;
  503. }else{
  504. ticks=10;
  505. if(newp.bdroptranslation)newp.translation=owner.translation;
  506. }
  507. }
  508. if(thisclass){
  509. int thisamt=max(0,tempamounts[0].toint());
  510. bool multipi=getdefaultbytype(thisclass).bmultipickup;
  511.  
  512. let mt=(class<HDMagAmmo>)(thisclass);
  513. if(
  514. owner.A_JumpIfInventory(thisclass,0,"null")
  515. ||HDPickup.MaxGive(owner,thisclass,
  516. mt?(getdefaultbytype(mt).roundbulk*getdefaultbytype(mt).maxperunit+getdefaultbytype(mt).magbulk)
  517. :getdefaultbytype(thisclass).bulk
  518. )<1
  519. )trytopocket=false;
  520.  
  521. if(mt){
  522. if(trytopocket)HDMagAmmo.GiveMag(owner,thisclass,thisamt);
  523. else HDMagAmmo.SpawnMag(owner,thisclass,thisamt);
  524. tempamounts.delete(0);
  525. }else{
  526. basicpickup=true;
  527. thisamt--;
  528. if(!trytopocket){
  529. int moar=0;
  530. if(multipi&&thisamt>0)moar=min(random(10,50),thisamt);
  531. let iii=inventory(spawn(thisclass,owner.pos+(0,0,owner.height-20),ALLOW_REPLACE));
  532. iii.angle=owner.angle;iii.vel=owner.vel;
  533. iii.A_ChangeVelocity(1,0,1,CVF_RELATIVE);
  534. iii.amount=1+moar;
  535. if(hdpickup(iii)&&hdpickup(iii).bdroptranslation)iii.translation=owner.translation;
  536. thisamt-=moar;
  537. }
  538. else HDF.Give(owner,thisclass,1);
  539. tempamounts[0]=""..thisamt;
  540. }
  541. //allow continuous move for smaller items
  542. if(multipi)ticks=6;else ticks=10;
  543. }
  544. //put the string back together
  545. string newamounts="";
  546. if(basicpickup){
  547. if(tempamounts[0].toint()>0)newamounts=tempamounts[0];
  548. }else{
  549. for(int i=0;i<tempamounts.size();i++){
  550. newamounts=newamounts..(i?" ":"")..tempamounts[i];
  551. }
  552. }
  553. amounts[which]=newamounts;
  554. if(havenone(which)&&!owner.countinv(invclasses[which]))UpdateMessage(which+1);
  555. UpdateMessage(index);
  556. return ticks;
  557. }
  558. //main interface
  559. string curamt;
  560. action void A_BPReady(){
  561. if(pressingfiremode()){
  562. int inputamt=player.cmd.pitch>>5;
  563. invoker.UpdateMessage(invoker.index-inputamt);
  564. HijackMouse();
  565. }
  566. int ttt=1;
  567. if(justpressed(BT_ATTACK))invoker.UpdateMessage(invoker.index-1);
  568. else if(justpressed(BT_ALTATTACK))invoker.UpdateMessage(invoker.index+1);
  569. else if(pressingreload()&&countinv(invoker.invclasses[invoker.index])){
  570. ttt=invoker.ItemToBackpack(findinventory(invoker.invclasses[invoker.index]));
  571. }else if(pressingunload()){
  572. ttt=invoker.RemoveFromBackpack(invoker.index,true);
  573. }else if(pressing(BT_ALTRELOAD)){
  574. invoker.RemoveFromBackpack(invoker.index,false);
  575. invoker.updatemessage(invoker.index+1);
  576. if(self is "HDPlayerPawn")ttt=randompick(0,0,0,0,0,1);
  577. if(!invoker.bulk){
  578. DropInventory(invoker);
  579. return;
  580. }
  581. }
  582. if(!pressing(BT_ALTRELOAD)){
  583. A_WeaponMessage(invoker.wepmsg,ttt+1);
  584. A_SetTics(max(1,ttt));
  585. }else A_SetTics(ttt);
  586. A_WeaponReady(
  587. WRF_NOFIRE|WRF_ALLOWUSER3
  588. |((player.cmd.buttons&(BT_RELOAD|BT_UNLOAD|BT_USE))?WRF_DISABLESWITCH:0)
  589. );
  590. }
  591. states{
  592. spawn:
  593. GRCR A -1 nodelay{
  594. invoker.weaponbulk();
  595. if(!invoker.bulk)frame=1;
  596. else if(target){
  597. translation=target.translation;
  598. frame=2;
  599. }
  600. invoker.bno_auto_switch=false;
  601. }
  602. select0:
  603. TNT1 A 10{
  604. A_PlaySound("weapons/pocket",CHAN_WEAPON);
  605. if(invoker.bulk>(HDBPC_CAPACITY*0.7))A_SetTics(20);
  606. invoker.index=clamp(invoker.index,0,invoker.maxindex);
  607. if(invoker.havenone(invoker.index))invoker.updatemessage(invoker.index+1);
  608. else invoker.UpdateMessage(invoker.index);
  609. }goto super::select0;
  610. ready:
  611. TNT1 A 1 A_BPReady();
  612. goto readyend;
  613. nope:
  614. TNT1 A 0 A_WeaponMessage(invoker.wepmsg,5);
  615. goto super::nope;
  616. }
  617. }
  618. enum HDBackpackItems{
  619. HDBPC_CAPACITY=1000,
  620. }
  621. //go through all backpacked items and call their respective Consolidate()s
  622. override void Consolidate(){
  623. for(int i=0;i<invclasses.size();i++){
  624. if(havenone(i))continue;
  625. let type=(class<hdpickup>)(invclasses[i]);
  626. if(!type)continue;
  627. int onperson=BPToInv(owner,type);
  628.  
  629. let thisinv=hdpickup(owner.findinventory(type));
  630. int maxinvbak=thisinv.maxamount;
  631. thisinv.maxamount=int.MAX;
  632.  
  633. thisinv.Consolidate();
  634.  
  635. //then put everything back
  636. if(thisinv.amount<1)return;
  637. int inbackpack=thisinv.amount-onperson;
  638. if(type is "HDMagAmmo"){
  639. let thismags=hdmagammo(thisinv);
  640. string ibp="";
  641. for(int i=0;i<inbackpack;i++){
  642. ibp=ibp..(ibp==""?"":" ")..thismags.mags[0];
  643. thismags.mags.delete(0);
  644. thismags.amount--;
  645. }
  646. amounts[i]=ibp;
  647. }else{
  648. amounts[i]=""..max(0,inbackpack);
  649. thisinv.amount=onperson;
  650. }
  651.  
  652. thisinv.maxamount=maxinvbak;
  653. }
  654. }
  655.  
  656. //increase maxamount by backpackamount
  657. //take backpack contents and put them in inventory
  658. //return original amount on person
  659. static int BPToInv(actor caller,class<inventory> type){
  660. int originalamount=caller.countinv(type);
  661. let bp=hdbackpack(caller.findinventory("hdbackpack"));
  662. if(
  663. bp
  664. &&bp.invclasses.find(type.getclassname())>=0
  665. ){
  666. int bpindex=bp.invclasses.find(type.getclassname());
  667. string addamt=bp.amounts[bpindex];
  668. if(addamt!=""){
  669. if(type is "HDMagAmmo"){
  670. array<string> bpmags;bpmags.clear();
  671. addamt.split(bpmags," ");
  672. hdmagammo onp=hdmagammo(caller.findinventory(type));
  673. for(int i=0;i<bpmags.size();i++){
  674. caller.A_GiveInventory(type,1);
  675. if(!onp){
  676. onp=hdmagammo(caller.findinventory(type));
  677. onp.mags.clear();
  678. }
  679. onp.maxamount=max(onp.maxamount,originalamount+bpmags.size());
  680. onp.mags.push(bpmags[i].toint());
  681. }
  682. }else if(type is "HDPickup"&&addamt.toint()>0){
  683. int bpamt=addamt.toint();
  684. let cfi=caller.findinventory(type);
  685. if(!cfi){
  686. cfi=caller.giveinventorytype(type);
  687. cfi.amount=0;
  688. }
  689. if(cfi){
  690. cfi.maxamount=max(cfi.maxamount,originalamount+bpamt);
  691. cfi.amount+=bpamt;
  692. }
  693. }
  694. }
  695. bp.amounts[bpindex]="";
  696. }
  697. return originalamount;
  698. }
  699. }
  700.  
  701. extend class HDGearCrate{
  702. bool DeleteItem(string invclass){
  703. int dexof=invclasses.find(invclass);
  704. if(
  705. dexof==invclasses.size()
  706. ||!amounts[dexof]
  707. ||amounts[dexof]==""
  708. )return false;
  709. amounts[dexof]="";
  710. return true;
  711. }
  712. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement