Advertisement
Guest User

Untitled

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