Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #library "JASHIN"
- #include "zcommon.acs"
- /*
- user_chase_time = last Timer()
- user_chase_x = x to move to
- user_chase_y = y to move to
- user_chase_z = z to move to
- */
- script "Jashin::ChaseTarget" (void)
- {
- int chase_speed = 15;
- int stored_tid = ActivatorTID();
- int jashin_tid = UniqueTID();
- Thing_ChangeTID(0, jashin_tid);
- int jashin_x = GetActorX(0);
- int jashin_y = GetActorY(0);
- int jashin_z = GetActorZ(0);
- int jashin_angle = GetActorAngle(0);
- if (!SetActivatorToTarget(0)) // target left.
- {
- Thing_ChangeTID(0, stored_tid);
- SetActorState(0, "See");
- terminate;
- }
- int target_stored_tid = ActivatorTID();
- int target_tid = UniqueTID();
- Thing_ChangeTID(0, target_tid);
- int target_x = GetActorX(0);
- int target_y = GetActorY(0);
- int target_z = GetActorZ(0);
- bool target_sight = CheckSight(jashin_tid, target_tid, 0);
- int jashin_chase_time = GetUserVariable(jashin_tid, "user_chase_time");
- int jashin_chase_x = GetUserVariable(jashin_tid, "user_chase_x")<<16;
- int jashin_chase_y = GetUserVariable(jashin_tid, "user_chase_y")<<16;
- int jashin_chase_z = GetUserVariable(jashin_tid, "user_chase_z")<<16;
- if (!jashin_chase_time || Timer()-jashin_chase_time > chase_speed)
- {
- int chaser_tid = GetUserVariable(jashin_tid, "user_chase_tid");
- if (!chaser_tid)
- {
- chaser_tid = UniqueTID();
- if (!Spawn("JashinChaser", jashin_x, jashin_y, jashin_z, chaser_tid, jashin_angle))
- {
- SetActivator(target_tid);
- Thing_ChangeTID(0, target_stored_tid);
- SetActivator(jashin_tid);
- Thing_ChangeTID(0, stored_tid);
- terminate;
- }
- //SetUserVariable(jashin_tid, "user_chase_tid", chaser_tid);
- }
- SetActivator(chaser_tid);
- SetPointer(AAPTR_TARGET, target_tid, AAPTR_DEFAULT, 0);
- for (int i = 0; i <= chase_speed; i++) SetActorState(0, "DoChase");
- jashin_chase_x = GetActorX(0);
- jashin_chase_y = GetActorY(0);
- jashin_chase_z = GetActorZ(0);
- Thing_Remove(0);
- SetActivator(target_tid);
- SetUserVariable(jashin_tid, "user_chase_time", Timer());
- SetUserVariable(jashin_tid, "user_chase_x", jashin_chase_x>>16);
- SetUserVariable(jashin_tid, "user_chase_y", jashin_chase_y>>16);
- SetUserVariable(jashin_tid, "user_chase_z", jashin_chase_z>>16);
- //printbold(s:"newchase");
- }
- SetActivator(target_tid);
- Thing_ChangeTID(0, target_stored_tid);
- SetActivator(jashin_tid);
- Thing_ChangeTID(0, stored_tid);
- int mdx = jashin_chase_x-GetActorX(0);
- int mdy = jashin_chase_y-GetActorY(0);
- int mdz = jashin_chase_z-GetActorZ(0);
- int mdlen = VectorLength(mdz, VectorLength(mdx, mdy));
- mdx = FixedDiv(mdx, mdlen);
- mdy = FixedDiv(mdy, mdlen);
- mdz = FixedDiv(mdz, mdlen);
- //printbold(s:"moving to ", f:jashin_chase_x, c:',', f:jashin_chase_y, c:',', f:jashin_chase_z);
- //printbold(s:"target is ", f:target_x, c:',', f:target_y, c:',', f:target_z);
- Warp(0, mdx, mdy, mdz, 0, WARPF_INTERPOLATE|WARPF_ABSOLUTEOFFSET);
- if (mdlen >= 2.0)
- {
- // calculate new angle too.
- int oldang = GetActorAngle(0);
- int reqang = VectorAngle(mdx, mdy);
- int newang = (reqang-oldang);
- if (newang > 0.5) newang = -(newang-0.5);
- if (newang < -0.5) newang = (-newang)-0.5;
- newang /= chase_speed;
- if ((oldang+newang > reqang && oldang < reqang) ||
- (oldang+newang < reqang && oldang > reqang)) ChangeActorAngle(0, reqang, true);
- else ChangeActorAngle(0, oldang+newang, true);
- }
- if (target_sight && Random(0, 1024) < 8)
- {
- SetActorState(0, "Missile");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement