Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script "whip" (int f, int spwn, int spawnharm)
- { /* f = which frame, spwn = whether to spawn actors, spawnharm = whether to spawn harming actor at end of whip */
- /* points for quartic bezier curve for x offsets */
- int w_x[7][5] = { /* p0, p1, p2, p3, p4 */
- { 0.0, -82.0, 43.0, -60.0, -27.0 }, /* frame 0 */
- { 0.0, -99.0, -157.0, -42.0, -32.0 }, /* frame 1 */
- { 0.0, -15.0, -147.0, -52.0, -86.0 }, /* frame 2 */
- { 0.0, 58.0, -7.0, -55.0, -94.0 }, /* frame 3 */
- { 0.0, 139.0, 144.0, 93.0, 77.0 }, /* frame 4 */
- { 0.0, 138.0, 192.0, 176.0, 187.0 }, /* frame 5 */
- { 0.0, 212.0, 212.0, 212.0, 212.0 }, /* frame 6 */
- };
- /* points for quartic bezier curve for y offsets */
- int w_y[7][5] = { /* p0, p1, p2, p3, p4 */
- { 0.0, 0.0, 48.0, 0.0, 18.0 }, /* frame 0 */
- { 0.0, 0.0, 42.0, 0.0, 14.0 }, /* frame 1 */
- { 0.0, 0.0, 36.0, 0.0, 10.0 }, /* frame 2 */
- { 0.0, 0.0, 30.0, 0.0, 6.0 }, /* frame 3 */
- { 0.0, 0.0, 24.0, 0.0, 2.0 }, /* frame 4 */
- { 0.0, 0.0, 18.0, 0.0, -2.0 }, /* frame 5 */
- { 0.0, 0.0, 12.0, 0.0, -6.0 }, /* frame 6 */
- };
- /* points for quartic bezier curve for z offsets */
- int w_z[7][5] = { /* p0, p1, p2, p3, p4 */
- { 0.0, -9.0, -77.0, -83.0, -121.0 }, /* frame 0 */
- { 0.0, 91.0, -58.0, -12.0, -61.0 }, /* frame 1 */
- { 0.0, 110.0, 73.0, 0.0, 29.0 }, /* frame 2 */
- { 0.0, 57.0, 161.0, 49.0, 70.0 }, /* frame 3 */
- { 0.0, 20.0, 94.0, 72.0, 96.0 }, /* frame 4 */
- { 0.0, -10.0, 27.0, 51.0, 65.0 }, /* frame 5 */
- { 0.0, 6.0, 6.0, 6.0, 6.0 }, /* frame 6 */
- };
- int w_s[7] = { 0, 0, 0, 0, 0, 0, 0 }; /* scaling for each frame out of 100.0, 0 gets unused */
- int s_x, s_y, s_z, s_ang, s_pit, i_amt, f_amt, i, s_tid, stid_c, o_tid, a_tid;
- int s_xoff, s_yoff, s_zoff, xoff, yoff, zoff, off_ang, off_c;
- int b1_xoff, b1_yoff, b1_zoff, b2_xoff, b2_yoff, b2_zoff, b4_xoff, b4_yoff, b4_zoff;
- int t, t_2, t_3, t_4, tm, tm_2, tm_3, tm_4;
- int spawn_x, spawn_y, spawn_z;
- int scale, scale_d, p_num;
- int xp[5], yp[5], zp[5];
- s_xoff = 6.0; /*x offset to entire curve */
- s_yoff = 6.0; /*y offset to entire curve */
- s_zoff = 32.0; /*z offset to entire curve */
- i_amt = 30; /* how many actors to spawn over the range */
- f_amt = i_amt << 16;
- scale_d = 30.0; /* default applied scaling out of 100; 0 is not applied */
- /* get shooter player number */
- p_num = PlayerNumber();
- /* get shooter tid */
- s_tid = ActivatorTID();
- /* check if shooter tid is 0 (it doesn't have one) or there are more actors than the shooter with the tid */
- if(!s_tid || ThingCount(T_NONE,s_tid) > 1){
- o_tid = s_tid; /* save the old tid */
- s_tid = UniqueTID(); /* get a new one */
- Thing_ChangeTID(0, s_tid); /* change the activator's tid to the new one */
- stid_c = 1; } /* flag that we changed it */
- /* IF the player is crouching, halve the static z offset */
- if(GetActorViewHeight(s_tid) < GetActorProperty(0, APROP_ViewHeight)){ s_zoff = s_zoff / 2; }
- if(w_s[f]){ scale = w_s[f]; } /* apply frame specific scaling, if specified */
- else{ scale = scale_d; } /* if not, then apply default scaling */
- s_x = GetActorX(0); /* Get x position of player */
- s_y = GetActorY(0); /* and y position */
- s_z = GetActorZ(0); /* and z position */
- s_ang = GetActorAngle(0); /* and angle */
- s_pit = GetActorPitch(0); /* and pitch */
- /* grab the values for the points in the quartic bezier curves from the arrays */
- for(i = 0; i < 5; ++i){
- xp[i] = w_x[f][i];
- yp[i] = w_y[f][i];
- zp[i] = w_z[f][i]; }
- if(scale){ /* apply scaling if specified */
- for(i = 0; i < 5; ++i){
- xp[i] = FixedDiv(FixedMul(xp[i], scale), 100.0);
- yp[i] = FixedDiv(FixedMul(yp[i], scale), 100.0);
- zp[i] = FixedDiv(FixedMul(zp[i], scale), 100.0); }}
- /* now apply player pitch to static offsets */
- off_ang = VectorAngle(s_xoff, s_zoff) + s_pit;
- off_c = VectorLength(s_xoff, s_zoff);
- s_xoff = FixedMul(cos(off_ang), off_c);
- s_zoff = FixedMul(sin(off_ang), off_c);
- /* apply static offsets */
- for(i = 0; i < 5; ++i){
- xp[i] += s_xoff;
- yp[i] += s_yoff;
- zp[i] += s_zoff; }
- /* the calculation / spawning / user_var setting loop */
- for(i = 0; i < i_amt; ++i){
- /* calculation of bezier terms for the linear and quartic bezier curves below */
- t = FixedDiv((i << 16), f_amt); /* t ranges from 0 to 1 */
- t_2 = FixedMul(t, t); /* t^2 */
- t_3 = FixedMul(t_2, t); /* t^3 */
- t_4 = FixedMul(t_3, t); /* t^4 */
- tm = (1.0 - t); /* (1 - t) */
- tm_2 = FixedMul(tm, tm); /* (1 - t)^2 */
- tm_3 = FixedMul(tm_2, tm); /* (1 - t)^3 */
- tm_4 = FixedMul(tm_3, tm); /* (1 - t)^4 */
- /* linear bezier curves */
- b1_xoff = ( FixedMul(tm, xp[0]) + FixedMul(t, xp[4]) );
- b1_yoff = ( FixedMul(tm, yp[0]) + FixedMul(t, yp[4]) );
- b1_zoff = ( FixedMul(tm, zp[0]) + FixedMul(t, zp[4]) );
- /* quadratic bezier curves */
- b2_xoff = ( FixedMul(tm_2, xp[0]) + 2 * FixedMul(FixedMul(tm, t), xp[2]) + FixedMul(t_2, xp[4]) );
- b2_yoff = ( FixedMul(tm_2, yp[0]) + 2 * FixedMul(FixedMul(tm, t), yp[2]) + FixedMul(t_2, yp[4]) );
- b2_zoff = ( FixedMul(tm_2, zp[0]) + 2 * FixedMul(FixedMul(tm, t), zp[2]) + FixedMul(t_2, zp[4]) );
- /* quartic bezier curvess */
- b4_xoff = f_m(tm_4, xp[0]) + 4 * f_m(f_m(t, tm_3), xp[1]) + 6 * f_m(f_m(t_2, tm_2), xp[2]) + 4 * f_m(f_m(t_3, tm), xp[3]) + f_m(t_4, xp[4]);
- b4_yoff = f_m(tm_4, yp[0]) + 4 * f_m(f_m(t, tm_3), yp[1]) + 6 * f_m(f_m(t_2, tm_2), yp[2]) + 4 * f_m(f_m(t_3, tm), yp[3]) + f_m(t_4, yp[4]);
- b4_zoff = f_m(tm_4, zp[0]) + 4 * f_m(f_m(t, tm_3), zp[1]) + 6 * f_m(f_m(t_2, tm_2), zp[2]) + 4 * f_m(f_m(t_3, tm), zp[3]) + f_m(t_4, zp[4]);
- /* reminder thet f_m() is FixedMul() and f_d() is FixedDiv() */
- if(f == 6){ /* last frame uses linear curves for x an z offsets */
- xoff = b1_xoff;
- yoff = b2_yoff;
- zoff = b1_zoff; }
- else{
- xoff = b4_xoff;
- yoff = b2_yoff;
- zoff = b4_zoff; }
- /* now apply player pitch to calculated offsets */
- off_ang = VectorAngle(xoff, zoff) - s_pit;
- off_c = VectorLength(xoff, zoff);
- xoff = FixedMul(cos(off_ang), off_c);
- zoff = FixedMul(sin(off_ang), off_c);
- /* calculate the spawning position for anything the script should spawn... */
- if(spwn || /* IF the script should spawn actors instead of just changing their user_vars OR */
- (spawnharm && /* if the script should spawn harming actor at the and of the whip AND */
- (i == (i_amt - 1)))){ /* it's the last iteration of the spawning/calculating loop */
- /* apply offsets, note that this isn't strictly necessary for appearance since they will
- appear where they should because of A_Warp, but it's good to be thorough */
- /* now apply the x offset, if it isn't 0 */
- if(xoff > 0){
- spawn_x = s_x + FixedMul(cos(s_ang), xoff);
- spawn_y = s_y + FixedMul(sin(s_ang), xoff); }
- else if(xoff < 0){
- spawn_x = s_x - FixedMul(cos(s_ang), xoff);
- spawn_y = s_y - FixedMul(sin(s_ang), xoff); }
- /* and the y offset, if it isn't 0 */
- if(yoff > 0){
- spawn_x = s_x + FixedMul(cos(FixedAngMod(s_ang - 0.25)), yoff);
- spawn_y = s_y + FixedMul(sin(FixedAngMod(s_ang - 0.25)), yoff); }
- else if(yoff < 0){
- spawn_x = s_x + FixedMul(cos(FixedAngMod(s_ang + 0.25)), yoff);
- spawn_y = s_y + FixedMul(sin(FixedAngMod(s_ang + 0.25)), yoff); }
- /* and the z offset */
- spawn_z = s_z + zoff; }
- if(spwn){ /* if the script should spawn actors instead of just changing their user_vars */
- /* get a new tid to give to the actor */
- a_tid = UniqueTID();
- /* then store its in the array */
- arr_tid[p_num][i] = a_tid;
- /* and now spawn the actor */
- SpawnForced("TestActor", spawn_x, spawn_y, spawn_z, a_tid, s_ang);
- /* set the shooter to be it's target so that A_Warp functions correctly */
- SetActivator(a_tid); /* first you have to set it to the activator to use SetPointer */
- SetPointer(AAPTR_TARGET, s_tid); } /* then change its target to the shooter */
- /* change its user vars to the offsets calculated above */
- SetUserVariable(arr_tid[p_num][i],"user_xoff", xoff);
- SetUserVariable(arr_tid[p_num][i],"user_yoff", yoff);
- SetUserVariable(arr_tid[p_num][i],"user_zoff", zoff); }
- /* now, after the loop */
- if(spawnharm){ /* if the script should spawn harming actor at the and of the whip */
- /* get a new tid to give to the actor */
- a_tid = UniqueTID();
- /* spawn the harming actor */ /* NOTE: this is not currently in, and just spawns a regular actor */
- SpawnForced("TestActor", spawn_x, spawn_y, spawn_z, a_tid, s_ang);
- /* the spawn variables are still set to ones used in the last iteration of the above loop */
- /* set the shooter to be it's target so that it behaves like a normal projectile */
- SetActivator(a_tid); /* first you have to set it to the activator to use SetPointer */
- SetPointer(AAPTR_TARGET, s_tid); } /* then change its target to the shooter */
- /* restore the original script activator */
- SetActivator(s_tid); /* not really necessary in this script, but potentially important in functions called by scripts */
- /* if we changed the activator's tid above */
- if(stid_c){ Thing_ChangeTID(s_tid, o_tid); } /* change it back to what it was previously */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement