version "4.10" const HDLD_KIRI_GRETCHENCOUNTER = "kgc"; class GretchenCounter : HDWeapon { default { +weapon.wimpy_weapon; +inventory.invbar; +hdweapon.droptranslation; +hdweapon.fitsinbackpack; hdweapon.barrelsize 0,0,0; weapon.selectionorder 1014; scale 0.6; inventory.icon "SARGF1"; inventory.pickupmessage "Picked up a Gretchen Counter."; inventory.pickupsound "derp/crawl"; translation 0; tag "Gretchen Counter"; hdweapon.refid HDLD_KIRI_GRETCHENCOUNTER; } float lastReading; float angularVelocity; float needlePosition; int framesSinceLastBeep; override double WeaponBulk() { return 20; } override bool AddSpareWeapon(actor newowner) { return AddSpareWeaponRegular(newowner); } override hdweapon GetSpareWeapon(actor newowner,bool reverse,bool doselect) { return GetSpareWeaponRegular(newowner,reverse,doselect); } states { spawn: SARG F -1; stop; // Needle overlay states. needle_indicator: KGCN A 1; wait; select0: KGCM A 1; goto select0big; deselect0: KGCM A 1; goto deselect0big; ready: KGCM A 1 { A_Overlay(355, "needle_indicator"); A_OverlayPivotAlign(355, PSPA_CENTER, PSPA_BOTTOM); UpdateDisplay(); A_WeaponReady(WRF_NOFIRE | WRF_ALLOWUSER3); // USER3 = MagManager. } goto readyend; readyend: #### # 0 A_ReadyEnd(); #### # 0 A_Jump(256,"ready"); } action float GetReadingForType(String type_name, float distance_scale) { ThinkerIterator iter = ThinkerIterator.Create(type_name); Actor mo; float totalReading = 0.0; while(mo = Actor(iter.Next())) { //shardCount++; float dist = Distance3D(mo); // Convert to "meters" (with a minimum). if(dist < 32) { dist = 32; } // Scale distance. dist *= distance_scale; console.printf("%s", type_name); totalReading += 1.0 / (dist * dist); } return totalReading; } // override void Tick() // { // super.Tick(); // UpdateDisplay(); // } action void UpdateDisplay() { float angle_min = -45.0; float angle_max = 45.0; // console.printf("kjsdcsjkdcnsdjkcnsdkjcnsdc"); // ThinkerIterator iter = ThinkerIterator.Create("BFGNecroShard"); // Actor mo; // int shardCount = 0; // float totalReading = 0.0; // while(mo = BFGNecroShard(iter.Next())) // { // //shardCount++; // float dist = Distance3D(mo); // // Convert to "meters" (with a minimum). // if(dist < 32) { // dist = 32; // } // dist /= 32.0; // // // Arbitrary scaling. // // dist /= 16.0; // totalReading += 1.0 / (dist * dist); // shardCount += 1; // } float totalReading = GetReadingForType("BFGNecroShard", 1.0) + GetReadingForType("HDBarrel", 2.0); // invoker.lastReading = totalReading * 0.01 + invoker.lastReading * 0.99; float pct_reading = invoker.lastReading * 2000.0; invoker.lastReading = totalReading; float r = frandom(0.0, 1.0); if(r < pct_reading) { console.printf("test: %f %f", r, pct_reading); A_StartSound("kiri/gretchencounter_click"); } // if(pct_reading > 1.0) { // pct_reading = 1.0; // } String meter_str = ""; float k; for(k = 0.0; k < 1.0; k += 0.02) { if(k < pct_reading) { meter_str = meter_str.."#"; } else { meter_str = meter_str.."_"; } } // if(pct_reading > 1.0) { // pct_reading = 1.0; // } // A_OverlayRotate(355, // angle_min + (angle_max - angle_min) * (1.0 - pct_reading)); invoker.angularvelocity += pct_reading - invoker.needlePosition; invoker.angularvelocity *= 0.97; bool wasNeedleAtMax = (invoker.needlePosition >= 0.9); invoker.needlePosition += invoker.angularvelocity * 0.1; invoker.needlePosition = clamp(invoker.needlePosition, 0.0, 1.0); A_OverlayRotate(355, angle_min + (angle_max - angle_min) * (1.0 - invoker.needlePosition)); console.printf("Ang vel %f", invoker.angularvelocity); console.printf("Shard count: [%s] %f", meter_str, pct_reading); invoker.framesSinceLastBeep++; if((!wasNeedleAtMax || invoker.framesSinceLastBeep > 15) && invoker.needlePosition >= 0.9) { A_StartSound("kiri/gretchencounter_blip"); invoker.framesSinceLastBeep = 0; } } }