1 #include "bot.h"
2 #include "q_shared.h"
3 #include "m_player.h"
4 
5 qboolean	pickup_pri;
6 
7 int			targetindex;		//debugtarget
8 char		ClientMessage[MAX_STRING_CHARS];
9 botinfo_t	Bot[MAXBOTS];
10 route_t		Route[MAXNODES];
11 int			CurrentIndex;
12 int			SpawnWaitingBots;
13 float		JumpMax = 0;
14 qboolean	JmpTableChk = false;
15 float		JumpTable[FALLCHK_LOOPMAX];
16 int			botskill;
17 int			trace_priority;
18 int			skullindex;
19 int			headindex;
20 int			mpindex[MPI_INDEX];	//items in map
21 int			ListedBotCount;
22 gitem_t		*zflag_item;
23 edict_t		*zflag_ent;
24 int			zigflag_spawn;
25 int			ListedBots;
26 edict_t*	ExplIndex[MAX_EXPLINDEX];
27 edict_t*	LaserIndex[MAX_LASERINDEX];
28 /*-------------------------*/
29 //pre searched items
30 gitem_t	*Fdi_GRAPPLE;
31 gitem_t	*Fdi_BLASTER;
32 gitem_t *Fdi_SHOTGUN;
33 gitem_t *Fdi_SUPERSHOTGUN;
34 gitem_t *Fdi_MACHINEGUN;
35 gitem_t *Fdi_CHAINGUN;
36 gitem_t *Fdi_GRENADES;
37 gitem_t *Fdi_GRENADELAUNCHER;
38 gitem_t *Fdi_ROCKETLAUNCHER;
39 gitem_t *Fdi_HYPERBLASTER;
40 gitem_t *Fdi_RAILGUN;
41 gitem_t *Fdi_BFG;
42 gitem_t *Fdi_PHALANX;
43 gitem_t *Fdi_BOOMER;
44 gitem_t *Fdi_TRAP;
45 
46 gitem_t *Fdi_SHELLS;
47 gitem_t *Fdi_BULLETS;
48 gitem_t *Fdi_CELLS;
49 gitem_t *Fdi_ROCKETS;
50 gitem_t *Fdi_SLUGS;
51 gitem_t *Fdi_MAGSLUGS;
52 /*--------------------------*/
53 
54 /*
55 FIRE_PRESTAYFIRE
56 FIRE_STAYFIRE
57 FIRE_IGNORE
58 FIRE_REFUGE
59 FIRE_EXPAVOID
60 FIRE_QUADUSE
61 FIRE_AVOIDINV
62 FIRE_JUMPROC
63 */
64 //combat flag set
65 int			FFlg[MAX_BOTSKILL]
66 =
67 {
68 //skill 0
69 	FIRE_PRESTAYFIRE | FIRE_STAYFIRE | FIRE_REFUGE,
70 //skill 1
71 	FIRE_REFUGE | FIRE_PRESTAYFIRE | FIRE_STAYFIRE | FIRE_REFUGE,
72 //skill 2
73 	FIRE_REFUGE | FIRE_PRESTAYFIRE | FIRE_IGNORE | FIRE_QUADUSE,
74 //skill 3
75 	FIRE_REFUGE | FIRE_EXPAVOID | FIRE_IGNORE | FIRE_QUADUSE,
76 //skill 4
77 	FIRE_REFUGE | FIRE_EXPAVOID | FIRE_IGNORE | FIRE_QUADUSE,
78 //skill 5
79 	FIRE_EXPAVOID | FIRE_IGNORE | FIRE_QUADUSE | FIRE_AVOIDINV | FIRE_IGNORE | FIRE_JUMPROC,
80 //skill 6
81 	FIRE_EXPAVOID | FIRE_IGNORE | FIRE_QUADUSE | FIRE_AVOIDINV | FIRE_IGNORE | FIRE_JUMPROC,
82 //skill 7
83 	FIRE_EXPAVOID | FIRE_IGNORE | FIRE_QUADUSE | FIRE_AVOIDINV| FIRE_IGNORE | FIRE_JUMPROC,
84 //skill 8
85 	FIRE_EXPAVOID | FIRE_IGNORE | FIRE_QUADUSE | FIRE_AVOIDINV| FIRE_IGNORE | FIRE_JUMPROC,
86 //skill 9
87 	FIRE_EXPAVOID | FIRE_IGNORE | FIRE_QUADUSE | FIRE_AVOIDINV| FIRE_IGNORE | FIRE_JUMPROC
88 };
89 
BotApplyStrength(edict_t * ent)90 qboolean BotApplyStrength(edict_t *ent)
91 {
92 	static gitem_t *tech = NULL;
93 
94 	if (!tech)
95 		tech = FindItemByClassname("item_tech2");
96 	if (tech && ent->client
97 		&& ent->client->pers.inventory[ITEM_INDEX(tech)])
98 		return true;
99 
100 	return false;
101 }
BotApplyResistance(edict_t * ent)102 qboolean BotApplyResistance(edict_t *ent)
103 {
104 	static gitem_t *tech = NULL;
105 
106 	if (!tech)
107 		tech = FindItemByClassname("item_tech1");
108 	if (tech && ent->client
109 		&& ent->client->pers.inventory[ITEM_INDEX(tech)])
110 		return true;
111 
112 	return false;
113 }
114 
115 //return foundedenemy
Bot_SearchEnemy(edict_t * ent)116 int Bot_SearchEnemy (edict_t *ent)
117 {
118 	zgcl_t		*zc;		//zc's address
119 	qboolean	tmpflg;		//temporary
120 	edict_t		*target,*trent;
121 	trace_t		rs_trace;
122 
123 	int		i,j,k;
124 	int		foundedenemy;
125 
126 	float	pitch,yaw;
127 	float	vr,hr;
128 
129 	char	*entcln;
130 
131 	vec3_t	trmin;
132 
133 	zc = &ent->client->zc;
134 
135 	vr = (float)Bot[zc->botindex].param[BOP_VRANGE];
136 	hr = (float)Bot[zc->botindex].param[BOP_HRANGE];
137 
138 	if(vr > 180) vr = 180;
139 	if(hr > 180) hr = 180;
140 	if(vr < 10) vr = 10;
141 	if(hr < 10) hr = 10;
142 	//-------------------------------------------
143 	//search for enemy
144 	foundedenemy = 0;
145 	target = NULL;
146 
147 	tmpflg = false;	//viewable flag
148 	if(zc->first_target != NULL){
149 		if(	Bot_trace(ent,zc->first_target)){
150 			tmpflg = true;
151 			foundedenemy++;
152 		}
153 	}
154 
155 //	if(zc->ctfstate == CTFS_SUPPORTER) zc->ctfstate = CTFS_OFFENCER;
156 
157 	// blue or red?
158 	if(ctf->value)
159 	{
160 		if(ent->client->resp.ctf_team == CTF_TEAM1) k = ITEM_INDEX(FindItem("Blue Flag"));
161 		else k = ITEM_INDEX(FindItem("Red Flag"));
162 	}
163 	else k = ITEM_INDEX(FindItem("ZB Flag"));
164 
165 	// decide da sorting first or last
166 	if(random() < 0.5) j = 0;
167 	else j = -1;
168 
169 	if(ent->client->pers.inventory[ITEM_INDEX(zflag_item)])
170 	{
171 		ent->client->zc.tmplstate = TMS_LEADER;
172 		ent->client->zc.followmate = NULL;
173 	}
174 
175 	for ( i = 1 ; i <= maxclients->value && target == NULL ; i++)
176 	{
177 		if(j){
178 			entcln = g_edicts[i].classname;
179 			trent =  &g_edicts[i];
180 		}
181 		else{
182 			entcln = g_edicts[(int)(maxclients->value) - i +1].classname;
183 			trent =  &g_edicts[(int)(maxclients->value) - i +1];
184 		}
185 
186 		if(!trent->inuse || ent == trent || zc->first_target == trent ||trent->deadflag) continue;
187 
188 		if( entcln[0] == 'p' && trent->movetype != MOVETYPE_NOCLIP ){
189 			if(Bot_traceS(ent,trent))
190 			{
191 				VectorSubtract (trent->s.origin, ent->s.origin, trmin);
192 				//not ctf mode and sameteam
193 				if(!ctf->value && OnSameTeam(ent,trent))
194 				{
195 					if(trent->client->zc.first_target)
196 					{
197 						if(Bot_traceS(ent,trent->client->zc.first_target)) target = trent->client->zc.first_target;
198 					}
199 					if(trmin[2] < JumpMax && VectorLength(trmin) < 400)
200 					{
201 						yaw = (float)Bot[ent->client->zc.botindex].param[BOP_TEAMWORK];
202 						if(trent->client->pers.inventory[ITEM_INDEX(zflag_item)])
203 						{
204 							trent->client->zc.tmplstate = TMS_LEADER;
205 							trent->client->zc.followmate = NULL;
206 							if((9 * random()) < yaw)
207 							{
208 								ent->client->zc.tmplstate = TMS_FOLLOWER;
209 								ent->client->zc.followmate = trent;
210 							}
211 						}
212 						else
213 						{
214 							if((9 * random()) < yaw)
215 							{
216 //gi.bprintf(PRINT_HIGH,"Team stateON\n");
217 								//���肪���[�_�[
218 								if(trent->client->zc.tmplstate == TMS_LEADER)
219 								{
220 									trent->client->zc.followmate = NULL;
221 									if(ent->client->zc.tmplstate == TMS_LEADER)
222 									{
223 										if(random() < 0.5)
224 										{
225 											ent->client->zc.tmplstate = TMS_FOLLOWER;
226 											ent->client->zc.followmate = trent;
227 										}
228 										else
229 										{
230 											ent->client->zc.tmplstate = TMS_LEADER;
231 											ent->client->zc.followmate = NULL;
232 											trent->client->zc.tmplstate = TMS_FOLLOWER;
233 											trent->client->zc.followmate = ent;
234 										}
235 									}
236 									else
237 									{
238 										ent->client->zc.tmplstate = TMS_FOLLOWER;
239 										ent->client->zc.followmate = trent;
240 									}
241 								}
242 								else
243 								{
244 									if(ent->client->zc.tmplstate == TMS_LEADER
245 										|| random() < 0.5)
246 									{
247 										ent->client->zc.tmplstate = TMS_LEADER;
248 										ent->client->zc.followmate = NULL;
249 										trent->client->zc.tmplstate = TMS_FOLLOWER;
250 										trent->client->zc.followmate = ent;
251 									}
252 									else
253 									{
254 										ent->client->zc.tmplstate = TMS_FOLLOWER;
255 										ent->client->zc.followmate = trent;
256 										trent->client->zc.tmplstate = TMS_LEADER;
257 										trent->client->zc.followmate = NULL;
258 									}
259 								}
260 							}
261 						}
262 					}
263 				}
264 				else if(ctf->value && ent->client->resp.ctf_team == trent->client->resp.ctf_team)
265 				{
266 					//have flag
267 					if(trent->client->pers.inventory[k])
268 					{
269 						if(ent->client->zc.ctfstate == CTFS_OFFENCER)
270 						{
271 							ent->client->zc.ctfstate = CTFS_SUPPORTER;
272 							ent->client->zc.followmate = trent;
273 						}
274 						// if carrier have enemy
275 						if(trent->client->zc.first_target != NULL)
276 						{
277 							if(trent->client->zc.first_target->classname[0] == 'p')
278 							{
279 								target = trent->client->zc.first_target;
280 							}
281 						}
282 						// if carrier tracing route
283 						if(trent->client->zc.route_trace && (trent->client->zc.routeindex - 2) > CurrentIndex)
284 						{
285 							zc->routeindex = trent->client->zc.routeindex - 2;
286 						}
287 //						ent->s.angles[YAW] = Get_yaw (trmin);
288 //						if(ent->client->zc.ctfstate == CTFS_SUPPORTER ){
289 //							zc->first_target = NULL;
290 //							break;
291 //						}
292 					}
293 				}
294 				else
295 				{
296 					foundedenemy++;
297 					if(!tmpflg && target == NULL)
298 					{
299 						pitch = Get_pitch(trmin);
300 						pitch = fabs(pitch - ent->s.angles[PITCH]);
301 						if(pitch > 180) pitch = 360 - pitch;
302 						//if(ent->client->zc.zcstate & STS_WAITS) target = trent;
303 						if(pitch <= vr)
304 						{
305 							yaw = Get_yaw(trmin);
306 							yaw = fabs(yaw - ent->s.angles[YAW]);
307 							if(yaw > 180) yaw = 360 - yaw;
308 							if(yaw <= hr || (ent->client->zc.zcstate & STS_WAITS))	target = trent;
309 						}
310 					}
311 					//
312 					if(!tmpflg && target == NULL && trent->mynoise && trent->mynoise2)
313 					{
314 						if(Bot[ent->client->zc.botindex].param[BOP_NOISECHK])
315 						{
316 							if(trent->mynoise->teleport_time >= (level.time - FRAMETIME))
317 							{
318 								VectorSubtract (trent->mynoise->s.origin, ent->s.origin, trmin);
319 								if(VectorLength(trmin) < 300)
320 								{
321 									pitch = (float)Bot[ent->client->zc.botindex].param[BOP_REACTION];
322 									if((9 * random()) < pitch) target = trent;
323 								}
324 							}
325 							if(target == NULL && trent->mynoise2->teleport_time >= (level.time - FRAMETIME))
326 							{
327 								VectorSubtract (trent->mynoise->s.origin, ent->s.origin, trmin);
328 								if(VectorLength(trmin) < 100)
329 								{
330 									pitch = (float)Bot[ent->client->zc.botindex].param[BOP_REACTION];
331 									if((9 * random()) < pitch) target = trent;
332 								}
333 							}
334 						}
335 					}
336 				}
337 			}
338 			//���݂̂ŏꏊ���f
339 			else
340 			{
341 				if(Bot[ent->client->zc.botindex].param[BOP_NOISECHK]
342 					&& Bot[ent->client->zc.botindex].param[BOP_ESTIMATE]
343 					&& !tmpflg && trent->mynoise)
344 				{
345 
346 					if(trent->mynoise->teleport_time >= (level.time - FRAMETIME))
347 					{
348 						AngleVectors (trent->client->v_angle, trmin, NULL, NULL);
349 						VectorScale(trmin,200,trmin);
350 						VectorAdd(trent->s.origin,trmin,trmin);
351 						rs_trace = gi.trace(trent->s.origin,NULL,NULL,trmin,trent,MASK_SHOT);
352 
353 						VectorSubtract (ent->s.origin, rs_trace.endpos, trmin);
354 						if(VectorLength(trmin) < 500)
355 						{
356 							VectorCopy(rs_trace.endpos,trmin);
357 							rs_trace = gi.trace(ent->s.origin,NULL,NULL,trmin,ent,MASK_SHOT);
358 							pitch = (float)Bot[ent->client->zc.botindex].param[BOP_REACTION];
359 
360 							if(rs_trace.fraction == 1.0 && (9 * random()) < pitch)
361 							{
362 								target = trent;
363 								ent->client->zc.battlemode |= FIRE_ESTIMATE;
364 								VectorCopy(trmin,ent->client->zc.vtemp);
365 							}
366 						}
367 					}
368 				}
369 			}
370 		}
371 	}
372 	if(target && !tmpflg) zc->first_target = target;
373 	else if(target && zc->first_target)
374 	{
375 		if(Get_KindWeapon(target->client->pers.weapon) >
376 			Get_KindWeapon(zc->first_target->client->pers.weapon)) zc->first_target = target;
377 	}
378 //	ent->client->zc.zcstate &= ~CTS_COMBS;	//clear combat state
379 
380 	return (foundedenemy);
381 }
382 
Bot_SearchItems(edict_t * ent)383 void Bot_SearchItems (edict_t *ent)
384 {
385 	zgcl_t		*zc;		//zc's address
386 	qboolean	wstayf,q;		//weaponflag
387 	edict_t		*target,*trent;
388 
389 	vec3_t		touchmin,touchmax;
390 	vec3_t		trmin,trmax;
391 
392 	gitem_t		*item;
393 	char		*entcln;
394 
395 	float		x,yaw;			//temporary
396 
397 	int			i,j,k,conts;
398 
399 	trace_t		rs_trace;
400 
401 	zc = &ent->client->zc;
402 
403 
404 	if((zc->tmpcount++) & 1) return;
405 
406 	j = 0;
407 	q = false;//rocket jump needed
408 	//search Items
409 	if(ctf->value)
410 	{
411 		if(ent->moveinfo.state == SUPPORTER) j = -1;
412 		else if( ent->target_ent != NULL)
413 		{
414 			if( ent->moveinfo.state == CARRIER && ent->target_ent->classname[6] == 'F') j = -1;
415 		}
416 		else if( ent->client->ctf_grapple != NULL) j = -1;
417 	}
418 	trent = zc->second_target;
419 	if( trent != NULL && !j )
420 	{
421 		x = random();
422 		if( trent->classname[0] == 'w') j = -1;
423 		else if( trent->classname[0]=='i'){
424 			if( trent->classname[5]=='q'
425 				|| trent->classname[5]=='f'
426 				|| trent->classname[5]=='t'
427 				|| trent->classname[5]=='i')
428 				j = -1;
429 		}
430 		else if((trent->classname[0] == 'p' && x > 0.2)
431 			|| ent->client->ctf_grapple != NULL	)
432 				j= -1;
433 	}
434 
435 	if( j == 0 )
436 	{
437 		if ((int)(dmflags->value) & DF_WEAPONS_STAY) wstayf = true;
438 		else wstayf = false;
439 
440 		target = NULL;
441 		VectorCopy (ent->absmin, touchmin);
442 		VectorCopy (ent->absmax, touchmax);
443 
444 		// when ctf
445 		if(0/*ctf->value*/){
446 			touchmin[0] -= 500;
447 			touchmin[1] -= 500;
448 			touchmin[2] -= 500;
449 			touchmax[0] += 500;
450 			touchmax[1] += 500;
451 			touchmax[2] += 598;
452 		}
453 		// when not
454 		else
455 		{
456 			touchmin[0] -= 300;
457 			touchmin[1] -= 300;
458 			touchmin[2] -= 300;
459 			if(ent->waterlevel) touchmin[2] -= 200;
460 			touchmax[0] += 300;
461 			touchmax[1] += 300;
462 			touchmax[2] += 54;// +290);
463 
464 			if(ent->health > 70 && ent->client->pers.inventory[ITEM_INDEX(Fdi_ROCKETLAUNCHER/*FindItem("Rocket Launcher")*/)])
465 			{
466 				i = ITEM_INDEX(Fdi_ROCKETS/*FindItem("Rockets")*/);
467 
468 				if(ent->client->pers.inventory[i] > 0)
469 				{
470 					q = true;
471 					touchmax[2] += 290;
472 				}
473 			}
474 		}
475 
476 
477 		if((level.framenum - ent->client->resp.enterframe ) % 64 > 32) j = 0;
478 		else j = -1;
479 
480 		k = globals.num_edicts + maxclients->value+1;
481 
482 		for ( i=maxclients->value+1 ; i<globals.num_edicts ; i++)
483 		{
484 			if(j)	//normal
485 			{
486 				trent = &g_edicts[i];
487 				entcln = trent->classname;
488 			}
489 			else	//reverse
490 			{
491 				trent = &g_edicts[k - i];
492 				entcln = trent->classname;
493 			}
494 
495 			if(!trent->inuse) continue;
496 			if(trent->solid != SOLID_TRIGGER)
497 			{
498 				if( ent->client->weaponstate == WEAPON_READY && !ent->client->zc.route_trace)
499 				{
500 					if( entcln )
501 					{
502 						if(entcln[0] == 'f' /*&& trent->classname[5] == 'b'*/
503 							&& trent->health //&&trent->moveinfo.state == PSTATE_BOTTOM
504 							&& trent->takedamage)//trent->moveinfo.wait == 0)
505 						{
506 							if(trent->classname[5] == 'b'
507 								&& trent->monsterinfo.attack_finished > level.time) continue;
508 
509 							trmax[0] = (trent->absmin[0] + trent->absmax[0]) / 2;
510 							trmax[1] = (trent->absmin[1] + trent->absmax[1]) / 2;
511 							trmax[2] = (trent->absmin[2] + trent->absmax[2]) / 2;
512 							rs_trace = gi.trace (ent->s.origin, NULL, NULL, trmax ,ent, MASK_SHOT);
513 
514 							if(rs_trace.ent == trent)
515 							{
516 					//		gi.bprintf(PRINT_HIGH,"kkkkkkk\n");
517 					//		continue;
518 								VectorSubtract (trmax, ent->s.origin,trmin);
519 								item = Fdi_BLASTER;//FindItem("Blaster");
520 //								ent->client->ammo_index = 0;
521 								item->use(ent,item);
522 								//ent->client->ammo_index = 0;
523 								//ent->client->pers.weapon = FindItem("Blaster");
524 								//ShowGun(ent);
525 								ent->s.angles[YAW] = Get_yaw(trmin);
526 								ent->s.angles[PITCH] = Get_pitch(trmin);
527 								ent->client->buttons |= BUTTON_ATTACK;
528 								ent->client->zc.objshot = true;
529 							}
530 						}
531 					}
532 				}
533 				continue;
534 			}
535 
536 
537 
538 
539 			if(trent->absmax[0]	< touchmin[0]) continue;
540 			if(touchmax[0]		< trent->absmin[0])	continue;
541 			if(trent->absmax[1]	< touchmin[1]) continue;
542 			if(touchmax[1]		< trent->absmin[1])	continue;
543 			if(trent->absmax[2]	< touchmin[2]) continue;
544 			if(touchmax[2]		< trent->absmin[2])	continue;
545 
546 			VectorSubtract (trent->s.origin, ent->s.origin, trmin);
547 			yaw = VectorLength(trmin);
548 
549 /*			if( trent->classname[0] == 'w' || trent->classname[0] == 'R') x = 0;
550 			else if(trent->classname[0]=='i')
551 			{
552 				if(trent->classname[5]=='q'
553 					|| trent->classname[5]=='f'
554 					|| trent->classname[5]=='t'
555 					|| trent->classname[5]=='i') x = 0;
556 			}*/
557 			/*else*/ if( !ctf->value )
558 			{
559 //				if(yaw >300 /*|| (trent->s.origin[2] - ent->s.origin[2] ) < -64*/)	continue;
560 			}
561 
562 			if( Bot_trace(ent,trent) )
563 			{
564 				if(entcln[0] == 'i')
565 				{
566 					if(entcln[5] == 'h')
567 					{
568 						if(Q_stricmp (entcln, "item_health") == 0 )
569 						{
570 							if( ent->health < 100 && (!pickup_pri || yaw < 96)) target = trent;
571 						}
572 						else if(entcln[12] == 's'){ //item_health_small
573 							if(fabs(trent->s.origin[2] - ent->s.origin[2] + 8) > JumpMax) continue;
574 							target = trent;
575 						}
576 						else if(entcln[12] == 'l') //item_health_large
577 						{
578 							if( ent->health < 100 && (!pickup_pri || yaw < 96)) target = trent;
579 						}
580 						else if(entcln[12] == 'm') //item_health_mega
581 							target = trent;
582 					}
583 					else if(entcln[5] == 'a' && !pickup_pri)
584 					{
585 						if(entcln[11] == 's'){		//item_armor_shard
586 							if(fabs(trent->s.origin[2] - ent->s.origin[2] + 8) > JumpMax) continue;
587 							target = trent;
588 						}
589 						else if(entcln[11] == 'j')	//item_armor_jacket
590 						{
591 							if( ent->client->pers.inventory[ITEM_INDEX(FindItem("Jacket Armor"))] < 50 ) target = trent;
592 						}
593 						else if(entcln[11] == 'c')	//item_armor_combat
594 						{
595 							if( ent->client->pers.inventory[ITEM_INDEX(FindItem("Combat Armor"))] < 100) target = trent;
596 						}
597 						else if(entcln[11] == 'b')	//item_armor_body
598 						{
599 							if( ent->client->pers.inventory[ITEM_INDEX(FindItem("Body Armor"))] < 200) target = trent;
600 						}
601 						else if(entcln[6] == 'd')	//item_adrenaline
602 										target = trent;
603 						else if(entcln[6] == 'n')	//item_ancient_head
604 										target = trent;
605 					}
606 					else if(entcln[5] == 'f')
607 					{
608 						if( trent->spawnflags & DROPPED_ITEM ) target = trent;
609 						else if(entcln[10] == 't' && entcln[14] == '1')
610 						{
611 							if( ent->client->resp.ctf_team == CTF_TEAM2) target = trent;
612 							else if( ent->client->pers.inventory[ITEM_INDEX(FindItem("Blue Flag"))]) target = trent;
613 						}
614 						else if(entcln[10] == 't' && entcln[14] == '2')
615 						{
616 							if( ent->client->resp.ctf_team == CTF_TEAM1) target = trent;
617 							else if(ent->client->pers.inventory[ITEM_INDEX(FindItem("Red Flag"))]) target = trent;
618 						}
619 					}
620 					else if(entcln[5] == 't')
621 					{
622 						if(!BotApplyResistance(ent))
623 							if(	!BotApplyStrength(ent))
624 								if( !CTFApplyHaste(ent))
625 									if( !CTFHasRegeneration(ent)) target = trent;
626 					}
627 					else
628 					{
629 						if(entcln[5] == 'q')		//item_quad
630 							target = trent;
631 						else if(entcln[5] == 'p' && entcln[6] == 'a')	//item_pack
632 							target = trent;
633 						else if(entcln[5] == 'b' && entcln[6] == 'a')	//item_bandolier
634 							target = trent;
635 						else if(entcln[5] == 'e')	//item_enviro
636 							target = trent;
637 						else if(entcln[5] == 'b')	//item_breather
638 							target = trent;
639 						else if(entcln[5] == 's')	//item_silencer
640 							target = trent;
641 						else if(entcln[5] == 'i')	//item_invulnerability
642 							target = trent;
643 						else if(entcln[5] == 'p' && entcln[12] == 'h')	//Q_stricmp (entcln, "item_power_shield") == 0)
644 							target = trent;
645 						else if(entcln[5] == 'p' && entcln[12] == 'c')	//Q_stricmp (entcln, "item_power_screen") == 0)
646 							target = trent;
647 					}
648 				}
649 				else if(entcln[0] == 'a' && !pickup_pri)
650 				{
651 					if(entcln[5] == 'b')							//ammo_bullets
652 					{
653 						if( ent->client->pers.inventory[ITEM_INDEX(Fdi_BULLETS/*FindItem("Bullets")*/)]
654 											< ent->client->pers.max_bullets) target = trent;
655 					}
656 					else if(entcln[5] == 's' && entcln[6] == 'h')	//ammo_shells
657 					{
658 						if(ent->client->pers.inventory[ITEM_INDEX(Fdi_SHELLS/*FindItem("Shells")*/)]
659 											< ent->client->pers.max_shells) target = trent;
660 					}
661 					else if(entcln[5] == 'g')						//ammo_grenades
662 					{
663 						if(ent->client->pers.inventory[ITEM_INDEX(Fdi_GRENADES/*FindItem("Grenades")*/)]
664 											< ent->client->pers.max_grenades) target = trent;
665 					}
666 					else if(entcln[5] == 'r')						//ammo_rockets
667 					{
668 						if(ent->client->pers.inventory[ITEM_INDEX(Fdi_ROCKETS/*FindItem("Rockets")*/)]
669 											< ent->client->pers.max_rockets) target = trent;
670 					}
671 					else if(entcln[5] == 's' )						//ammo_slugs
672 					{
673 						if(ent->client->pers.inventory[ITEM_INDEX(Fdi_SLUGS/*FindItem("Slugs")*/)]
674 											< ent->client->pers.max_slugs) target = trent;
675 					}
676 					else if(entcln[5] == 'c' )						//ammo_cells
677 					{
678 						if(ent->client->pers.inventory[ITEM_INDEX(Fdi_CELLS/*FindItem("Cells")*/)]
679 											< ent->client->pers.max_cells) target = trent;
680 					}
681 					else if(entcln[5] == 'm' )						//ammo_magslug
682 					{
683 						if(ent->client->pers.inventory[ITEM_INDEX(Fdi_MAGSLUGS/*FindItem("Mag Slug")*/)]
684 											< ent->client->pers.max_magslug) target = trent;
685 					}
686 					else if(entcln[5] == 't' )						//ammo_trap
687 					{
688 						if(ent->client->pers.inventory[ITEM_INDEX(Fdi_TRAP/*FindItem("Trap")*/)]
689 											< ent->client->pers.max_trap) target = trent;
690 					}
691 				}
692 				else if(entcln[0] == 'w')
693 				{
694 					if(entcln[7] == 's' && entcln[8] == 'h' )	//weapon_shotgun
695 					{
696 						if(!wstayf || (wstayf && !pickup_pri
697 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_SHOTGUN/*FindItem("Shotgun")*/)]
698 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM) ) )) target = trent;
699 					}
700 					else if(entcln[7] == 's')					//weapon_supershotgun
701 					{
702 						if(!wstayf || (wstayf
703 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_SUPERSHOTGUN/*FindItem("Super Shotgun")*/)]
704 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM))) ) target = trent;
705 					}
706 					else if(entcln[7] == 'm')					//weapon_machinegun
707 					{
708 						if(!wstayf || (wstayf
709 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_MACHINEGUN/*FindItem("Machinegun")*/)]
710 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))) target = trent;
711 					}
712 					else if(entcln[7] == 'c')					//weapon_chaingun
713 					{
714 						if(!wstayf || (wstayf
715 								&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_CHAINGUN/*FindItem("Chaingun")*/)]
716 								|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM))) ) target = trent;
717 					}
718 					else if(entcln[7] == 'g')					//weapon_grenadelauncher
719 					{
720 						if(!wstayf || (wstayf
721 						&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_GRENADELAUNCHER/*FindItem("Grenade Launcher")*/)]
722 						|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))) target = trent;
723 					}
724 					else if(entcln[7]=='r' && entcln[8] == 'o')	//weapon_rocketlauncher
725 						{
726 						if(!wstayf || (wstayf
727 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_ROCKETLAUNCHER/*FindItem("Rocket Launcher")*/)]
728 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))) target = trent;
729 					}
730 					else if(entcln[7] == 'h')					//weapon_hyperblaster
731 					{
732 						if(!wstayf || (wstayf
733 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_HYPERBLASTER/*FindItem("HyperBlaster")*/)]
734 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))) target = trent;
735 					}
736 					else if(entcln[7] == 'r')					//weapon_railgun
737 					{
738 						if(!wstayf || (wstayf
739 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_RAILGUN/*FindItem("Railgun")*/)]
740 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))) target = trent;
741 					}
742 					else if(entcln[7] == 'b' && entcln[8] == 'o')//weapon_boomer
743 					{
744 						if(!wstayf || (wstayf
745 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_BOOMER/*FindItem("Ionripper")*/)]
746 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))) target = trent;
747 					}
748 					else if(entcln[7] == 'p')					//weapon_phalanx
749 					{
750 						if(!wstayf || (wstayf
751 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_PHALANX/*FindItem("Phalanx")*/)]
752 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))) target = trent;
753 					}
754 					else if(entcln[7] == 'b')					//weapon_bfg
755 					{
756 						if(!wstayf || (wstayf
757 							&& (!ent->client->pers.inventory[ITEM_INDEX(Fdi_BFG/*FindItem("BFG10K")*/)]
758 							|| trent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)))) target = trent;
759 					}
760 				}
761 				else if(entcln[0] == 'R' && !ent->client->zc.route_trace)
762 				{
763 					if(entcln[2] == 'n')
764 					{
765 						if(ctf->value)
766 						{
767 							if(ent->moveinfo.state == CARRIER)
768 							{
769 								if(random() < 0.05) target = trent;
770 							}
771 							else if(ent->moveinfo.state == DEFENDER)
772 							{
773 								if(random() < 0.01) target = trent;
774 							}
775 							else if(random() < 0.02) target = trent;
776 						}
777 						else if(random() < 0.4)	target = trent;
778 					}
779 					else if(ent->client->zc.route_trace)
780 					{
781 						if(ent->client->zc.routeindex < CurrentIndex)
782 						{
783 							if(entcln[6] == 'X' && Route[ent->client->zc.routeindex].state == GRS_ONTRAIN) target = trent;
784 							else if(entcln[6] == '2' && Route[ent->client->zc.routeindex].state == GRS_PUSHBUTTON
785 								&& Route[ent->client->zc.routeindex].ent == trent) target = trent;
786 							else target = NULL;
787 						}
788 					}
789 					else if(entcln[6] == '3') target = NULL;
790 				}
791 			}
792 			// founded!
793 /*			if( target != NULL && !ctf->value)
794 			{
795 				if(!ent->waterlevel)
796 				{
797 					VectorSubtract(target->s.origin,ent->s.origin,touchmax);
798 					x = touchmax[2];
799 					touchmax[2] = 0;
800 					iyaw = VectorLength(touchmax);
801 					if( x < -39 )
802 					{
803 						yaw = iyaw/(-x);*/
804 //						if( /*yaw < 0.5 &&*/ yaw > 2.5 /*&& iyaw > 64*/) target = NULL;
805 /*						if(target != NULL)
806 						{
807 							if((target->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)) && x < -64) target = NULL;
808 						}
809 					}
810 					if(target != NULL && !ent->waterlevel && x < -60)
811 					{
812 						if( target->classname[0] == 'w'
813 							|| (target->classname[0]=='i' && target->classname[5]=='q')
814 							|| (target->classname[0]=='i' && target->classname[5]=='f')
815 							|| (target->classname[0]=='i' && target->classname[5]=='t')
816 							|| (target->classname[0]=='i' && target->classname[5]=='i'))
817 						{
818 							if(iyaw < 64 ) target = NULL;
819 						}
820 						else target = NULL;
821 					}
822 				}
823 			}
824 */
825 			if(target != NULL)
826 			{
827 				conts = gi.pointcontents (target->s.origin);
828 				if(conts & CONTENTS_LAVA) target = NULL;
829 				else if((conts & CONTENTS_SLIME) && ent->client->enviro_framenum <= level.framenum) target = NULL;
830 			}
831 			if(target != NULL && !ctf->value )
832 			{
833 				if((target->s.origin[2] - ent->s.origin[2]) > 32  && !q)
834 				{
835 					x = target->moveinfo.start_origin[2] - ent->s.origin[2];
836 					if(x > 54 || x < -24) target = NULL;
837 					else
838 					{
839 						x = target->s.origin[2] - target->moveinfo.start_origin[2];
840 						if(x > 54 || x < 0) target = NULL;
841 					}
842 				}
843 				else if((target->s.origin[2] - ent->s.origin[2]) <= 100  && q)
844 				{
845 					target = NULL;
846 				}
847 			}
848 
849 			if(target != NULL )
850 			{
851 				if(	zc->second_target == NULL )
852 				{
853 					zc->second_target = target;
854 					break;
855 				}
856 				else if(zc->second_target->classname[6] == 'F' &&
857 					zc->second_target->classname[6] == 'F')
858 				{
859 					target = NULL;
860 					continue;
861 				}
862 				else
863 				{
864 					if( (target->classname[0] == 'R' && target->classname[0] != 'F')
865 						|| target->classname[0] == 'w'
866 						|| (target->classname[0]=='i' && target->classname[5]=='q')
867 						|| (target->classname[0]=='i' && target->classname[5]=='t')
868 						|| (target->classname[0]=='i' && target->classname[5]=='f')
869 						|| (target->classname[0]=='i' && target->classname[5]=='i'))
870 					{
871 						VectorSubtract (ent->s.origin, target->s.origin, trmin);
872 						if(ctf->value
873 							&& zc->second_target->classname[6] == 'F'
874 							&& ent->moveinfo.state != CARRIER)
875 						{
876 							zc->second_target = target;
877 							break;
878 						}
879 						else if( VectorLength(trmin) > 24 )
880 						{
881 							zc->second_target = target;
882 							break;
883 						}
884 					}
885 				}
886 			}
887 			target = NULL;
888 		}
889 	}
890 }
891 
892 //-----------------------------------------------------------------------------------------
893 //�o�N�n�c�����
894 //Avoid explotion
895 //
896 #define EXPLO_BOXSIZE	64
Bot_ExploAvoid(edict_t * ent,vec3_t v)897 qboolean Bot_ExploAvoid(edict_t *ent,vec3_t	v)
898 {
899 	int	i;
900 
901 	vec3_t	absmax,absmin;
902 	vec3_t	msmax,msmin;
903 
904 	if(ent->groundentity == NULL && !ent->waterlevel) return true;
905 	if(!(FFlg[Bot[ent->client->zc.botindex].param[BOP_COMBATSKILL]] & FIRE_EXPAVOID)) return true;
906 
907 	VectorCopy(v,msmax);
908 	VectorCopy(v,msmin);
909 	msmax[0] += ent->maxs[0]; msmax[1] += ent->maxs[1]; msmax[2] += ent->maxs[2];
910 	msmin[0] += ent->mins[0]; msmin[1] += ent->mins[1]; msmin[2] += ent->mins[2];
911 
912 	for(i = 0;i < MAX_EXPLINDEX;i++)
913 	{
914 		if(ExplIndex[i] != NULL) {if(ExplIndex[i]->inuse == false) ExplIndex[i] = NULL;}
915 		if(ExplIndex[i] != NULL)
916 		{
917 			VectorCopy(ExplIndex[i]->s.origin,absmax);
918 			VectorCopy(absmax,absmin);
919 			absmax[0] += EXPLO_BOXSIZE; absmax[1] += EXPLO_BOXSIZE; absmax[2] += EXPLO_BOXSIZE;
920 			absmin[0] -= EXPLO_BOXSIZE; absmin[1] -= EXPLO_BOXSIZE; absmin[2] -= EXPLO_BOXSIZE;
921 
922 			if(absmax[0]	< msmin[0]) continue;
923 			if(msmax[0]	< absmin[0])	continue;
924 			if(absmax[1]	< msmin[1]) continue;
925 			if(msmax[1]	< absmin[1])	continue;
926 			if(absmax[2]	< msmin[2]) continue;
927 			if(msmax[2]	< absmin[2])	continue;
928 
929 			return false;
930 		}
931 	}
932 	return true;
933 }
934 
935 //���[�U�[�̃`�F�b�N
CheckLaser(vec3_t pos,vec3_t maxs,vec3_t mins)936 qboolean CheckLaser(vec3_t pos,vec3_t maxs,vec3_t mins)
937 {
938 	int	i;
939 	vec3_t v,end,absmax,absmin;
940 	float L1,L2,L3;
941 
942 	VectorAdd(pos,maxs,absmax);
943 	VectorAdd(pos,mins,absmin);
944 
945 	for(i = 0;i < MAX_LASERINDEX;i++)
946 	{
947 		if(LaserIndex[i] == NULL) return false;
948 		if (!(LaserIndex[i]->spawnflags & 1)) continue;
949 
950 		VectorSubtract(pos,LaserIndex[i]->s.origin,v);
951 		L1 = VectorLength(v);
952 		VectorSubtract(pos,LaserIndex[i]->moveinfo.end_origin,v);
953 		L2 = VectorLength(v);
954 
955 		VectorSubtract(LaserIndex[i]->s.origin,LaserIndex[i]->moveinfo.end_origin,v);
956 		L3 = VectorLength(v);
957 
958 //		VectorCopy (LaserIndex[i]->s.origin, start);
959 		VectorMA (LaserIndex[i]->s.origin, L3 * L1 / (L1 + L2), LaserIndex[i]->movedir, end);
960 
961 		VectorSubtract(pos,end,v);
962 		L3 = VectorLength(v);
963 
964 		if(L3 > L1 || L3 > L2) continue;
965 
966 //gi.bprintf(PRINT_HIGH,"Length %f!\n",L3);
967 
968 		if(end[0]	< absmin[0]) continue;
969 		if(absmax[0]	< end[0])	continue;
970 		if(end[1]	< absmin[1]) continue;
971 		if(absmax[1]	< end[1])	continue;
972 		if(end[2]	< absmin[2]) continue;
973 		if(absmax[2]	< end[2])	continue;
974 //gi.bprintf(PRINT_HIGH,"Laser Checked! %f\n",L3);
975 		return true;
976 	}
977 	return false;
978 }
979 
980 //-----------------------------------------------------------------------------------------
981 // BOT�ړ��”\����new
982 // bot move test
983 //  return	false	can't
984 //			true	stand
985 //			2		duck
Bot_moveT(edict_t * ent,float ryaw,vec3_t pos,float dist,float * bottom)986 int Bot_moveT ( edict_t *ent,float ryaw,vec3_t pos,float dist,float *bottom)
987 {
988 	float		i,yaw;
989 	vec3_t		trstart,trend;
990 	vec3_t		trmin,trmax,v,vv;
991 	trace_t		rs_trace;
992 	float		tracelimit;
993 	qboolean	moveok;
994 	int			contents;
995 
996 	int			tcontents;
997 
998 
999 
1000 	tcontents =/* MASK_BOTSOLID*/MASK_BOTSOLIDX;//MASK_PLAYERSOLID /*| CONTENTS_TRANSLUCENT*/;  //���[�U�[�ɂ͐G��Ȃ�
1001 //	if(!ent->waterlevel) tcontents |= CONTENTS_WATER;
1002 
1003 	if(/*ent->client->zc.waterstate == WAS_FLOAT*/ent->waterlevel >= 1/*2*/) tracelimit = 75;//75;//61;
1004 	else if(ent->client->ps.pmove.pm_flags & PMF_DUCKED) tracelimit = 26;
1005 	else tracelimit = JumpMax + 5;//61;
1006 
1007 	VectorSet (trmin,-16,-16,-24);
1008 	VectorSet (trmax,16,16,3);
1009 
1010 	if(ent->client->zc.route_trace) VectorSet (vv,16,16,0);
1011 	else VectorSet (vv,16,16,3);
1012 
1013 	if(0/*!(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
1014 		&& (ent->client->zc.n_duckedtime < FRAMETIME * 10 /*&& !ent->client->zc.route_trace)*/) trmax[2] = 31;
1015 //	else if(ent->waterlevel && !ent->groundentity) trmax[2] = 32;
1016 	else if(ent->client->zc.route_trace
1017 		&& !(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
1018 		&& ent->waterlevel < 2)
1019 	{
1020 		Get_RouteOrigin(ent->client->zc.routeindex,v);
1021 		if((v[2] - ent->s.origin[2]) > 20) trmax[2] = 31;
1022 	}
1023 
1024 	//�ړ��悪�ǂ��Ȃ��Ă���̂����ׂ�
1025 	yaw = ryaw*M_PI*2 / 360;
1026 	trend[0] = cos(yaw) * dist ;				//start
1027 	trend[1] = sin(yaw) * dist ;
1028 	trend[2] = 0;
1029 	VectorAdd (trend, ent->s.origin, trstart);
1030 
1031 	VectorCopy(trstart,trend);
1032 	trend[2] += 1;
1033 	rs_trace = gi.trace (trstart, trmin, trmax, trend,ent, tcontents);
1034 
1035 	trmax[2] += 1;
1036 	if(rs_trace.allsolid || rs_trace.startsolid || rs_trace.fraction != 1.0)	//�O�ɂ͐i�߂Ȃ��ꍇ
1037 	{
1038 		moveok = false;
1039 		VectorCopy (trstart, trend);
1040 
1041 		for( i = 4 ; i < (tracelimit + 4) ; i += 4 )
1042 		{
1043 			trstart[2] = ent->s.origin[2] + i;
1044 			rs_trace = gi.trace (trstart, trmin, vv/*trmax*/, trend,ent, tcontents );
1045 //			rs_trace = gi.trace (trstart, trmin, trmax, trstart,ent, tcontents );
1046 			if(!rs_trace.allsolid && !rs_trace.startsolid && rs_trace.fraction > 0)
1047 			{
1048 				moveok = true;
1049 				break;
1050 			}
1051 		}
1052 		if(!moveok/*i >= tracelimit+4*/)
1053 //		if(i >= tracelimit - 4)
1054 		{
1055 //gi.bprintf(PRINT_HIGH,"apooX %f >= %f\n",i ,tracelimit);
1056 //if(ent->client->ps.pmove.pm_flags & PMF_DUCKED) gi.bprintf(PRINT_HIGH,"apoo1 %f %f \n",i,trmax[2]);
1057 			return false;
1058 		}
1059 
1060 //		rs_trace = gi.trace (trstart, trmin, trmax, trend,ent, tcontents );
1061 		*bottom = rs_trace.endpos[2] - ent->s.origin[2];
1062 
1063 		if(!ent->client->zc.route_trace)
1064 		{
1065 //gi.bprintf(PRINT_HIGH,"apoo2\n");
1066 //if(ent->client->zc.waterstate == 1 && ryaw == ent->client->zc.moveyaw) gi.bprintf(PRINT_HIGH,"apoo2\n");
1067 			if(rs_trace.plane.normal[2] < 0.7 && (!ent->client->zc.waterstate && ent->groundentity)) return false;
1068 		}
1069 		else
1070 		{
1071 			Get_RouteOrigin(ent->client->zc.routeindex,v);
1072 			if(rs_trace.plane.normal[2] < 0.7 && v[2] < ent->s.origin[2]) return false;
1073 		}
1074 
1075 		if( *bottom >/*=*/ tracelimit - 5)
1076 		{
1077 //gi.bprintf(PRINT_HIGH,"apooY %f > %f\n",*bottom ,tracelimit - 5);
1078 //gi.bprintf(PRINT_HIGH,"apoo3\n");
1079 //if(ent->client->zc.waterstate == 1 && ryaw == ent->client->zc.moveyaw) gi.bprintf(PRINT_HIGH,"apoo3\n");
1080 			return false;
1081 		}
1082 		pos[0] = rs_trace.endpos[0];
1083 		pos[1] = rs_trace.endpos[1];
1084 		pos[2] = rs_trace.endpos[2];
1085 
1086 		if(trmax[2] == 32)
1087 		{
1088 			if(Bot_ExploAvoid(ent,pos))
1089 			{
1090 				if(!CheckLaser(pos,trmax,trmin))
1091 				return true;
1092 			}
1093 			return false;
1094 		}
1095 
1096 //		trmax[2] = 32;
1097 		VectorCopy(pos,trend);
1098 		trend[2] += 28;
1099 		rs_trace = gi.trace (pos, trmin, trmax, trend,ent, tcontents );
1100 		if(!rs_trace.allsolid && !rs_trace.startsolid && rs_trace.fraction == 1.0)
1101 		{
1102 			if(Bot_ExploAvoid(ent,pos))
1103 			{
1104 				if(!CheckLaser(pos,trmax,trmin))
1105 				return true;
1106 			}
1107 			return false;
1108 		}
1109 		if(Bot_ExploAvoid(ent,pos))
1110 		{
1111 			if(!CheckLaser(pos,trmax,trmin))
1112 			return 2;
1113 		}
1114 		return false;
1115 
1116 
1117 /*		trmax[2] = 32;
1118 		rs_trace = gi.trace (pos, trmin, trmax, pos,ent, tcontents );
1119 		if(!rs_trace.allsolid && !rs_trace.startsolid)	return true;
1120 		return 2;*/
1121 	}
1122 	else								//�i�߂��Ƃ��Ă����������Ȃ����̂��߂̃`�F�b�N
1123 	{
1124 		pos[0] = trstart[0];
1125 		pos[1] = trstart[1];
1126 		pos[2] = trstart[2];
1127 		VectorCopy (trstart, trend);
1128 
1129 		trstart[2] = trend[2] -8190;
1130 		rs_trace = gi.trace (trend, trmin, trmax, trstart,ent, tcontents | MASK_OPAQUE);
1131 
1132 		*bottom = rs_trace.endpos[2] - ent->s.origin[2];
1133 
1134 		if(0/*rs_trace.fraction != 1.0 && rs_trace.plane.normal[2] < 0.7 && ent->waterlevel < 2 && ent->groundentity*/)
1135 		{
1136 			i = Get_vec_yaw (rs_trace.plane.normal,ryaw);
1137 			if( i < 90)
1138 			{
1139 				if(*bottom < 0 ) *bottom *= 3.0;
1140 			}
1141 			else
1142 			{
1143 //if(ent->client->ps.pmove.pm_flags & PMF_DUCKED) gi.bprintf(PRINT_HIGH,"apoo2\n");
1144 //if(ent->client->zc.waterstate == WAS_FLOAT && ryaw == ent->client->zc.moveyaw) gi.bprintf(PRINT_HIGH,"apooX\n");
1145 				return false;
1146 			}
1147 		}
1148 		if(0/*!ent->client->zc.route_trace*/)
1149 		{
1150 			if(rs_trace.plane.normal[2] > 0 && rs_trace.plane.normal[2] < 0.7) *bottom /= rs_trace.plane.normal[2];
1151 		}
1152 /*		else
1153 		{
1154 
1155 		}*/
1156 
1157 		contents = 0;
1158 		if(!ent->waterlevel)
1159 		{
1160 			if (ent->client->enviro_framenum > level.framenum) contents = CONTENTS_LAVA;
1161 			else contents = ( CONTENTS_LAVA | CONTENTS_SLIME);
1162 		}
1163 		if( rs_trace.contents & contents ) *bottom = -9999; /*return false;*/
1164 		else if( rs_trace.surface->flags & SURF_SKY ) *bottom = -9999;
1165 
1166 		if(!ent->waterlevel && (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
1167 			&& ent->groundentity == NULL && ent->velocity[2] > 10 && trmax[2] == 4) return 2;
1168 
1169 
1170 		if(trmax[2] == 32)
1171 		{
1172 			if(Bot_ExploAvoid(ent,pos))
1173 			{
1174 				if(!CheckLaser(pos,trmax,trmin))
1175 				return true;
1176 			}
1177 			return false;
1178 		}
1179 
1180 //		trmax[2] = 32;
1181 		VectorCopy(pos,trend);
1182 		trend[2] += 28;
1183 		rs_trace = gi.trace (pos, trmin, trmax, trend,ent, tcontents );
1184 		if(!rs_trace.allsolid && !rs_trace.startsolid && rs_trace.fraction == 1.0)
1185 		{
1186 			if(Bot_ExploAvoid(ent,pos))
1187 			{
1188 				if(!CheckLaser(pos,trmax,trmin))
1189 				return true;
1190 			}
1191 			return false;
1192 		}
1193 		if(Bot_ExploAvoid(ent,pos))
1194 		{
1195 			if(!CheckLaser(pos,trmax,trmin))
1196 			return 2;
1197 		}
1198 		return false;
1199 	}
1200 }
1201 
Bot_Watermove(edict_t * ent,vec3_t pos,float dist,float upd)1202 int Bot_Watermove ( edict_t *ent,vec3_t pos,float dist,float upd)
1203 {
1204 	trace_t		rs_trace;
1205 	vec3_t		trmin,trmax,touchmin;
1206 	float		i,j;
1207 
1208 	float		max,vec;
1209 
1210 	VectorCopy(ent->s.origin,trmax);
1211 
1212 	trmax[2] += upd;
1213 
1214 	rs_trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, trmax,ent, /*MASK_BOTSOLID*/MASK_BOTSOLIDX);
1215 
1216 	if(!rs_trace.allsolid && !rs_trace.startsolid )
1217 	{
1218 		if(rs_trace.fraction > 0)
1219 		{
1220 			VectorCopy(rs_trace.endpos,pos);
1221 			return true;
1222 			if(upd < 0) ent->velocity[2] = 0;
1223 		}
1224 	}
1225 //gi.bprintf(PRINT_HIGH,"Water MOVE NG %f %f!\n",dist,upd);
1226 //	return false;
1227 //	if(upd > -7 && upd < 7)	return false;
1228 
1229 	VectorCopy(ent->s.origin,trmin);
1230 	trmin[2] += upd;
1231 
1232 	vec = -1;
1233 	max = 0;
1234 	for(i = 0;i < 360; i += 10)
1235 	{
1236 		if(i && upd > -13 && upd < 0/*13*/) break;
1237 		if(i > 60 && i < 300) continue;
1238 
1239 		j = ent->client->zc.moveyaw + i;
1240 
1241 		if(j > 180) j = j - 360;
1242 		else if(j < -180) j = j + 360;
1243 		else j = i;
1244 
1245 		touchmin[0] = cos(j) * 24 ;
1246 		touchmin[1] = sin(j) * 24 ;
1247 		touchmin[2] = 0;
1248 
1249 		VectorAdd(trmin,touchmin,trmax);
1250 		rs_trace = gi.trace (trmax/*ent->s.origin*/, ent->mins, ent->maxs, trmin,ent, MASK_BOTSOLIDX);
1251 
1252 //		yaw = VectorLength(trmax);
1253 		if(!rs_trace.allsolid && !rs_trace.startsolid )
1254 		{
1255 			VectorAdd(rs_trace.endpos,touchmin,trmax);
1256 			rs_trace = gi.trace (trmax, ent->mins, ent->maxs, trmax,ent, MASK_BOTSOLIDX);
1257 //gi.bprintf(PRINT_HIGH,"NGAAAAAAAAAAAAAAAAAAAAAAAAAAA!\n");
1258 
1259 //			VectorSubtract(rs_trace.endpos,ent->s.origin,trmax);
1260 			if(!rs_trace.allsolid && !rs_trace.startsolid )
1261 			{
1262 //gi.bprintf(PRINT_HIGH,"go go go!\n");
1263 				vec = i;break;
1264 			}
1265 		}
1266 	}
1267 
1268 	if(vec == -1)
1269 	{
1270 //gi.bprintf(PRINT_HIGH,"Water MOVE NG %f %f!\n",dist,upd);
1271 		return false;
1272 	}
1273 
1274 //gi.bprintf(PRINT_HIGH,"Water MOVE OK %f %f!\n",dist,upd);
1275 	VectorCopy(trmax,pos);
1276 	if(upd < 0) ent->velocity[2] = 0;
1277 	return true;
1278 
1279 	touchmin[0] = cos(vec) * 16;//dist ;
1280 	touchmin[1] = sin(vec) * 16;//dist ;
1281 	touchmin[2] = 0;
1282 
1283 	VectorAdd(ent->s.origin,touchmin,trmin);
1284 	VectorCopy(trmin,trmax);
1285 	trmax[2] += upd;
1286 	rs_trace = gi.trace (trmin, ent->mins, ent->maxs, trmax,ent, MASK_BOTSOLIDX);
1287 
1288 	if(rs_trace.allsolid || rs_trace.startsolid )
1289 	{
1290 		return false;
1291 	}
1292 
1293 	VectorCopy(rs_trace.endpos,pos);
1294 	return true;
1295 
1296 
1297 	VectorCopy(rs_trace.plane.normal,trmin);
1298 	trmin[2] = 0;
1299 	VectorNormalize(trmin);
1300 	VectorAdd(trmax,trmin,trmax);
1301 	for(i = 1.0;i < dist;i += 1.0)
1302 	{
1303 		rs_trace = gi.trace (trmax, ent->mins, ent->maxs,trmax,ent, MASK_BOTSOLIDX/*MASK_PLAYERSOLID*/);
1304 		if(!rs_trace.allsolid && !rs_trace.startsolid)
1305 		{
1306 			VectorCopy(trmax,pos);
1307 			return true;
1308 		}
1309 		VectorAdd(trmax,trmin,trmax);
1310 	}
1311 //	gi.bprintf(PRINT_HIGH,"failed2\n");
1312 	return false;
1313 }
1314 
Bot_moveW(edict_t * ent,float ryaw,vec3_t pos,float dist,float * bottom)1315 int Bot_moveW ( edict_t *ent,float ryaw,vec3_t pos,float dist,float *bottom)
1316 {
1317 	float		yaw;
1318 	vec3_t		trstart,trend;
1319 	trace_t		rs_trace;
1320 
1321 	int			contents;
1322 
1323 	int			tcontents;
1324 
1325 	if (ent->client->enviro_framenum > level.framenum) contents = CONTENTS_LAVA;
1326 	else contents = ( CONTENTS_LAVA | CONTENTS_SLIME);
1327 
1328 	tcontents = MASK_BOTSOLIDX/*MASK_PLAYERSOLID*/;
1329 	tcontents |= CONTENTS_WATER;
1330 
1331 	//�ړ��悪�ǂ��Ȃ��Ă���̂����ׂ�
1332 	yaw = ryaw*M_PI*2 / 360;
1333 	trend[0] = cos(yaw) * dist ;				//start
1334 	trend[1] = sin(yaw) * dist ;
1335 	trend[2] = 0;
1336 	VectorAdd (trend, ent->s.origin, trstart);
1337 
1338 	pos[0] = trstart[0];
1339 	pos[1] = trstart[1];
1340 	pos[2] = trstart[2];
1341 	VectorCopy (trstart, trend);
1342 
1343 	trstart[2] = trend[2] -8190;//95;
1344 	rs_trace = gi.trace (trend, ent->mins, ent->maxs, trstart,ent, tcontents);
1345 
1346 	if((trend[2] - rs_trace.endpos[2]) >= 95) return false;
1347 
1348 	if(rs_trace.contents & contents) return false;
1349 	if(!(rs_trace.contents & CONTENTS_WATER)) return false;
1350 
1351 	*bottom = rs_trace.endpos[2] - ent->s.origin[2];
1352 	return true;
1353 }
1354 
1355 //-----------------------------------------------------------------------------------------
1356 // Bank check
1357 //	true	safe
1358 //	false	danger
BankCheck(edict_t * ent,vec3_t pos)1359 qboolean BankCheck(edict_t *ent,vec3_t pos)
1360 {
1361 	trace_t	rs_trace;
1362 	vec3_t	end,v1,v2;
1363 
1364 	VectorSet(v1,-16,-16,-24);
1365 	VectorSet(v2,16,16,16);
1366 
1367 	VectorCopy(pos,end);
1368 
1369 	end[2] -= 5000;
1370 
1371 	rs_trace = gi.trace (pos, v1, v2,end,ent, MASK_BOTSOLIDX/*MASK_PLAYERSOLID*/);
1372 
1373 	if(rs_trace.startsolid || rs_trace.allsolid) return false;
1374 	if(rs_trace.plane.normal[2] < 0.8 ) return false;
1375 	return true;
1376 }
1377 
1378 
1379 //-----------------------------------------------------------------------------------------
1380 // hazard check
1381 //	true	safe
1382 //	false	danger
HazardCheck(edict_t * ent,vec3_t pos)1383 qboolean HazardCheck(edict_t *ent,vec3_t pos)
1384 {
1385 	trace_t	rs_trace;
1386 	vec3_t	end,v1,v2;
1387 	int		contents;
1388 
1389 	VectorSet(v1,-16,-16,-16);
1390 	VectorSet(v2,16,16,16);
1391 
1392 	VectorCopy(pos,end);
1393 
1394 	end[2] -= 8190;
1395 
1396 	if (ent->client->enviro_framenum > level.framenum) contents = CONTENTS_LAVA;
1397 	else contents = ( CONTENTS_LAVA | CONTENTS_SLIME);
1398 
1399 	rs_trace = gi.trace (pos, v1, v2,end,ent, MASK_OPAQUE);
1400 
1401 	if(rs_trace.contents & contents) return false;
1402 	return true;
1403 }
1404 
1405 //-----------------------------------------------------------------------------------------
1406 // bot's shot
1407 /*qboolean Bot_Shot()
1408 {
1409 
1410 
1411 	if( ent->client->weaponstate == WEAPON_READY)
1412 	{
1413 		if(trent->movetype == MOVETYPE_STOP && trent->classname)
1414 		{
1415 			&& trent->health && trent->moveinfo.state == 1
1416 				&& trent->takedamage)//trent->moveinfo.wait == 0)
1417 			{
1418 				trmax[0] = (trent->absmin[0] + trent->absmax[0]) / 2;
1419 				trmax[1] = (trent->absmin[1] + trent->absmax[1]) / 2;
1420 				trmax[2] = (trent->absmin[2] + trent->absmax[2]) / 2;
1421 				rs_trace = gi.trace (ent->s.origin, NULL, NULL, trmax ,ent, MASK_SHOT);
1422 
1423 				if(rs_trace.ent == trent)
1424 							{
1425 					//		gi.bprintf(PRINT_HIGH,"kkkkkkk\n");
1426 					//		continue;
1427 								VectorSubtract (trmax, ent->s.origin,trmin);
1428 								ent->client->ammo_index = 0;
1429 								ent->client->pers.weapon = FindItem("Blaster");
1430 								ShowGun(ent);
1431 								ent->s.angles[YAW] = Get_yaw(trmin);
1432 								ent->s.angles[PITCH] = Get_pitch(trmin);
1433 								ent->client->buttons |= BUTTON_ATTACK;
1434 								ent->client->zc.objshot = true;
1435 							}
1436 						}
1437 					}
1438 				}
1439 
1440 */
1441 //-----------------------------------------------------------------------------------------
1442 // set the bot's combatstate
1443 
Set_Combatstate(edict_t * ent,int foundedenemy)1444 void Set_Combatstate(edict_t *ent,int foundedenemy)
1445 {
1446 	vec3_t	v;
1447 	gclient_t	*client;
1448 	float	distance;
1449 	edict_t	*target;
1450 	int		enewep;
1451 	int		combskill;
1452 	float	aim;
1453 
1454 	client = ent->client;
1455 
1456 	target = client->zc.first_target;
1457 
1458 	if(client->zc.zcstate & STS_LADDERUP) return;
1459 
1460 	if(target == NULL)
1461 	{
1462 		client->zc.zccmbstt &= ~CTS_COMBS; // clear status
1463 		return;
1464 	}
1465 
1466 	//target is dead
1467 	if(!target->inuse || target->deadflag || target->solid != SOLID_BBOX)
1468 	{
1469 		client->zc.battleduckcnt = 0;
1470 		client->zc.first_target = NULL;
1471 		client->zc.zccmbstt &= ~CTS_COMBS; //clear status
1472 
1473 		if((9 * random()) < Bot[client->zc.botindex].param[BOP_COMBATSKILL])
1474 															UsePrimaryWeapon(ent);
1475 		return;
1476 	}
1477 
1478 	if(!Bot_trace(ent,target))
1479 	{
1480 		if(client->zc.targetlock <= level.time)
1481 		{
1482 			client->zc.first_target = NULL;
1483 			return;
1484 		}
1485 		client->zc.zccmbstt |= CTS_ENEM_NSEE;//can't see
1486 //		return;
1487 	}
1488 	else
1489 	{
1490 		ent->client->zc.targetlock = level.time + FRAMETIME * 12;
1491 		ent->client->zc.zccmbstt &= ~CTS_ENEM_NSEE;//can see
1492 		ent->client->zc.battlemode &= ~FIRE_ESTIMATE;
1493 	}
1494 
1495 	VectorSubtract(target->s.origin,ent->s.origin,v);
1496 	distance = VectorLength(v);
1497 
1498 	//enemy's weapon
1499 	enewep = Get_KindWeapon(target->client->pers.weapon);
1500 
1501 	//status set
1502 	aim = 10.0 - (float)Bot[client->zc.botindex].param[BOP_AIM];
1503 	if(aim <= 0 || aim > 10) aim = 5;
1504 	combskill = (int)Bot[client->zc.botindex].param[BOP_COMBATSKILL];
1505 	if(combskill < 0 || combskill > 9) combskill = 5;
1506 
1507 
1508 	if(!(client->zc.zccmbstt & CTS_ENEM_NSEE)) Combat_Level0(ent,foundedenemy,enewep,aim,distance,combskill);
1509 	else if(client->zc.zccmbstt & FIRE_REFUGE) Combat_Level0(ent,foundedenemy,enewep,aim,distance,combskill);
1510 	else Combat_LevelX(ent,foundedenemy,enewep,aim,distance,combskill);
1511 
1512 	if(client->zc.first_target)
1513 	{
1514 		client->zc.last_target = client->zc.first_target;
1515 		VectorCopy(client->zc.first_target->s.origin,client->zc.last_pos);
1516 	}
1517 	return;
1518 }
1519 
1520 //-----------------------------------------------------------------------------------------
1521 // Bot Jump
1522 // return true		sequaense done
1523 // return false		failed
Get_FlyingSpeed(float bottom,float block,float dist,float * speed)1524 qboolean Get_FlyingSpeed(float bottom,float block,float dist,float *speed)
1525 {
1526 	float tdist;
1527 
1528 	if(bottom >= 40)
1529 	{
1530 		if(block > 4 ) return false;
1531 		tdist = (dist * block) / 4 ;
1532 	}
1533 	else if(bottom >= 35)
1534 	{
1535 		if(block > 5) return false;
1536 		tdist = (dist * block) / 5 ;
1537 	}
1538 	else if(bottom >= 30)
1539 	{
1540 		if(block > 6) return false;
1541 		tdist = (dist * block) / 6 ;
1542 	}
1543 	else if(bottom >= 20)
1544 	{
1545 		if(block > 7) return false;
1546 		tdist = (dist * block) / 7 ;
1547 	}
1548 	else if(bottom >= -5)
1549 	{
1550 		if(block > 8 ) return false;
1551 		tdist = (dist * block) / 8 ;
1552 	}
1553 	else if(bottom >= -20)
1554 	{
1555 		if(block > 9) return false;
1556 		tdist = (dist * block) / 7;
1557 	}
1558 	else if(bottom >= -35)
1559 	{
1560 		if(block > 10) return false;
1561 		tdist = (dist * block) / 6 ;
1562 	}
1563 	else if(bottom >= -52)
1564 	{
1565 		if(block > 11) return false;
1566 		tdist = (dist * block) / 5;
1567 	}
1568 	else if(bottom >= -75)
1569 	{
1570 		if(block > 12) return false;
1571 		tdist = (dist * block) / 4;
1572 	}
1573 	else if(bottom >= -95)
1574 	{
1575 		if(block > 13) return false;
1576 		tdist = (dist * block) / 3;
1577 	}
1578 	else if(bottom >= - 125)
1579 	{
1580 		if(block > 14) return false;
1581 		tdist = (dist * block) / 2;
1582 	}
1583 	else
1584 	{
1585 		if(block > 15) return false;
1586 		tdist = (dist * block) / 2;
1587 	}
1588 
1589 	*speed = tdist / MOVE_SPD_RUN;
1590 	return true;
1591 }
1592 
Bot_Jump(edict_t * ent,vec3_t pos,float dist)1593 qboolean Bot_Jump(edict_t *ent,vec3_t pos,float dist)
1594 {
1595 	float	x,yaw,tdist,bottom,speed;
1596 	vec3_t	temppos;
1597 	zgcl_t	*zc;
1598 
1599 	zc = &ent->client->zc;
1600 
1601 	yaw = zc->moveyaw;
1602 
1603 	Bot_moveT (ent,yaw,temppos,dist,&bottom);
1604 	if(bottom > -JumpMax) return false;
1605 
1606 	for( x = 2 ; x <= 16; x += 1)
1607 	{
1608 		tdist = dist * x;
1609 		if( Bot_moveT (ent,yaw,temppos,tdist,&bottom) == true)
1610 		{
1611 			if( x == 2 && ( bottom > - JumpMax ) && bottom <= 0)
1612 			{
1613 				VectorCopy( pos,ent->s.origin);
1614 				return true;
1615 			}
1616 			if( bottom <= JumpMax && bottom > -JumpMax)
1617 			{
1618 				if(Get_FlyingSpeed(bottom,x,dist,&speed))
1619 				{
1620 					speed *= 1.5;
1621 					if(speed > 1.2) speed = 1.2;
1622 					ent->moveinfo.speed = speed;
1623 					ent->velocity[2] += VEL_BOT_JUMP;
1624 					gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
1625 					PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
1626 					Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
1627 //					ent->s.frame = FRAME_jump1-1;
1628 //					ent->client->anim_end = FRAME_jump6;
1629 //					ent->client->anim_priority = ANIM_JUMP;
1630 					return true;
1631 				}
1632 			}
1633 			continue;
1634 		}
1635 		else return false;
1636 	}
1637 	return false;
1638 }
1639 
1640 //-----------------------------------------------------------------------------------------
1641 // Bot Fall
1642 // return true		sequaense done
1643 // return false		failed
1644 
Bot_Fall(edict_t * ent,vec3_t pos,float dist)1645 qboolean Bot_Fall(edict_t *ent,vec3_t pos,float dist)
1646 {
1647 	zgcl_t	*zc;
1648 	float	x,l,speed,grav,vel,ypos,yori;
1649 	vec3_t	v,vv;
1650 	int		mf = false;
1651 	short	mode = 0;
1652 
1653 	zc = &ent->client->zc;
1654 
1655 	if(zc->second_target != NULL)// && !(zc.zcstate & STS_COMBS))
1656 	{
1657 		mode = 1;
1658 		ypos = zc->second_target->s.origin[2];
1659 
1660 		//if on hazard object cause error
1661 		if(!HazardCheck(ent,zc->second_target->s.origin))
1662 		{
1663 			zc->second_target = NULL;
1664 			return false;
1665 		}
1666 
1667 		yori = ent->s.origin[2];
1668 		VectorSubtract(zc->second_target->s.origin,pos,v);
1669 
1670 		grav = ent->gravity * sv_gravity->value * FRAMETIME;
1671 		if(v[2] > 0) goto JMPCHK;
1672 
1673 		vel = ent->velocity[2];
1674 //		grav = ent->gravity * sv_gravity->value * FRAMETIME;
1675 		l = 1.0;
1676 		for(x = 1;x <= FALLCHK_LOOPMAX;++x ,l += x )
1677 		{
1678 			vel -= grav;// * l;
1679 			yori += vel * FRAMETIME;
1680 			if(ypos >= yori)
1681 			{
1682 				mf = true;
1683 				break;
1684 			}
1685 		}
1686 		VectorCopy(v,vv);
1687 		vv[2] = 0;
1688 		l = VectorLength(vv);
1689 		speed = l / x;
1690 		if(speed <= MOVE_SPD_RUN && mf)
1691 		{
1692 			ent->moveinfo.speed = speed / MOVE_SPD_RUN;
1693 			VectorCopy(pos,ent->s.origin);
1694 			return true;
1695 		}
1696 		goto JUMPCATCH;
1697 	}
1698 	else if(zc->route_trace)
1699 	{
1700 //gi.bprintf(PRINT_HIGH,"fall\n");
1701 		mode = 2;
1702 		Get_RouteOrigin(zc->routeindex,vv);
1703 		ypos = vv[2];
1704 
1705 		//if on hazard object cause error
1706 		if(!HazardCheck(ent,vv))
1707 		{
1708 			if(++zc->routeindex >= CurrentIndex) zc->routeindex = 0;
1709 
1710 //gi.bprintf(PRINT_HIGH,"OFF 1\n"); //ppx
1711 //gi.bprintf(PRINT_HIGH,"hazard out\n");
1712 //			zc->route_trace = false;
1713 			return false;
1714 		}
1715 
1716 		yori = pos[2];
1717 		VectorSubtract(vv,pos,v);
1718 
1719 		grav = ent->gravity * sv_gravity->value * FRAMETIME;
1720 		if(v[2] >= 0/*-8*/) goto JUMPCATCH;//JMPCHK;
1721 
1722 		vel = ent->velocity[2];
1723 		//grav = ent->gravity * sv_gravity->value * FRAMETIME;
1724 		l = 1.0;
1725 		for(x = 1;x <= FALLCHK_LOOPMAX;++x ,l += x )
1726 		{
1727 			vel -= grav;// * l;
1728 			yori += vel * FRAMETIME;
1729 			if(ypos >= yori)
1730 			{
1731 				mf = true;
1732 				break;
1733 			}
1734 		}
1735 
1736 		VectorCopy(v,vv);
1737 		vv[2] = 0;
1738 		//vel�l���̗���
1739 		if(Route[zc->routeindex].state == GRS_ONTRAIN)
1740 		{
1741 			if(1/*Route[zc->routeindex].ent->trainteam == NULL*/)
1742 			{
1743 				vv[0] += FRAMETIME * Route[zc->routeindex].ent->velocity[0] * x;
1744 				vv[1] += FRAMETIME * Route[zc->routeindex].ent->velocity[1] * x;
1745 			}
1746 		}
1747 
1748 		l = VectorLength(vv);
1749 		speed = l / x;
1750 		if(speed <= MOVE_SPD_RUN && mf)
1751 		{
1752 //gi.bprintf(PRINT_HIGH,"fall do\n");
1753 			ent->moveinfo.speed = speed / MOVE_SPD_RUN;
1754 			VectorCopy(pos,ent->s.origin);
1755 			return true;
1756 		}
1757 		goto JUMPCATCH;
1758 	}
1759 	goto JMPCHK;
1760 
1761 JUMPCATCH:
1762 	vel = ent->velocity[2] + VEL_BOT_JUMP;
1763 	yori = pos[2];
1764 //	l = 1.0;
1765 //	VectorCopy(v,vv);
1766 //	vv[2] = 0;
1767 //	l = VectorLength(vv);
1768 //gi.bprintf(PRINT_HIGH,"J fall\n");
1769 	mf = false;
1770 	for(x = 1;x <= FALLCHK_LOOPMAX;++x /*,l += x*/ )
1771 	{
1772 		vel -= grav;
1773 		yori += vel * FRAMETIME;
1774 
1775 		if(vel > 0)
1776 		{
1777 			if(mf == false)
1778 			{
1779 				if(ypos < yori) mf = 2;
1780 //gi.bprintf(PRINT_HIGH,"pre ok\n");
1781 			}
1782 /*			else if(mf == 2)
1783 			{
1784 				if(ypos >= yori)
1785 					if((l / x) < MOVE_SPD_RUN)
1786 					{
1787 						mf = true;
1788 						break;
1789 					}
1790 			}*/
1791 		}
1792 		else if(x > 1)
1793 		{
1794 //gi.bprintf(PRINT_HIGH,"oops\n");
1795 			if(mf == false)
1796 			{
1797 				if(ypos < yori) mf = 2;
1798 			}
1799 
1800 			else if(mf == 2)
1801 			{
1802 				if(ypos >= yori)
1803 				{
1804 /*					if((l / (x - 1)) <= MOVE_SPD_RUN)
1805 					{*/
1806 //gi.bprintf(PRINT_HIGH,"Go %f\n",l / x);
1807 						mf = true;
1808 						break;
1809 //					}
1810 				}
1811 			}
1812 		}
1813 	}
1814 	VectorCopy(v,vv);
1815 	vv[2] = 0;
1816 	if(mode == 2)
1817 	{
1818 		//vel�l���̗���
1819 		if(Route[zc->routeindex].state == GRS_ONTRAIN)
1820 		{
1821 			if(1/*Route[zc->routeindex].ent->trainteam == NULL*/)
1822 			{
1823 //gi.bprintf(PRINT_HIGH,"Go!\n"); //ppx
1824 				vv[0] += FRAMETIME * Route[zc->routeindex].ent->velocity[0] * x;
1825 				vv[1] += FRAMETIME * Route[zc->routeindex].ent->velocity[1] * x;
1826 			}
1827 		}
1828 	}
1829 	l = VectorLength(vv);
1830 
1831 	if(x > 1) l = l / (x - 1);
1832 	if(l < MOVE_SPD_RUN && mf == true)
1833 	{
1834 		ent->moveinfo.speed = l / MOVE_SPD_RUN;
1835 		VectorCopy(pos,ent->s.origin);
1836 
1837 		ent->velocity[2] += VEL_BOT_JUMP;
1838 		gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
1839 		PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
1840 		Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
1841 //		ent->s.frame = FRAME_jump1-1;
1842 //		ent->client->anim_end = FRAME_jump6;
1843 //		ent->client->anim_priority = ANIM_JUMP;
1844 //gi.bprintf(PRINT_HIGH,"j fall do\n");
1845 		return true;
1846 	}
1847 
1848 	if(mode == 1) goto JMPCHK;//zc->second_target = NULL;
1849 //ponko	else zc->route_trace = false;
1850 //gi.bprintf(PRINT_HIGH,"j fall false\n");
1851 //	return false;
1852 JMPCHK:
1853 //gi.bprintf(PRINT_HIGH,"NJ \n");
1854 	if(Bot_Jump(ent,pos,dist)) return true;
1855 
1856 //gi.bprintf(PRINT_HIGH,"NJ FAIL\n");
1857 	zc->second_target = NULL;
1858 	return false;
1859 }
1860 //-----------------------------------------------------------------------------------------
1861 // target jump
1862 
TargetJump(edict_t * ent,vec3_t tpos)1863 qboolean TargetJump(edict_t *ent,vec3_t tpos)
1864 {
1865 	zgcl_t	*zc;
1866 	float	x,l,grav,vel,ypos,yori;
1867 	vec3_t	v,vv;
1868 	int		mf = false;
1869 
1870 	zc = &ent->client->zc;
1871 	grav = ent->gravity * sv_gravity->value * FRAMETIME;
1872 
1873 	vel = ent->velocity[2] + VEL_BOT_JUMP;
1874 	yori = ent->s.origin[2];
1875 	ypos = tpos[2];
1876 
1877 	//if on hazard object cause error
1878 	if(!HazardCheck(ent,tpos))	return false;
1879 
1880 	VectorSubtract(tpos,ent->s.origin,v);
1881 
1882 	for(x = 1;x <= FALLCHK_LOOPMAX * 2 ;++x )
1883 	{
1884 		vel -= grav;
1885 		yori += vel * FRAMETIME;
1886 
1887 		if(vel > 0)
1888 		{
1889 			if(mf == false)
1890 			{
1891 				if(ypos < yori) mf = 2;
1892 			}
1893 		}
1894 		else if(x > 1)
1895 		{
1896 			if(mf == false)
1897 			{
1898 				if(ypos < yori) mf = 2;
1899 			}
1900 
1901 			else if(mf == 2)
1902 			{
1903 				if(ypos >= yori)
1904 				{
1905 						mf = true;
1906 						break;
1907 				}
1908 			}
1909 		}
1910 	}
1911 	VectorCopy(v,vv);
1912 	vv[2] = 0;
1913 
1914 	l = VectorLength(vv);
1915 
1916 	if(x > 1) l = l / (x - 1);
1917 	if(l < MOVE_SPD_RUN && mf == true)
1918 	{
1919 		ent->moveinfo.speed = l / MOVE_SPD_RUN;
1920 
1921 		ent->velocity[2] += VEL_BOT_JUMP;
1922 		gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
1923 		PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
1924 		Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
1925 		return true;
1926 	}
1927 	return false;
1928 }
1929 
TargetJump_Turbo(edict_t * ent,vec3_t tpos)1930 qboolean TargetJump_Turbo(edict_t *ent,vec3_t tpos)
1931 {
1932 	zgcl_t	*zc;
1933 	float	x,l,grav,vel,ypos,yori;
1934 	vec3_t	v,vv;
1935 	int		mf = false;
1936 	float	jvel;
1937 
1938 	zc = &ent->client->zc;
1939 	grav = ent->gravity * sv_gravity->value * FRAMETIME;
1940 
1941 	vel = ent->velocity[2] + VEL_BOT_JUMP;
1942 
1943 //if(vel > (VEL_BOT_JUMP + 100 + ent->gravity * sv_gravity->value * FRAMETIME ))
1944 //	vel = VEL_BOT_JUMP + 100 + ent->gravity * sv_gravity->value * FRAMETIME;
1945 	jvel = vel;
1946 
1947 	yori = ent->s.origin[2];
1948 	ypos = tpos[2];
1949 
1950 	//if on hazard object cause error
1951 	if(!HazardCheck(ent,tpos))	return false;
1952 
1953 	VectorSubtract(tpos,ent->s.origin,v);
1954 
1955 	for(x = 1;x <= FALLCHK_LOOPMAX * 2 ;++x )
1956 	{
1957 		vel -= grav;
1958 		yori += vel * FRAMETIME;
1959 
1960 		if(vel > 0)
1961 		{
1962 			if(mf == false)
1963 			{
1964 				if(ypos < yori) mf = 2;
1965 			}
1966 		}
1967 		else if(x > 1)
1968 		{
1969 			if(mf == false)
1970 			{
1971 				if(ypos < yori) mf = 2;
1972 			}
1973 
1974 			else if(mf == 2)
1975 			{
1976 				if(ypos >= yori)
1977 				{
1978 						mf = true;
1979 						break;
1980 				}
1981 			}
1982 		}
1983 	}
1984 	VectorCopy(v,vv);
1985 	vv[2] = 0;
1986 
1987 	l = VectorLength(vv);
1988 
1989 	if(x > 1) l = l / (x - 1);
1990 	if(l < MOVE_SPD_RUN && mf == true)
1991 	{
1992 		ent->moveinfo.speed = l / MOVE_SPD_RUN;
1993 //		VectorCopy(pos,ent->s.origin);
1994 
1995 		ent->velocity[2] = jvel;//VEL_BOT_JUMP;
1996 		gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
1997 		PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
1998 		Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
1999 //		ent->s.frame = FRAME_jump1-1;
2000 //		ent->client->anim_end = FRAME_jump6;
2001 //		ent->client->anim_priority = ANIM_JUMP;
2002 		return true;
2003 	}
2004 	return false;
2005 }
TargetJump_Chk(edict_t * ent,vec3_t tpos,float defvel)2006 qboolean TargetJump_Chk(edict_t *ent,vec3_t tpos,float defvel)
2007 {
2008 	zgcl_t	*zc;
2009 	float	x,l,grav,vel,ypos,yori;
2010 	vec3_t	v,vv;
2011 	int		mf = false;
2012 
2013 	zc = &ent->client->zc;
2014 	grav = ent->gravity * sv_gravity->value * FRAMETIME;
2015 
2016 	vel = defvel + VEL_BOT_JUMP;
2017 	yori = ent->s.origin[2];
2018 	ypos = tpos[2];
2019 
2020 	//if on hazard object cause error
2021 	if(!HazardCheck(ent,tpos))	return false;
2022 
2023 	VectorSubtract(tpos,ent->s.origin,v);
2024 
2025 	for(x = 1;x <= FALLCHK_LOOPMAX * 2 ;++x )
2026 	{
2027 		vel -= grav;
2028 		yori += vel * FRAMETIME;
2029 
2030 		if(vel > 0)
2031 		{
2032 			if(mf == false)
2033 			{
2034 				if(ypos < yori) mf = 2;
2035 			}
2036 		}
2037 		else if(x > 1)
2038 		{
2039 			if(mf == false)
2040 			{
2041 				if(ypos < yori) mf = 2;
2042 			}
2043 
2044 			else if(mf == 2)
2045 			{
2046 				if(ypos >= yori)
2047 				{
2048 						mf = true;
2049 						break;
2050 				}
2051 			}
2052 		}
2053 	}
2054 	VectorCopy(v,vv);
2055 	vv[2] = 0;
2056 
2057 	l = VectorLength(vv);
2058 
2059 	if(x > 1) l = l / (x - 1);
2060 	if(l < MOVE_SPD_RUN && mf == true)
2061 	{
2062 		return true;
2063 	}
2064 	return false;
2065 }
2066 //-----------------------------------------------------------------------------------------
2067 // set anim
Set_BotAnim(edict_t * ent,int anim,int frame,int end)2068 void Set_BotAnim(edict_t *ent,int anim,int frame,int end)
2069 {
2070 	if(ent->client->anim_priority < anim)
2071 	{
2072 		ent->s.frame = frame;
2073 		ent->client->anim_end = end;
2074 	}
2075 }
2076 
2077 
2078 //-----------------------------------------------------------------------------------------
2079 // Get Water State
Get_WaterState(edict_t * ent)2080 void Get_WaterState(edict_t *ent)
2081 {
2082 	zgcl_t	*zc;
2083 	vec3_t	trmin,trmax;
2084 	float	x;
2085 	trace_t		rs_trace;
2086 
2087 	zc = &ent->client->zc;
2088 
2089 	//---------------
2090 	//get waterstate
2091 	if(ent->waterlevel)
2092 	{
2093 		VectorCopy(ent->s.origin,trmax);
2094 		VectorCopy(ent->s.origin,trmin);
2095 		trmax[2] -= 24;
2096 		trmin[2] += 8;
2097 
2098 		rs_trace = gi.trace (trmin, NULL,NULL,trmax,ent, MASK_WATER );
2099 		x = trmin[2] - rs_trace.endpos[2];
2100 
2101 		if(rs_trace.allsolid || rs_trace.startsolid || (/*x >= 4 &&*/ x < 4.0 )) zc->waterstate = WAS_IN;
2102 		else
2103 		{
2104 
2105 			if(x >= 4.0 && x <= 12.0 ) zc->waterstate = WAS_FLOAT;
2106 			else zc->waterstate = WAS_NONE;
2107 		}
2108 	}
2109 	else zc->waterstate = WAS_NONE;
2110 }
2111 
2112 
2113 //-----------------------------------------------------------------------------------------
2114 // Get origin of Route Index
Get_RouteOrigin(int index,vec3_t pos)2115 void Get_RouteOrigin(int index,vec3_t pos)
2116 {
2117 	edict_t	*e;
2118 
2119 	//when normal or items
2120 	if(Route[index].state <= GRS_ITEMS || Route[index].state >= GRS_GRAPSHOT)
2121 	{
2122 		if(Route[index].state == GRS_ITEMS)
2123 		{
2124 			VectorCopy(Route[index].ent->s.origin,pos);
2125 			pos[2] += 8;
2126 		}
2127 		else VectorCopy(Route[index].Pt,pos);
2128 
2129 	}
2130 	//when plat
2131 	else if(Route[index].state == GRS_ONPLAT)
2132 	{
2133 		VectorCopy(Route[index].ent->union_ent->s.origin,pos);
2134 		pos[2] += 8;
2135 	}
2136 	//when train
2137 	else if(Route[index].state == GRS_ONTRAIN)
2138 	{
2139 		if(Route[index].ent->trainteam == NULL)
2140 		{
2141 			VectorCopy(Route[index].ent->union_ent->s.origin,pos);
2142 			pos[2] += 8;
2143 			return;
2144 		}
2145 		if(Route[index].ent->target_ent)
2146 		{
2147 			if(VectorCompare(Route[index].Tcourner,Route[index].ent->target_ent->s.origin))
2148 			{
2149 				VectorCopy(Route[index].ent->union_ent->s.origin,pos);
2150 				pos[2] += 8;
2151 				return;
2152 			}
2153 		}
2154 		e = Route[index].ent->trainteam;
2155 		while(1)
2156 		{
2157 			if(e == Route[index].ent) break;
2158 			if(e->target_ent)
2159 			{
2160 				if(VectorCompare(Route[index].Tcourner,e->target_ent->s.origin))
2161 				{
2162 					VectorCopy(e->union_ent->s.origin,pos);
2163 					pos[2] += 8;
2164 					Route[index].ent = e;
2165 					return;
2166 				}
2167 			}
2168 			e = e->trainteam;
2169 		}
2170 		VectorCopy(Route[index].ent->union_ent->s.origin,pos);
2171 		pos[2] += 8;
2172 		return;
2173 	}
2174 	else if(Route[index].state == GRS_ONDOOR)
2175 	{
2176 		if(Route[index].ent->union_ent)
2177 		{
2178 			VectorCopy(Route[index].ent->union_ent->s.origin,pos);
2179 			pos[2] += 8;
2180 		}
2181 		else if(index + 1 < CurrentIndex)
2182 		{
2183 			if(Route[index + 1].state <= GRS_ITEMS )
2184 			{
2185 				VectorCopy(Route[index + 1].Pt,pos);
2186 				if(Route[index + 1].state == GRS_ITEMS) pos[2] += 8;
2187 				pos[2] += 8;
2188 			}
2189 			//when plat or train
2190 			else if(Route[index + 1].state <= GRS_ONTRAIN)
2191 			{
2192 				VectorCopy(Route[index + 1].ent->union_ent->s.origin,pos);
2193 				pos[2] += 8;
2194 			}
2195 			else if(Route[index + 1].state == GRS_PUSHBUTTON)
2196 			{
2197 				VectorCopy(Route[index + 1].ent->union_ent->s.origin,pos);
2198 				pos[2] += 8;
2199 			}
2200 			else VectorCopy(Route[index + 1].Pt,pos);
2201 		}
2202 		else
2203 		{
2204 			pos[0] = (Route[index].ent->absmin[0] + Route[index].ent->absmax[0]) / 2;
2205 			pos[1] = (Route[index].ent->absmin[1] + Route[index].ent->absmax[1]) / 2;
2206 			pos[2] = Route[index].ent->absmax[2];
2207 		}
2208 	}
2209 	else if(Route[index].state == GRS_PUSHBUTTON) VectorCopy(Route[index].ent->union_ent->s.origin,pos);
2210 }
2211 
2212 //-----------------------------------------------------------------------------------------
2213 // search nearly pod
Search_NearlyPod(edict_t * ent)2214 void Search_NearlyPod(edict_t *ent)
2215 {
2216 	vec3_t	v,v1,v2;
2217 	float x;
2218 
2219 	if(Route[ent->client->zc.routeindex].state >= GRS_ITEMS)	return;
2220 //	else if(Route[ent->client->zc.routeindex].state ==/*>=*/ GRS_ITEMS)
2221 //	{
2222 //		if(Route[ent->client->zc.routeindex].ent->solid != SOLID_TRIGGER) return;
2223 //	}
2224 
2225 	if((ent->client->zc.routeindex + 1) < CurrentIndex)
2226 	{
2227 		if(Route[ent->client->zc.routeindex + 1].state >= GRS_ITEMS)	return;
2228 		Get_RouteOrigin(ent->client->zc.routeindex + 1,v);
2229 		if(TraceX(ent,v))
2230 		{
2231 			VectorSubtract(v,ent->s.origin,v1);
2232 
2233 			Get_RouteOrigin(ent->client->zc.routeindex,v);
2234 			VectorSubtract(v,ent->s.origin,v2);
2235 			x = fabs(v1[2]);
2236 
2237 			if(VectorLength(v1) < VectorLength(v2) && x <= JumpMax
2238 				&& Route[ent->client->zc.routeindex].state <= GRS_ONROTATE)
2239 			{
2240 				ent->client->zc.routeindex++;
2241 			}
2242 			else if(ent->client->zc.waterstate) return;
2243 			else if(v2[2] > JumpMax && fabs(v1[2]) < JumpMax) ent->client->zc.routeindex++;
2244 
2245 		}
2246 	}
2247 }
2248 
Get_KindWeapon(gitem_t * it)2249 int Get_KindWeapon(gitem_t	*it)
2250 {
2251 	if(it == NULL) return WEAP_BLASTER;
2252 
2253 	if(it->weaponthink		== Weapon_Shotgun)		return WEAP_SHOTGUN;
2254 	else if(it->weaponthink == Weapon_SuperShotgun) return WEAP_SUPERSHOTGUN;
2255 	else if(it->weaponthink == Weapon_Machinegun)	return WEAP_MACHINEGUN;
2256 	else if(it->weaponthink == Weapon_Chaingun)		return WEAP_CHAINGUN;
2257 	else if(it->weaponthink == Weapon_Grenade)		return WEAP_GRENADES;
2258 	else if(it->weaponthink == Weapon_Trap)			return WEAP_TRAP;
2259 	else if(it->weaponthink == Weapon_GrenadeLauncher)	return WEAP_GRENADELAUNCHER;
2260 	else if(it->weaponthink == Weapon_RocketLauncher)	return WEAP_ROCKETLAUNCHER;
2261 	else if(it->weaponthink == Weapon_HyperBlaster) return WEAP_HYPERBLASTER;
2262 	else if(it->weaponthink == Weapon_Ionripper)	return WEAP_BOOMER;
2263 	else if(it->weaponthink == Weapon_Railgun)		return WEAP_RAILGUN;
2264 	else if(it->weaponthink == Weapon_Phalanx)		return WEAP_PHALANX;
2265 	else if(it->weaponthink == Weapon_BFG)			return WEAP_BFG;
2266 	else if(it->weaponthink == CTFWeapon_Grapple)	return WEAP_GRAPPLE;
2267 	else return WEAP_BLASTER;
2268 }
2269 
2270 //-----------------------------------------------------------------------------------------
2271 //
2272 //
2273 //
2274 // normal bot's AI
2275 //
2276 //
2277 //
2278 //-----------------------------------------------------------------------------------------
2279 
Bots_Move_NORM(edict_t * ent)2280 void Bots_Move_NORM (edict_t *ent)
2281 {
2282 	float		dist;		//moving distance
2283 	zgcl_t		*zc;		//zc's address
2284 
2285 	int			foundedenemy;
2286 
2287 	gitem_t		*item;
2288 
2289 	float		x,yaw,iyaw,f1,f2,f3,bottom;
2290 	qboolean	tempflag;//,buttonuse;
2291 	vec3_t		temppos;
2292 
2293 	trace_t		rs_trace;
2294 	edict_t		*touch[MAX_EDICTS],*trent;
2295 	vec3_t		touchmin,touchmax,v,vv;
2296 	vec3_t		trmin,trmax;
2297 	int			i,j,k;
2298 	qboolean	canrocj,waterjumped;
2299 	edict_t		*it_ent;
2300 	gitem_t		*it;
2301 
2302 	edict_t		*front,*left,*right,*e;
2303 
2304 	char		*string;
2305 
2306 	cplane_t	plane;
2307 
2308 	vec3_t		Origin,Velocity;//original param
2309 	float		OYaw;			//
2310 
2311 	qboolean	ladderdrop;
2312 
2313 
2314 	trace_priority = TRP_NORMAL;	//trace on
2315 
2316 	zc = &ent->client->zc;		//client add
2317 
2318 	ent->client->zc.objshot = false;		//object shot clear
2319 
2320 	ent->client->buttons &= ~BUTTON_ATTACK;
2321 
2322 	//--------------------------------------------------------------------------------------
2323 	//Solid Check
2324 	i = gi.pointcontents (ent->s.origin);
2325 	if(i & CONTENTS_SOLID)
2326 	T_Damage (ent, ent, ent, ent->s.origin, ent->s.origin, ent->s.origin,100 , 1, 0, MOD_CRUSH);
2327 
2328 
2329 	if(VectorCompare(ent->s.origin,ent->s.old_origin))
2330 	{
2331 		if(ent->groundentity == NULL && !ent->waterlevel)
2332 		{
2333 			VectorCopy(ent->s.origin,v);
2334 			v[2] -= 1.0;
2335 			rs_trace = gi.trace(ent->s.origin,ent->mins,ent->maxs,v,ent,MASK_BOTSOLIDX);
2336 			if(!rs_trace.allsolid && !rs_trace.startsolid) ent->groundentity = rs_trace.ent;
2337 		}
2338 	}
2339 	//	VectorCopy(ent->s.origin,Origin);
2340 //	VectorCopy(ent->velocity,Velocity);
2341 //	OYaw = ent->s.angles[YAW];
2342 
2343 	//--------------------------------------------------------------------------------------
2344 	//Check Debug mode
2345 	if(chedit->value)
2346 	{
2347 		j = false;
2348 		if(!zc->route_trace )
2349 		{
2350 //gi.bprintf(PRINT_HIGH,"route off\n");
2351 			j = true;
2352 		}
2353 		if(zc->routeindex >= CurrentIndex)
2354 		{
2355 //gi.bprintf(PRINT_HIGH,"index overflow\n");
2356 			j = true;
2357 		}
2358 		else if(Route[zc->routeindex].index == 0 && zc->routeindex > 0)
2359 		{
2360 //gi.bprintf(PRINT_HIGH,"index end\n");
2361 			j = true;
2362 		}
2363 
2364 		if(j)
2365 		{
2366 			RemoveBot();
2367 			//gi.cprintf(NULL,PRINT_HIGH,"Tracing failed.\n");
2368 			return;
2369 		}
2370 	}
2371 	//--------------------------------------------------------------------------------------
2372 	//get JumpMax
2373 	if(JumpMax == 0)
2374 	{
2375 		x = /*ent->velocity[2] + */ VEL_BOT_JUMP - ent->gravity * sv_gravity->value * FRAMETIME;
2376 		JumpMax = 0;
2377 		while(1)
2378 		{
2379 			JumpMax += x * FRAMETIME;
2380 			x -= ent->gravity * sv_gravity->value * FRAMETIME;
2381 			if( x < 0 ) break;
2382 		}
2383 //gi.bprintf(PRINT_HIGH,"JumpMax %f",JumpMax);
2384 	}
2385 /*	if(!JmpTableChk)
2386 	{
2387 
2388 
2389 	}*/
2390 	//--------------------------------------------------------------------------------------
2391 	//target set
2392 	if(!zc->havetarget && zc->route_trace)
2393 	{
2394 		k = 0;
2395 		//primary weapon
2396 		j = mpindex[Bot[zc->botindex].param[BOP_PRIWEP]];
2397 		//secondary weapon
2398 //		if(j && ent->client->pers.inventory[j]) j = mpindex[Bot[zc->botindex].param[BOP_SECWEP]];
2399 
2400 		//ctf
2401 		if(0/*ctf->value && bot_team_flag1 && bot_team_flag2*/)
2402 		{
2403 			it = NULL;
2404 			if(ent->client->resp.ctf_team == CTF_TEAM1)
2405 			{
2406 				if(zc->ctfstate == CTFS_DEFENDER || zc->ctfstate == CTFS_CARRIER) it = bot_team_flag1->item;
2407 				else if(zc->ctfstate == CTFS_OFFENCER) it = bot_team_flag2->item;
2408 			}
2409 			else if(ent->client->resp.ctf_team == CTF_TEAM2)
2410 			{
2411 				if(zc->ctfstate == CTFS_DEFENDER || zc->ctfstate == CTFS_CARRIER) it = bot_team_flag2->item;
2412 				else if(zc->ctfstate == CTFS_OFFENCER) it = bot_team_flag1->item;
2413 			}
2414 			if(it) {k = true;}
2415 		}
2416 if(ctf->value) j = 0;
2417 		if((j && !ent->client->pers.inventory[j]) || k)
2418 		{
2419 			if(!k) it = &itemlist[j];
2420 			if(zc->targetindex < zc->routeindex
2421 				|| zc->targetindex >= CurrentIndex) zc->targetindex = zc->routeindex;
2422 			for(i = zc->targetindex + 1;i < (zc->targetindex + 50);i++)
2423 			{
2424 				if(i > CurrentIndex) break;
2425 				if(Route[i].state == GRS_ITEMS)
2426 				{
2427 					if(Route[i].ent->item == it)
2428 					{
2429 //gi.bprintf(PRINT_HIGH,"Target Flag On\n");
2430 						zc->havetarget = true;
2431 						break;
2432 					}
2433 					else if(!ctf->value && Route[i].ent->solid == SOLID_TRIGGER)
2434 					{
2435 						//Quad
2436 						if(j = mpindex[MPI_QUAD])
2437 							if(Route[i].ent->item == &itemlist[j])
2438 							{zc->havetarget = true;	break;}
2439 						//Quad fire
2440 						if(j = mpindex[MPI_QUADF])
2441 							if(Route[i].ent->item == &itemlist[j])
2442 							{zc->havetarget = true;	break;}
2443 						//Quad fire
2444 						if(j = mpindex[MPI_PENTA])
2445 							if(Route[i].ent->item == &itemlist[j])
2446 							{zc->havetarget = true;	break;}
2447 					}
2448 				}
2449 			}
2450 			zc->targetindex = i;
2451 		}
2452 		else
2453 		{
2454 			//quad
2455 			j = mpindex[MPI_QUAD];
2456 			//quad fire
2457 			if(!j) j = mpindex[MPI_QUADF];
2458 
2459 			if(j)
2460 			{
2461 				it = &itemlist[j];
2462 				if(zc->targetindex < zc->routeindex
2463 					|| zc->targetindex >= CurrentIndex) zc->targetindex = zc->routeindex;
2464 				for(i = zc->targetindex + 1;i < (zc->targetindex + 25);i++)
2465 				{
2466 					if(i > CurrentIndex) break;
2467 					if(Route[i].state == GRS_ITEMS)
2468 					{
2469 						if(Route[i].ent->item == it)
2470 						{
2471 							if(Route[i].ent->solid == SOLID_TRIGGER)
2472 							{
2473 								zc->havetarget = true;
2474 								break;
2475 							}
2476 						}
2477 					}
2478 				}
2479 				zc->targetindex = i;
2480 			}
2481 		}
2482 	}
2483 	else if(zc->havetarget)
2484 	{
2485 		if(zc->targetindex < zc->routeindex)
2486 		{
2487 			zc->havetarget = false;
2488 			zc->targetindex = zc->routeindex;
2489 		}
2490 
2491 		else if(ctf->value)
2492 		{
2493 			it = NULL;
2494 			if(ent->client->resp.ctf_team == CTF_TEAM1)
2495 			{
2496 				if(zc->ctfstate == CTFS_DEFENDER || zc->ctfstate == CTFS_CARRIER) it = bot_team_flag1->item;
2497 				else if(zc->ctfstate == CTFS_OFFENCER) it = bot_team_flag2->item;
2498 			}
2499 			else if(ent->client->resp.ctf_team == CTF_TEAM2)
2500 			{
2501 				if(zc->ctfstate == CTFS_DEFENDER || zc->ctfstate == CTFS_CARRIER) it = bot_team_flag2->item;
2502 				else if(zc->ctfstate == CTFS_OFFENCER) it = bot_team_flag1->item;
2503 			}
2504 			if(Route[zc->targetindex].ent->item != it)
2505 			{
2506 				zc->havetarget = false;
2507 				zc->targetindex = zc->routeindex;
2508 			}
2509 		}
2510 	}
2511 	//--------------------------------------------------------------------------------------
2512 	//can rocket jump?
2513 	it = Fdi_ROCKETLAUNCHER;//FindItem("Rocket Launcher");
2514 	i = ITEM_INDEX(Fdi_ROCKETS/*FindItem("Rockets")*/);
2515 
2516 	if(	ent->client->pers.inventory[ITEM_INDEX(it)]
2517 		&& ent->client->pers.inventory[i] > 0) canrocj = true;
2518 	else canrocj = false;
2519 	if(!Bot[zc->botindex].param[BOP_ROCJ]) canrocj = false;
2520 
2521 	//--------------------------------------------------------------------------------------
2522 	//ducking check
2523 	if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
2524 	{
2525 		if(ent->client->zc.battleduckcnt > 0 && ent->groundentity) goto DCHCANC;
2526 
2527 		VectorSet(v,16,16,32);
2528 		VectorCopy(ent->s.origin,v);
2529 
2530 		v[2] += 28;
2531 
2532 		rs_trace = gi.trace(ent->s.origin,ent->mins,ent->maxs,v,ent,MASK_BOTSOLIDX);
2533 //gi.bprintf(PRINT_HIGH,"try to duck clear!\n");
2534 		if(!rs_trace.startsolid && !rs_trace.allsolid && rs_trace.fraction == 1.0)
2535 		{
2536 //gi.bprintf(PRINT_HIGH,"duck cleared!\n");
2537 			ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
2538 			ent->maxs[2] = 32;
2539 		}
2540 //		else gi.bprintf(PRINT_HIGH,"failed %i %i\n",rs_trace.startsolid ,rs_trace.allsolid);
2541 	}
2542 	else if(ent->velocity[2] > 10 && ent->groundentity == NULL
2543 		&& !(zc->zcstate & STS_SJMASK))
2544 	{
2545 		VectorSet(v,16,16,40);
2546 		rs_trace = gi.trace(ent->s.origin,ent->mins,v,ent->s.origin,ent,MASK_BOTSOLIDX);
2547 
2548 		if(rs_trace.startsolid || rs_trace.allsolid)
2549 		{
2550 			ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
2551 			ent->maxs[2] = 4;
2552 		}
2553 	}
2554 DCHCANC://���Ⴊ�݂��ςȂ�
2555 	//--------------------------------------------------------------------------------------
2556 	//movingspeed set
2557 	if(ent->groundentity || ent->waterlevel)
2558 	{
2559 		if(ent->waterlevel)
2560 		{
2561 			if(!(zc->zcstate & STS_WATERJ)) zc->zcstate &= ~STS_SJMASK;
2562 		}
2563 		else zc->zcstate &= ~STS_SJMASK;
2564 		if(ent->groundentity && !ent->waterlevel) ent->moveinfo.speed = 1.0;
2565 		else if(ent->waterlevel && ent->velocity[2] <= 1) ent->moveinfo.speed = 1.0;
2566 	}
2567 
2568 	// if ducking down to da speed
2569 	if(ent->client->ps.pmove.pm_flags & PMF_DUCKED && ent->groundentity) dist = MOVE_SPD_DUCK * ent->moveinfo.speed;
2570 	else
2571 	{
2572 		if( !ent->waterlevel )
2573 		{
2574 			if(chedit->value || !Bot[zc->botindex].param[BOP_WALK] || !ent->groundentity) dist = MOVE_SPD_RUN * ent->moveinfo.speed;
2575 			else dist = MOVE_SPD_WALK * ent->moveinfo.speed;
2576 		}
2577 		else
2578 		{
2579 			if(ent->groundentity && ent->waterlevel < 2 ) dist = MOVE_SPD_RUN * ent->moveinfo.speed;
2580 			else dist = MOVE_SPD_WATER * ent->moveinfo.speed;
2581 		}
2582 		if(ent->groundentity) dist *= zc->ground_slope;
2583 	}
2584 
2585 	//--------------------------------------------------------------------------------------
2586 	//get waterstate
2587 	Get_WaterState( ent );
2588 
2589 	//--------------------------------------------------------------------------------------
2590 	//
2591 	//search for enemy
2592 	//
2593 //	foundedenemy = 0;
2594 //	i = CTS_AIMING ;
2595 
2596 	zc->firstinterval += 2;
2597 	if(zc->firstinterval >= 10)
2598 	{
2599 		zc->foundedenemy = Bot_SearchEnemy(ent);
2600 		zc->firstinterval = Bot[zc->botindex].param[BOP_REACTION];
2601 		if(zc->firstinterval > 10) zc->firstinterval = 10;
2602 		if(zc->firstinterval < 0) zc->firstinterval = 0;
2603 	}
2604 	//--------------------------------------------------------------------------------------
2605 	//
2606 	//bot's combat status set
2607 	//
2608 	foundedenemy = zc->foundedenemy;
2609 //	if(ent->client->ctf_grapple && !(ent->client->buttons & BUTTON_ATTACK)) {}
2610 //	else
2611 	Set_Combatstate(ent,foundedenemy);
2612 	if(trace_priority == TRP_ALLKEEP) goto VCHCANSEL;
2613 	//--------------------------------------------------------------------------------------
2614 	//brause target status
2615 	if(zc->second_target != NULL && zc->route_trace)
2616 								zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
2617 	if(zc->second_target != NULL && !(zc->zcstate & STS_WAITSMASK))
2618 	{
2619 		if(zc->second_target->solid != SOLID_TRIGGER || !zc->second_target->inuse)
2620 		{
2621 			zc->second_target = NULL;
2622 		}
2623 		else if(!Bot_trace (ent,zc->second_target))
2624 		{
2625 			zc->second_target = NULL;
2626 		}
2627 		else if((zc->second_target->s.origin[2] - ent->s.origin[2]) > 32 && zc->waterstate != WAS_IN)
2628 		{
2629 			VectorSubtract(zc->second_target->s.origin,ent->s.origin,temppos);
2630 			x = zc->second_target->moveinfo.start_origin[2] - ent->s.origin[2];
2631 			k = false;
2632 			if(temppos[2] > 32)
2633 			{
2634 				if(!canrocj)
2635 				{
2636 					if(x < 0 || x > 32) k = true;
2637 					else if(!Bot_trace2 (ent,zc->second_target->moveinfo.start_origin)) k = true;
2638 				}
2639 				else
2640 				{
2641 					if(temppos[2] > 300) k = true;
2642 				}
2643 			}
2644 			else
2645 			{
2646 				if(temppos[0] <= (ent->absmax[0] + 32) && temppos[0] >= (ent->absmin[0] + 32))
2647 				if(temppos[1] <= (ent->absmax[1] + 32) && temppos[1] >= (ent->absmin[1] + 32))
2648 				if(temppos[2] <= (ent->absmax[2] + 32) && temppos[2] >= (ent->absmin[2] + 32))
2649 						k = true;
2650 			}
2651 			if(k)
2652 			{
2653 				zc->second_target = NULL;
2654 //				if(zc->route_trace) Search_NearlyPod(ent);
2655 			}
2656 		}
2657 	}
2658 //	if(zc->route_trace && (zc->zcstate & STS_LADDERUP)) zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
2659 	if(zc->route_trace)
2660 	{
2661 //PON-CTF>>
2662 		if(zc->routeindex > 0)
2663 		{
2664 			if(ent->client->ctf_grapple)
2665 			{
2666 				ent->client->buttons |= BUTTON_ATTACK;
2667 			}
2668 
2669 //			if(Route[zc->routeindex].state == GRS_GRAPSHOT)
2670 //			{
2671 //				if(Route[zc->routeindex - 1].state == GRS_GRAPRELEASE) zc->routeindex++;
2672 //			}
2673 			if(!zc->first_target && ent->client->pers.weapon != Fdi_GRAPPLE	)
2674 			{
2675 				for(i = 0;i < (5 * 2);i++)
2676 				{
2677 					if((zc->routeindex + i) >= CurrentIndex) break;
2678 					if(Route[zc->routeindex + i].state == GRS_GRAPSHOT)
2679 					{
2680 						item = Fdi_GRAPPLE;//FindItem("Grapple");
2681 						if(	ent->client->pers.inventory[ITEM_INDEX(item)]) item->use(ent,item);
2682 					}
2683 				}
2684 			}
2685 			//����Grapple
2686 			else if(Route[zc->routeindex - 1].state == GRS_GRAPSHOT
2687 				&& ent->client->ctf_grapple == NULL
2688 				&& zc->first_target == NULL)
2689 			{
2690 				item = Fdi_GRAPPLE;;//FindItem("Grapple");
2691 
2692 				if(	ent->client->pers.inventory[ITEM_INDEX(item)])
2693 				{
2694 					item->use(ent,item);
2695 //					ent->client->ctf_grapplestate = CTF_GRAPPLE_STATE_FLY;
2696 //					ent->client->pers.weapon = item;
2697 //					ent->client->weaponstate = WEAPON_READY;
2698 //					ent->s.sound = 0;
2699 					ShowGun(ent);
2700 					if(ent->client->weaponstate == WEAPON_READY && ent->client->pers.weapon == item)
2701 					{
2702 						vv[0] = ent->s.origin[0];
2703 						vv[1] = ent->s.origin[1];
2704 						vv[2] = ent->s.origin[2] + ent->viewheight-8+2;
2705 //						VectorCopy(Route[zc->routeindex - 1].Pt,ent->s.origin);
2706 						VectorSubtract(Route[zc->routeindex - 1].Tcourner,vv,v);
2707 						ent->s.angles[YAW] = Get_yaw(v);
2708 						ent->s.angles[PITCH] = Get_pitch(v);
2709 						trace_priority = TRP_ANGLEKEEP;
2710 //						item->use(ent,item);
2711 //						if(ent->client->weaponstate == WEAPON_READY)
2712 //						{
2713 							ent->client->buttons |= BUTTON_ATTACK;
2714 //						}
2715 					}
2716 					else
2717 					{
2718 						if(zc->first_target == NULL && ent->groundentity) trace_priority = TRP_ALLKEEP;
2719 						zc->routeindex--;/* trace_priority = TRP_ALLKEEP;*/
2720 					}
2721 				}
2722 			}
2723 			else if(ent->client->ctf_grapple)
2724 			{
2725 				//sticking check
2726 				if(zc->nextcheck < (level.time + FRAMETIME * 10))
2727 				{
2728 					VectorSubtract(zc->pold_origin,ent->s.origin,temppos);
2729 					if(VectorLength(temppos) < 64)
2730 					{
2731 						if(zc->route_trace)
2732 						{
2733 							zc->route_trace = false;
2734 							zc->routeindex++;
2735 							ent->client->buttons &= ~BUTTON_ATTACK;
2736 						}
2737 					}
2738 
2739 					if(zc->nextcheck < level.time)
2740 					{
2741 						VectorCopy(ent->s.origin,zc->pold_origin);
2742 						zc->nextcheck = level.time + FRAMETIME * 40;
2743 					}
2744 				}
2745 				if(ent->client->ctf_grapplestate == CTF_GRAPPLE_STATE_PULL)
2746 				{
2747 					if(ent->groundentity == NULL) zc->zcstate |= STS_ROCJ;
2748 
2749 					if(Route[zc->routeindex].state != GRS_GRAPRELEASE)
2750 					{
2751 						for(i = 0;(zc->routeindex - i) > 0;i++)
2752 						{
2753 							if(Route[zc->routeindex - i].state == GRS_GRAPSHOT) break;
2754 						}
2755 						if((zc->routeindex - i) > 0)
2756 						{
2757 							for(j = 0;(zc->routeindex - i + j) < CurrentIndex;j++)
2758 							{
2759 								if(Route[zc->routeindex - i + j].state == GRS_GRAPRELEASE) break;
2760 							}
2761 							if((zc->routeindex - i + j) < CurrentIndex)
2762 									zc->routeindex = zc->routeindex - i + j;
2763 						}
2764 					}
2765 					if(Route[zc->routeindex].state != GRS_GRAPRELEASE)
2766 					{
2767 						item = Fdi_GRAPPLE;//FindItem("Grapple");
2768 					item->use(ent,item);
2769 //						ent->client->pers.weapon = item;
2770 //						ent->s.sound = 0;
2771 //						ShowGun(ent);
2772 						ent->client->buttons &= ~BUTTON_ATTACK;
2773 					}
2774 				}
2775 				else if(ent->client->ctf_grapplestate == CTF_GRAPPLE_STATE_HANG
2776 					&& Route[zc->routeindex].state != GRS_GRAPRELEASE)
2777 				{
2778 					item = Fdi_GRAPPLE;//FindItem("Grapple");
2779 					item->use(ent,item);
2780 //					ent->client->pers.weapon = item;
2781 //					ent->s.sound = 0;
2782 //					ShowGun(ent);
2783 					ent->client->buttons &= ~BUTTON_ATTACK;
2784 //gi.bprintf(PRINT_HIGH,"Groff 2!\n");
2785 				}
2786 			}
2787 
2788 			else if(Route[zc->routeindex - 1].state == GRS_GRAPHOOK
2789 				&& ent->client->ctf_grapple)
2790 			{
2791 				if(ent->client->ctf_grapplestate == CTF_GRAPPLE_STATE_FLY)
2792 					trace_priority = TRP_ALLKEEP;
2793 
2794 			}
2795 /*			if(Route[zc->routeindex].state == GRS_GRAPHOOK
2796 				&& ent->client->ctf_grapple)
2797 			{
2798 				trace_priority = TRP_ALLKEEP;
2799 			}*/
2800 			if(Route[zc->routeindex].state == GRS_GRAPRELEASE
2801 				&& ent->client->ctf_grapple)
2802 			{
2803 				k = 0;
2804 				if(ent->client->ctf_grapplestate == CTF_GRAPPLE_STATE_FLY)
2805 					trace_priority = TRP_ALLKEEP;
2806 				else if(ent->client->ctf_grapplestate == CTF_GRAPPLE_STATE_PULL)
2807 				{
2808 					if(1)
2809 					{
2810 						e = (edict_t*)ent->client->ctf_grapple;
2811 						VectorSubtract(ent->s.origin,e->s.origin,v);
2812 						yaw = VectorLength(v);
2813 						if(yaw <= (Route[zc->routeindex].Tcourner[0] /*+ 32*/))
2814 						{
2815 //							if(yaw < 40) ent->moveinfo.speed = 0;
2816 							item = Fdi_GRAPPLE;//FindItem("Grapple");
2817 							item->use(ent,item);
2818 							ent->client->buttons &= ~BUTTON_ATTACK;
2819 							zc->routeindex++;
2820 							k = true;
2821 //gi.bprintf(PRINT_HIGH,"Groff 1!\n");
2822 						}
2823 						else if(!ent->waterlevel) trace_priority = TRP_ALLKEEP;
2824 					}
2825 //					gi.bprintf(PRINT_HIGH,"length %f < %f\n",Route[zc->routeindex].Tcourner[0],VectorLength(v));
2826 				}
2827 				else if(ent->client->ctf_grapplestate == CTF_GRAPPLE_STATE_HANG)
2828 				{
2829 /*					if((zc->routeindex + 1) < CurrentIndex)
2830 					{
2831 						if(Route[zc->routeindex + 1].state == GRS_GRAPSHOT)
2832 						{
2833 							if(TraceX(ent,Route[zc->routeindex + 1].Tcourner)) k = true;
2834 						}
2835 						else k = true;
2836 					}*/
2837 					ent->moveinfo.speed = 0;
2838 					k = true;
2839 					if(k)
2840 					{
2841 						item = Fdi_GRAPPLE;//FindItem("Grapple");
2842 						item->use(ent,item);
2843 						ent->client->buttons &= ~BUTTON_ATTACK;
2844 						zc->routeindex++;
2845 //gi.bprintf(PRINT_HIGH,"Groff 0!\n");
2846 					}
2847 				}
2848 				if(k)
2849 				{
2850 					if(zc->routeindex < CurrentIndex)
2851 					{
2852 						if(Route[zc->routeindex].state == GRS_GRAPSHOT)
2853 						{
2854 							if(1/*TraceX(ent,Route[zc->routeindex + 1].Tcourner)*/) zc->routeindex++;
2855 						}
2856 					}
2857 				}
2858 			}
2859 /*			else if(ent->client->ctf_grapple)
2860 			{
2861 				if(ent->client->ctf_grapplestate == CTF_GRAPPLE_STATE_PULL
2862 					&& Route[zc->routeindex - 1].state == GRS_GRAPRELEASE)
2863 				{
2864 					ent->client->buttons &= ~BUTTON_ATTACK;
2865 					CTFResetGrapple(ent->client->ctf_grapple);
2866 				}
2867 			}*/
2868 		}
2869 //>>PON-CTF
2870 //		if(trace_priority == TRP_ALLKEEP) goto VCHCANSEL;
2871 
2872 		if(Route[zc->routeindex].state >= GRS_NORMAL) Search_NearlyPod(ent);
2873 
2874 		Get_RouteOrigin(zc->routeindex,v);
2875 
2876 		x = v[2] - ent->s.origin[2];
2877 
2878 		if(zc->zcstate & STS_WAITSMASK) zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
2879 		else if(Route[zc->routeindex].state <= GRS_ITEMS && (x > JumpMax && !zc->waterstate)
2880 			&& !(zc->zcstate & STS_LADDERUP))
2881 		{
2882 			if(zc->rt_locktime <= level.time)
2883 			{
2884 #ifdef _DEBUG
2885 gi.bprintf(PRINT_HIGH,"OFF 2\n"); //ppx
2886 #endif
2887 				zc->route_trace = false;
2888 				zc->rt_releasetime = level.time + FRAMETIME * POD_RELEFRAME;
2889 			}
2890 		}
2891 		else if(!TraceX(ent,v) /*&& ent->client->ctf_grapple == NULL*/)
2892 		{
2893 			k = false;
2894 			if(ent->groundentity)
2895 			{
2896 				if(ent->groundentity->classname[0] == 'f')
2897 				{
2898 					if(/*!Q_stricmp(ent->groundentity->classname, "func_plat")
2899 						||*/ !Q_stricmp(ent->groundentity->classname, "func_train"))
2900 					{
2901 						zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
2902 						k = true;
2903 					}
2904 				}
2905 			}
2906 //			if(Route[zc->routeindex].state == GRS_ONTRAIN
2907 //				&& /*Route[zc->routeindex].ent->trainteam*/) zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
2908 //PON
2909 			if(ent->client->ctf_grapple)
2910 			{
2911 				if(!VectorCompare(ent->s.origin,ent->s.old_origin)) zc->rt_locktime += FRAMETIME;
2912 			}
2913 //PON
2914 			if(zc->rt_locktime <= level.time && !k)
2915 			{
2916 //				gi.bprintf(PRINT_HIGH,"shit1");
2917 #ifdef _DEBUG
2918 gi.bprintf(PRINT_HIGH,"OFF 3\n"); //ppx
2919 #endif
2920 				zc->route_trace = false;
2921 				zc->rt_releasetime = level.time + FRAMETIME * POD_RELEFRAME;
2922 			}
2923 		}
2924 		else
2925 		{
2926 			if(Route[zc->routeindex].state > GRS_ITEMS
2927 				&& Route[zc->routeindex].state <= GRS_ONPLAT)
2928 			{
2929 				if(0/*Route[zc->routeindex].state == GRS_ONPLAT && Route[zc->routeindex].ent->moveinfo.state != PSTATE_BOTTOM*/)
2930 				{
2931 #ifdef _DEBUG
2932 gi.bprintf(PRINT_HIGH,"OFF 4\n"); //ppx
2933 #endif
2934 					zc->route_trace = false;
2935 					zc->rt_releasetime = level.time + FRAMETIME * POD_RELEFRAME;
2936 				}
2937 				else if(0/*Route[zc->routeindex].ent->union_ent->solid != SOLID_TRIGGER*/)
2938 				{
2939 #ifdef _DEBUG
2940 gi.bprintf(PRINT_HIGH,"OFF 5\n"); //ppx
2941 #endif
2942 					zc->route_trace = false;
2943 					zc->rt_releasetime = level.time + FRAMETIME * POD_RELEFRAME;
2944 				}
2945 				else zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
2946 			}
2947 			else zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
2948 		}
2949 	}
2950 	else
2951 	{
2952 		if(ent->client->ctf_grapple)
2953 		{
2954 			item = FindItem("Grapple");
2955 			ent->client->pers.weapon = item;
2956 			ent->s.sound = 0;
2957 			ShowGun(ent);
2958 			ent->client->buttons &= ~BUTTON_ATTACK;
2959 		}
2960 	}
2961 	if(trace_priority == TRP_ALLKEEP)
2962 	{
2963 		if(ent->client->ctf_grapple)
2964 		{
2965 			rs_trace = gi.trace (ent->s.origin, ent->maxs, ent->mins, ent->s.origin,ent, MASK_BOTSOLIDX);
2966 			if(rs_trace.allsolid || rs_trace.startsolid || rs_trace.fraction != 1.0)
2967 				ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
2968 		}
2969 		goto VCHCANSEL;
2970 	}
2971 	//--------------------------------------------------------------------------------------
2972 	//search for items
2973 	if(!chedit->value && zc->second_target == NULL)
2974 	{
2975 		pickup_pri = false;			//pickup priority off
2976 		k = false;
2977 
2978 		zc->secondinterval++;
2979 		//when tracing routes
2980 		if(zc->route_trace && zc->secondinterval > 40)
2981 		{
2982 			for(i = zc->routeindex ; i < (zc->routeindex + 20); i++)
2983 			{
2984 				if(i >= CurrentIndex) break;
2985 				if(Route[i].state == GRS_ITEMS)
2986 				{
2987 					if(Route[i].ent->solid == SOLID_TRIGGER)
2988 					{
2989 						pickup_pri = true;
2990 						break;
2991 					}
2992 				}
2993 			}
2994 		}
2995 
2996 		if(1/*!k*/)
2997 		{
2998 			if(zc->secondinterval > 40)
2999 			{
3000 				if(!(zc->zcstate & STS_WAITSMASK ))
3001 				{
3002 					Bot_SearchItems(ent);
3003 					if(zc->second_target != NULL && pickup_pri)
3004 					{
3005 						for(i = zc->routeindex ; i < (zc->routeindex + 20); i++)
3006 						{
3007 							if(i >= CurrentIndex) break;
3008 							if(Route[i].state == GRS_ITEMS)
3009 							{
3010 								if(Route[i].ent == zc->second_target)
3011 								{
3012 									zc->second_target = NULL;
3013 									break;
3014 								}
3015 							}
3016 						}
3017 					}
3018 				}
3019 			}
3020 		}
3021 
3022 		if(zc->secondinterval > 40/*zc->second_target != NULL*/ /*&& !k*/)
3023 		{
3024 			zc->secondinterval = Bot[zc->botindex].param[BOP_PICKUP] * 4;
3025 			if(zc->secondinterval > 36) zc->secondinterval = 36;
3026 			if(zc->secondinterval < 0) zc->secondinterval = 0;
3027 		}
3028 
3029 		if(ent->client->zc.objshot) goto VCHCANSEL; //object shot!!
3030 	}
3031 
3032 	//--------------------------------------------------------------------------------------
3033 	//go up ladder
3034 	//
3035 	//
3036 	//
3037 	//	��q��o��
3038 	//
3039 	//
3040 	//--------------------------------------------------------------------------------------
3041 
3042 	if(zc->zcstate & STS_LADDERUP)
3043 	{
3044 #ifdef _DEBUG
3045 gi.bprintf(PRINT_HIGH,"ladder UP!! %f %i\n",zc->moveyaw,ent->waterlevel);
3046 #endif
3047 		if(ent->waterlevel > 1)
3048 		{
3049 /*			if(zc->route_trace )
3050 			{
3051 				Get_RouteOrigin(zc->routeindex,v);
3052 				Bot_Watermove ( ent,pos,dist,upd)*/
3053 			ent->velocity[2] = VEL_BOT_WLADRUP;
3054 //			if(VectorCompare(ent->s.origin,ent->s.old_origin)) ent->velocity[2] += 50;
3055 		}
3056 		else
3057 		{
3058 			ent->velocity[2] = VEL_BOT_LADRUP;
3059 //			if(VectorCompare(ent->s.origin,ent->s.old_origin)) ent->velocity[2] += 50;
3060 		}
3061 
3062 		VectorCopy(ent->mins,trmin);
3063 		trmin[2] += 20;
3064 
3065 		yaw = zc->moveyaw * M_PI * 2 / 360;
3066 		touchmin[0] = cos(yaw) * 32;//96 ;
3067 		touchmin[1] = sin(yaw) * 32;//96 ;
3068 		touchmin[2] = 0;
3069 
3070 		VectorAdd(ent->s.origin,touchmin,touchmax);
3071 
3072 		rs_trace = gi.trace (ent->s.origin, trmin/*ent->mins*/,ent->maxs, touchmax,ent, MASK_BOTSOLID/*MASK_PLAYERSOLID*/);
3073 
3074 		plane = rs_trace.plane;
3075 
3076 		if(!(rs_trace.contents & CONTENTS_LADDER) && !rs_trace.allsolid /*&& !rs_trace.startsolid*/)
3077 		{
3078 #ifdef _DEBUG
3079 gi.bprintf(PRINT_HIGH,"ladder OFF1!!\ncont %x %x\nall %i\nstart %i\n",rs_trace.contents,i,rs_trace.allsolid,rs_trace.startsolid);
3080 #endif
3081 			if(ent->velocity[2] <= VEL_BOT_LADRUP && !ent->waterlevel) ent->velocity[2] = VEL_BOT_LADRUP;
3082 			zc->zcstate &= ~STS_LADDERUP;
3083 			ent->moveinfo.speed = 0.25;
3084 			if(zc->route_trace)
3085 			{
3086 				Get_RouteOrigin(zc->routeindex,v);
3087 				if(VectorLength(v) > 32)
3088 				{
3089 					VectorSubtract(v,ent->s.origin,v);
3090 					zc->moveyaw = Get_yaw(v);
3091 					if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = zc->moveyaw;
3092 				}
3093 				else zc->routeindex++;
3094 			}
3095 		}
3096 		else
3097 		{
3098 //pon
3099 			if(!rs_trace.allsolid)
3100 			{
3101 				VectorCopy(rs_trace.endpos,ent->s.origin);
3102 			}
3103 
3104 //pon
3105 //			ent->moveinfo.speed = 1.0;
3106 			VectorCopy(ent->s.origin,touchmin);
3107 			touchmin[2] += 8;
3108 
3109 			rs_trace = gi.trace (ent->s.origin, ent->mins,ent->maxs, touchmin,ent, MASK_BOTSOLID/*MASK_PLAYERSOLID*/ );
3110 
3111 			x = rs_trace.endpos[2] - ent->s.origin[2];
3112 
3113 			if(ent->waterlevel )
3114 			{
3115 				ent->s.origin[2] += x;
3116 			}
3117 			else
3118 			{
3119 				ent->s.origin[2] += x;
3120 			}
3121 
3122 			e = rs_trace.ent;
3123 
3124 			if(x == 0/*VectorCompare(ent->s.origin,ent->s.old_origin)*/)
3125 			{
3126 				x = Get_yaw(plane.normal);
3127 
3128 				//right
3129 				VectorCopy(ent->s.origin,v);
3130 				yaw = x + 90;
3131 				if(yaw > 180) yaw -= 360;
3132 				yaw = yaw * M_PI * 2 / 360;
3133 				touchmin[0] = cos(yaw) * 48 ;
3134 				touchmin[1] = sin(yaw) * 48 ;
3135 				touchmin[2] = 0;
3136 				VectorAdd(ent->s.origin,touchmin,trmin);
3137 
3138 				VectorCopy(trmin,trmax);
3139 				trmin[2] += 32;
3140 				trmax[2] += 64;
3141 				rs_trace = gi.trace(trmin,NULL,NULL,trmax,ent,MASK_BOTSOLID);
3142 				f1 = rs_trace.fraction;
3143 
3144 				//left
3145 				VectorCopy(ent->s.origin,v);
3146 				iyaw = x -90 ;
3147 				if(iyaw < 180) iyaw += 360;
3148 				iyaw = iyaw * M_PI * 2 / 360;
3149 				touchmin[0] = cos(iyaw) * 48 ;
3150 				touchmin[1] = sin(iyaw) * 48 ;
3151 				touchmin[2] = 0;
3152 				VectorAdd(ent->s.origin,touchmin,trmin);
3153 
3154 				VectorCopy(trmin,trmax);
3155 				trmin[2] += 32;
3156 				trmax[2] += 64;
3157 				rs_trace = gi.trace(trmin,NULL,NULL,trmax,ent,MASK_BOTSOLID);
3158 				f2 = rs_trace.fraction;
3159 
3160 				x = 0.0;
3161 				if(f1 == 1.0 && f2 != 1.0) x = yaw;
3162 				else if(f1 != 1.0 && f2 == 1.0) x = iyaw;
3163 
3164 				if(x != 0.0)
3165 				{
3166 					touchmin[0] = cos(x) * 4 ;
3167 					touchmin[1] = sin(x) * 4 ;
3168 					touchmin[2] = 0;
3169 					VectorAdd(ent->s.origin,touchmin,trmin);
3170 					rs_trace = gi.trace(ent->s.origin,ent->mins,ent->maxs,trmin,ent,MASK_BOTSOLID);
3171 					if(rs_trace.startsolid || rs_trace.allsolid) x = 0;
3172 					else VectorCopy(rs_trace.endpos,ent->s.origin);
3173 				}
3174 
3175 				if(x == 0.0)
3176 				{
3177 #ifdef _DEBUG
3178 gi.bprintf(PRINT_HIGH,"ladder OFF2!!\n");
3179 #endif
3180 					k = 0;
3181 					if(e)
3182 					{
3183 						if(Q_stricmp (e->classname, "func_door") == 0)
3184 						{
3185 							if(e->moveinfo.state == PSTATE_UP) k = true;
3186 						}
3187 					}
3188 					if(!k)
3189 					{
3190 						zc->moveyaw += 180;
3191 						if(zc->moveyaw > 180) zc->moveyaw -= 360;
3192 						zc->zcstate &= ~STS_LADDERUP;
3193 						ent->moveinfo.speed = 0.25;
3194 					}
3195 				}
3196 			}
3197 		}
3198 
3199 		if(zc->zcstate & STS_LADDERUP)
3200 		{
3201 			if(zc->route_trace )
3202 			{
3203 				Get_RouteOrigin(zc->routeindex,v);
3204 				if(v[2] < ent->s.origin[2])
3205 				{
3206 					VectorSubtract(ent->s.origin,v,vv);
3207 					vv[2] = 0;
3208 					if(VectorLength(vv) < 32) zc->routeindex++;
3209 				}
3210 			}
3211 
3212 
3213 			ent->velocity[0] = 0;
3214 			ent->velocity[1] = 0;
3215 			goto VCHCANSEL_L;
3216 		}
3217 	}
3218 
3219 	//--------------------------------------------------------------------------------------
3220 	//bot's true moving yaw,yaw pitch set
3221 	// j is used ground entity check section
3222 	//
3223 	//
3224 	//
3225 	//	�ړ���������
3226 	//
3227 	//
3228 	//--------------------------------------------------------------------------------------
3229 
3230 	j = 0;
3231 	if(ent->groundentity && ent->waterlevel <= 1 && trace_priority < TRP_ANGLEKEEP) ent->s.angles[PITCH] = 0;
3232 	if(zc->second_target != NULL )
3233 	{
3234 		if((zc->second_target->s.origin[2] - ent->s.origin[2]) > 32 && !ent->waterlevel)
3235 		{
3236 			x = zc->second_target->moveinfo.start_origin[2] - ent->s.origin[2];
3237 			if(x <= 32 && x > -24 && Bot_trace2 (ent,zc->second_target->moveinfo.start_origin))
3238 			{
3239 				VectorSubtract(zc->second_target->moveinfo.start_origin,ent->s.origin,temppos);
3240 				k = false;
3241 				yaw = temppos[2];
3242 				temppos[2] = 0;
3243 				x = VectorLength(temppos);
3244 
3245 				if(yaw < -32 && x < 32) k = true;
3246 
3247 				if(!k)
3248 				{
3249 					if(!ent->groundentity && !ent->waterlevel)
3250 					{
3251 						if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = Get_yaw(temppos);
3252 					}
3253 					else if(ent->groundentity || ent->waterlevel )
3254 					{
3255 						if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);
3256 						if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = zc->moveyaw;
3257 					}
3258 
3259 					if(x < dist && fabs(temppos[2]) < 24) dist = x;//pon
3260 				}
3261 				j = -1;
3262 			}
3263 		}
3264 		else
3265 		{
3266 			VectorSubtract(zc->second_target->s.origin,ent->s.origin,temppos);
3267 			if(ent->waterlevel && !ent->groundentity && trace_priority < TRP_ANGLEKEEP) ent->s.angles[PITCH] = Get_pitch(temppos);
3268 
3269 			if(!ent->groundentity && !ent->waterlevel && trace_priority < TRP_ANGLEKEEP)
3270 			{
3271 				temppos[2] = 0;
3272 				if(VectorLength(temppos) > 32)
3273 				{
3274 					if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = Get_yaw(temppos);
3275 				}
3276 			}
3277 			else if(ent->groundentity || ent->waterlevel )
3278 			{
3279 				k = false;
3280 				yaw = temppos[2];
3281 				temppos[2] = 0;
3282 				x = VectorLength(temppos);
3283 
3284 				if(yaw < -32 && x < 32) k = true;
3285 
3286 				if(!k)
3287 				{
3288 					if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);	//set the movin' yaw
3289 					if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = zc->moveyaw;
3290 					if(x < dist && fabs(yaw) < JumpMax) dist = x;
3291 				}
3292 			}
3293 			j = -1;
3294 		}
3295 	}
3296 	else
3297 	{
3298 		if(ent->groundentity && !zc->route_trace)
3299 		{
3300 			if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = ent->s.angles[YAW];
3301 		}
3302 		else if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = zc->moveyaw ;
3303 	}
3304 
3305 /*	if(zc->first_target != NULL)
3306 	{
3307 		VectorSubtract(zc->first_target->s.origin,ent->s.origin,temppos);
3308 		ent->s.angles[YAW] = Get_yaw(temppos);	//set the model's yaw
3309 		ent->s.angles[PITCH] = Get_pitch(temppos);
3310 	}
3311 */
3312 	//�`�[���v���C���̃��[�`��
3313 	if(ctf->value ||((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
3314 	{
3315 		if(ctf->value)
3316 		{
3317 			if(zc->ctfstate == CTFS_SUPPORTER)
3318 			{
3319 				if(zc->followmate)
3320 				{
3321 					if(zc->followmate->inuse)
3322 						if(zc->followmate->client->zc.ctfstate != CTFS_CARRIER)
3323 						{
3324 							zc->ctfstate = CTFS_OFFENCER;
3325 							zc->followmate = NULL;
3326 						}
3327 				}
3328 
3329 				if(zc->second_target == NULL) j = 1;
3330 			}
3331 			else j = 0;
3332 		}
3333 		else
3334 		{
3335 			if(zc->tmplstate == TMS_FOLLOWER && zc->second_target == NULL) j = 1;
3336 			else j = 0;
3337 		}
3338 
3339 		if(j/*zc->tmplstate == TMS_FOLLOWER && zc->second_target == NULL*/)
3340 		{
3341 			if(zc->followmate)
3342 			{
3343 				k = Bot_traceS(ent,zc->followmate);
3344 				if(k || zc->route_trace) zc->matelock = level.time + FRAMETIME * 5;
3345 				if(!zc->followmate->inuse || zc->followmate->deadflag || zc->matelock <= level.time)
3346 				{
3347 					if(ctf->value) zc->ctfstate = CTFS_OFFENCER;
3348 					else zc->tmplstate = TMS_NONE;
3349 					zc->followmate = NULL;
3350 				}
3351 				else
3352 				{
3353 					VectorSubtract(zc->followmate->s.origin,ent->s.origin,v);
3354 					if(VectorLength(v) < 200)
3355 					{
3356 						if(k && zc->followmate->client->zc.route_trace
3357 							&& (zc->followmate->client->zc.routeindex - 2) > 0
3358 							&& (ent->svflags & SVF_MONSTER))
3359 						{
3360 							zc->routeindex = zc->followmate->client->zc.routeindex - 2;
3361 							zc->route_trace = true;
3362 							if(zc->followmate->client->zc.havetarget)
3363 							{
3364 								zc->targetindex = zc->followmate->client->zc.targetindex;
3365 							}
3366 						}
3367 						else if(!(ent->svflags & SVF_MONSTER))
3368 						{
3369 							zc->moveyaw = Get_yaw(v);
3370 							//if(VectorLength(v) < 100) trace_priority = TRP_ALLKEEP;
3371 							//else trace_priority = TRP_MOVEKEEP;
3372 						}
3373 						if(VectorLength(v) < 100)
3374 						{
3375 							if(!v[0]) v[0] = 1;
3376 							if(!v[1]) v[1] = 1;
3377 							v[0] *= -1;
3378 							v[1] *= -1;
3379 							if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(v);
3380 							if(trace_priority < TRP_ANGLEKEEP)
3381 							{
3382 								ent->s.angles[YAW] = zc->moveyaw;
3383 								ent->s.angles[PITCH] = Get_pitch(v);
3384 							}
3385 						}
3386 						else if(trace_priority < TRP_MOVEKEEP)
3387 						{
3388 							goto VCHCANSEL;
3389 						}
3390 					}
3391 					else if(ent->groundentity || ent->waterlevel )
3392 					{
3393 						if(zc->followmate->client->zc.route_trace && (ent->svflags & SVF_MONSTER)) zc->routeindex = zc->followmate->client->zc.routeindex;
3394 						else
3395 						{
3396 							if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(v);
3397 							if(trace_priority < TRP_ANGLEKEEP)
3398 							{
3399 								ent->s.angles[YAW] = zc->moveyaw;
3400 								ent->s.angles[PITCH] = Get_pitch(v);
3401 							}
3402 						}
3403 					}
3404 				}
3405 			}
3406 			else
3407 			{
3408 				if(ctf->value) zc->ctfstate = CTFS_OFFENCER;
3409 				else zc->tmplstate = TMS_NONE;
3410 			}
3411 		}
3412 	}
3413 
3414 	//ctf route index fix
3415 	if(ctf->value && !chedit->value)
3416 	{
3417 		j = 0;
3418 		if(ent->client->resp.ctf_team == CTF_TEAM1)
3419 		{
3420 //if(zc->ctfstate == CTFS_CARRIER)
3421 //			gi.bprintf(PRINT_HIGH,"I am carrierX!!\n");
3422 			if(zc->ctfstate == CTFS_DEFENDER
3423 				|| zc->ctfstate == CTFS_CARRIER
3424 				|| zc->ctfstate == CTFS_SUPPORTER) j = FOR_FLAG1;
3425 			else j = FOR_FLAG2;
3426 		}
3427 		else if(ent->client->resp.ctf_team == CTF_TEAM2)
3428 		{
3429 			if(zc->ctfstate == CTFS_DEFENDER
3430 				|| zc->ctfstate == CTFS_CARRIER
3431 				|| zc->ctfstate == CTFS_SUPPORTER) j = FOR_FLAG2;
3432 			else j = FOR_FLAG1;
3433 		}
3434 
3435 		if(zc->route_trace)
3436 		{
3437 			if(Route[zc->routeindex].state < GRS_ITEMS
3438 				&& Route[zc->routeindex].linkpod[MAXLINKPOD - 1])
3439 			{
3440 				k = Route[zc->routeindex].linkpod[MAXLINKPOD - 1];
3441 				if(j == FOR_FLAG1)
3442 				{
3443 					if(k & CTF_FLAG2_FLAG)
3444 					{
3445 //gi.bprintf(PRINT_HIGH,"Wrong way 1\n");
3446 						for(i = 0;i < (MAXLINKPOD - 1);i++)
3447 						{
3448 							if(!Route[zc->routeindex].linkpod[i]) break;
3449 							k = Route[Route[zc->routeindex].linkpod[i]].linkpod[MAXLINKPOD - 1];
3450 							if(!(k & CTF_FLAG2_FLAG))
3451 							{
3452 								zc->routeindex = Route[zc->routeindex].linkpod[i];// zc->route_trace = false;
3453 								zc->havetarget = false;
3454 //gi.bprintf(PRINT_HIGH,"fixed for flag 1\n");
3455 							}
3456 						}
3457 					}
3458 					else if(!zc->havetarget && zc->ctfstate == CTFS_CARRIER)
3459 					{
3460 						zc->havetarget = true;
3461 						zc->targetindex = Route[zc->routeindex].linkpod[MAXLINKPOD - 1] & 0x7FFF;
3462 					}
3463 				}
3464 				else if(j == FOR_FLAG2)
3465 				{
3466 					if(!(k & CTF_FLAG2_FLAG))
3467 					{
3468 //gi.bprintf(PRINT_HIGH,"Wrong way 2\n");
3469 						for(i = 0;i < (MAXLINKPOD - 1);i++)
3470 						{
3471 							if(!Route[zc->routeindex].linkpod[i]) break;
3472 							k = Route[Route[zc->routeindex].linkpod[i]].linkpod[MAXLINKPOD - 1];
3473 							if(k & CTF_FLAG2_FLAG)
3474 							{
3475 								zc->routeindex = Route[zc->routeindex].linkpod[i];// zc->route_trace = false;
3476 								zc->havetarget = false;
3477 //gi.bprintf(PRINT_HIGH,"fixed for flag 2\n");
3478 							}
3479 						}
3480 					}
3481 					else if(!zc->havetarget && zc->ctfstate == CTFS_CARRIER)
3482 					{
3483 						zc->havetarget = true;
3484 						zc->targetindex = Route[zc->routeindex].linkpod[MAXLINKPOD - 1] & 0x7FFF;
3485 					}
3486 				}
3487 			}
3488 		}
3489 	}
3490 
3491 	if(1/*!(zc->zcstate & STS_WAITSMASK)*/)
3492 	{
3493 		//���[�g�g���[�X�pindex����
3494 		if(!zc->route_trace && zc->rt_releasetime <= level.time)
3495 		{
3496 			//zc->routeindex;
3497 			if(zc->routeindex >= CurrentIndex) zc->routeindex = 0;
3498 			//fix route index
3499 			for(i = 0;i < CurrentIndex && i < MAX_SEARCH;i++)
3500 			{
3501 				if(Route[zc->routeindex].state == GRS_GRAPHOOK)
3502 				{
3503 					while(1)
3504 					{
3505 						++zc->routeindex;
3506 						if(zc->routeindex >= CurrentIndex){i = CurrentIndex; break;}
3507 						if(Route[zc->routeindex].state == GRS_GRAPRELEASE) {++zc->routeindex; break;}
3508 					}
3509 					continue;
3510 				}
3511 				else if(Route[zc->routeindex].state == GRS_GRAPRELEASE) {++zc->routeindex; continue;}
3512 				else if(ctf->value && !chedit->value)
3513 				{
3514 					if(Route[zc->routeindex].state < GRS_ITEMS
3515 						&& Route[zc->routeindex].linkpod[MAXLINKPOD - 1])
3516 					{
3517 						k = Route[zc->routeindex].linkpod[MAXLINKPOD - 1];
3518 						if(j == FOR_FLAG1)
3519 						{
3520 							if(k & CTF_FLAG2_FLAG)
3521 							{
3522 								zc->routeindex = (k & 0x7FFF);
3523 //gi.bprintf(PRINT_HIGH,"skipped to flag 1 %x\n",k);
3524 							}
3525 						}
3526 						else if(j == FOR_FLAG2)
3527 						{
3528 							if(!(k & CTF_FLAG2_FLAG))
3529 							{
3530 								zc->routeindex = (k & 0x7FFF);
3531 //gi.bprintf(PRINT_HIGH,"skipped to flag 2 %x\n",k);
3532 							}
3533 						}
3534 					}
3535 				}
3536 				Get_RouteOrigin(zc->routeindex,v);
3537 //				VectorSubtract(Route[k].Pt,ent->s.origin,temppos);
3538 				if(Route[zc->routeindex].state <= GRS_ITEMS && TraceX(ent,v))
3539 				{
3540 					if(fabs(v[2] - ent->s.origin[2]) <= JumpMax || zc->waterstate == WAS_IN)
3541 					{
3542 						zc->route_trace = true;
3543 						zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
3544 						break;
3545 					}
3546 				}
3547 				if(++zc->routeindex >= CurrentIndex) zc->routeindex = 0;
3548 			}
3549 		}
3550 		else if(zc->route_trace)
3551 		{
3552 			if(Route[zc->routeindex].state == GRS_ONDOOR)
3553 			{
3554 				if(1/*!Route[zc->routeindex].ent->union_ent*/)
3555 				{
3556 					it_ent = Route[zc->routeindex].ent;
3557 					if(zc->routeindex + 1 < CurrentIndex )
3558 					{
3559 						Get_RouteOrigin(zc->routeindex + 1,v);
3560 						zc->route_trace = false;
3561 						j = TraceX(ent,v);
3562 						zc->route_trace = true;
3563 						if((!j || (v[2] - ent->s.origin[2]) > JumpMax )&& it_ent->union_ent)
3564 						{
3565 
3566 							k = false;
3567 							if((it_ent->union_ent->s.origin[2] - ent->s.origin[2]) > JumpMax) k = true;
3568 
3569 							VectorSubtract(it_ent->union_ent->s.origin,ent->s.origin,temppos);
3570 							yaw = Get_yaw(temppos);
3571 							if(trace_priority < TRP_ANGLEKEEP)
3572 							{
3573 								ent->s.angles[PITCH] = Get_pitch(temppos);
3574 								ent->s.angles[YAW] = yaw;
3575 							}
3576 							temppos[2] = 0;
3577 							x = VectorLength(temppos);
3578 
3579 							if( x == 0/*< dist*/ || k)
3580 							{
3581 								if(it_ent->nextthink >= level.time) zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
3582 								goto VCHCANSEL;	//if center position move cancel
3583 							}
3584 							if(x < dist) dist = x;
3585 							if(it_ent->nextthink > level.time) zc->rt_locktime = it_ent->nextthink + FRAMETIME * POD_LOCKFRAME;
3586 							else zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
3587 							if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = yaw;
3588 							goto GOMOVE;
3589 						}
3590 					}
3591 
3592 				}
3593 				zc->routeindex++;
3594 			}
3595 
3596 			if(zc->routeindex < CurrentIndex)
3597 			{
3598 				Get_RouteOrigin(zc->routeindex,v);
3599 /*				if(Route[zc->routeindex].state == GRS_ITEMS)
3600 				{
3601 					if(Route[zc->routeindex].ent->solid == SOLID
3602 				}*/
3603 
3604 				k = false;
3605 				if(Route[zc->routeindex].state == GRS_PUSHBUTTON)
3606 				{
3607 					it_ent = Route[zc->routeindex].ent;
3608 					if(it_ent->health && (it_ent->takedamage || it_ent->moveinfo.state != PSTATE_TOP))
3609 					{
3610 						k = 2;
3611 					}
3612 					else if(it_ent->health)
3613 					{
3614 						zc->routeindex++;
3615 						if(zc->routeindex < CurrentIndex) Get_RouteOrigin(zc->routeindex,v);
3616 					}
3617 				}
3618 				else
3619 				{
3620 					//VectorCopy(ent->mins,touchmin);
3621 					//touchmin[2] += 20;
3622 					VectorSet(touchmax,16,16,4);
3623 					VectorSet(touchmin,-16,-16,0);
3624 					rs_trace = gi.trace(ent->s.origin,touchmin,touchmax,v,ent,MASK_SHOT);
3625 					if(rs_trace.fraction != 1.0 && rs_trace.ent)
3626 					{
3627 						if((rs_trace.ent->health || rs_trace.ent->takedamage)
3628 							&& rs_trace.ent->classname[0] != 'p'
3629 							&& rs_trace.ent->classname[0] != 'b')
3630 						{
3631 //gi.bprintf(PRINT_HIGH,"shushu!\n");
3632 							zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
3633 							it_ent = rs_trace.ent;
3634 							k = true;
3635 						}
3636 					}
3637 				}
3638 
3639 				//�g���K������
3640 				if(k && !(ent->client->buttons & BUTTON_ATTACK))
3641 				{
3642 //gi.bprintf(PRINT_HIGH,"ooooooo!\n");
3643 					trmin[0] = (it_ent->absmin[0] + it_ent->absmax[0])/2;
3644 					trmin[1] = (it_ent->absmin[1] + it_ent->absmax[1])/2;
3645 					trmin[2] = (it_ent->absmin[2] + it_ent->absmax[2])/2;
3646 
3647 					//if button
3648 					if(k == 2)
3649 					{
3650 						VectorSet(touchmin, 0, 0, ent->viewheight-8);
3651 						VectorAdd(ent->s.origin,touchmin,touchmin);
3652 
3653 						rs_trace = gi.trace(it_ent->union_ent->s.origin,NULL,NULL,trmin,it_ent->union_ent,MASK_SHOT);
3654 						VectorSubtract(rs_trace.endpos,ent->s.origin,trmax);
3655 					}
3656 					else VectorSubtract(v,ent->s.origin,trmax);
3657 
3658 //gi.bprintf(PRINT_HIGH,"shoot!\n");
3659 					//�������m�̎��͎����ւ�
3660 					i = Get_KindWeapon(ent->client->pers.weapon);
3661 					if(!zc->first_target && it_ent->takedamage)
3662 					{
3663 						if(i == WEAP_GRENADES
3664 							|| i == WEAP_GRENADELAUNCHER
3665 							|| i == WEAP_ROCKETLAUNCHER
3666 							|| i == WEAP_PHALANX
3667 							|| i == WEAP_BFG)
3668 						{
3669 							item = Fdi_BLASTER;//FindItem("Blaster");
3670 							item->use(ent,item);
3671 //if(ent->client->newweapon) gi.bprintf(PRINT_HIGH,"selected %s\n",ent->client->newweapon->pickup_name);
3672 						}
3673 					}
3674 					if(!zc->first_target || it_ent->takedamage)
3675 					{
3676 						ent->s.angles[YAW] = Get_yaw(trmax);
3677 						ent->s.angles[PITCH] = Get_pitch(trmax);
3678 					}
3679 					if(it_ent->takedamage) ent->client->buttons |= BUTTON_ATTACK;
3680 					if(k == 2)
3681 					{
3682 						if(it_ent->moveinfo.state != PSTATE_TOP) goto VCHCANSEL;
3683 					}
3684 					else
3685 					{
3686 						if(!TraceX(ent,v)) goto VCHCANSEL;
3687 					}
3688 					//if(j)goto VCHCANSEL;
3689 				}
3690 
3691 				if(Route[zc->routeindex].state == GRS_ONTRAIN && !zc->waterstate /*< WAS_IN*/
3692 					/*ent->groundentity*/)
3693 				{
3694 					Get_RouteOrigin(zc->routeindex -1 ,trmin);
3695 					if((trmin[2] - ent->s.origin[2]) > /*2*/JumpMax
3696 						&& (v[2] - ent->s.origin[2]) > JumpMax
3697 						&& ent->waterlevel < 3)
3698 					{
3699 						zc->route_trace = false;
3700 #ifdef _DEBUG
3701 gi.bprintf(PRINT_HIGH,"OFF 10\n");
3702 #endif
3703 					}
3704 /*					if(!Q_stricmp(ent->groundentity->classname, "func_train"))
3705 					{
3706 						VectorCopy(ent->groundentity->union_ent->s.origin,v);
3707 						if(VectorLength(v) < 16 && (zc->routeindex + 1) < CurrentIndex)
3708 						{
3709 							zc->routeindex++;
3710 							Get_RouteOrigin(zc->routeindex,v);
3711 						}
3712 
3713 					}*/
3714 
3715 				}
3716 				if(zc->waterstate == WAS_IN) f2 = 20;
3717 				else if(ent->groundentity) f2 = -8;
3718 				else f2 = 0;
3719 				if(ent->client->ps.pmove.pm_flags & PMF_DUCKED) f1 = -16;
3720 				else
3721 				{
3722 					if(zc->waterstate == WAS_IN) f1 = 24;
3723 					else if(/*zc->waterstate == WAS_FLOAT*/ent->waterlevel && ent->waterlevel < 3)
3724 					{
3725 						if(v[0] == ent->s.origin[0] && v[1] == ent->s.origin[1]) f1 = -300;
3726 						else f1 = -(JumpMax + 64);
3727 					}
3728 					else f1 = -(JumpMax + 64);
3729 				}
3730 //���B�`�F�b�N
3731 				if( Route[zc->routeindex].state == GRS_ONROTATE) yaw = -48;
3732 				else yaw = 12;
3733 				if(v[0] <= (ent->absmax[0] - yaw) && v[0] >= (ent->absmin[0] + yaw))
3734 				{
3735 					if(v[1] <= (ent->absmax[1] - yaw) && v[1] >= (ent->absmin[1] + yaw))
3736 					{
3737 						if((v[2] <= (ent->absmax[2] - f1) && v[2] >= (ent->absmin[2] + f2))
3738 							|| Route[zc->routeindex].state == GRS_ONROTATE
3739 							/*|| zc->waterstate == WAS_FLOAT*/)
3740 						{
3741 							if(zc->routeindex < CurrentIndex /*&& TraceX(ent,Route[zc->routeindex + 1].Pt)*/)
3742 							{
3743 //�A�C�e�������N�`�F�b�N1>>
3744 								if(Route[zc->routeindex].state <= GRS_ITEMS)
3745 								{
3746 									if(zc->havetarget)
3747 									{
3748 										for(i = 0;i < (MAXLINKPOD - (ctf->value != 0));i++)
3749 										{
3750 											k = Route[zc->routeindex].linkpod[i];
3751 											if(!k) break;
3752 //gi.bprintf(PRINT_HIGH,"tryto change index1\n");
3753 											if(k > zc->routeindex && k < zc->targetindex)
3754 											{
3755 //gi.bprintf(PRINT_HIGH,"change index1\n");
3756 												if(1/*!ctf->value*/)
3757 												{
3758 													zc->routeindex = k;
3759 													break;
3760 												}
3761 											}
3762 										}
3763 									}
3764 									else if(random() < 0.2 && !ctf->value)
3765 									{
3766 										for(i = 0;i < (MAXLINKPOD - (ctf->value != 0));i++)
3767 										{
3768 											k = Route[zc->routeindex].linkpod[i];
3769 											if(!k) break;
3770 											if(k > zc->routeindex && k < zc->targetindex)
3771 											{
3772 												if(random() < 0.5)
3773 												{
3774 													zc->routeindex = k;
3775 													break;
3776 												}
3777 											}
3778 										}
3779 									}
3780 								}
3781 //�A�C�e�������N�`�F�b�N<<
3782 								zc->routeindex++;
3783 								//not a normal pod
3784 								if(zc->routeindex < CurrentIndex)
3785 								{
3786 									if(Route[zc->routeindex].state != GRS_NORMAL && Route[zc->routeindex].ent)
3787 									{
3788 										//when items
3789 										if(0/*Route[zc->routeindex].state == GRS_ITEMS*/)
3790 										{
3791 											zc->second_target = Route[zc->routeindex].ent;
3792 											//zc->routeindex++;
3793 										}
3794 									}
3795 								}
3796 								else zc->routeindex = 0;
3797 							}
3798 						}
3799 					}
3800 				}
3801 
3802 				if(zc->routeindex < CurrentIndex
3803 					&& trace_priority && zc->second_target == NULL)
3804 				{
3805 					if(1/*TraceX(ent,Route[zc->routeindex].Pt)*/)
3806 					{
3807 						Get_RouteOrigin(zc->routeindex,v);
3808 
3809 						VectorSubtract(v,ent->s.origin,temppos);
3810 						if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[PITCH] = Get_pitch(temppos);
3811 
3812 						k = false;
3813 //						if(zc->waterstate != WAS_IN && temppos[2] < 32) k = true;
3814 //						else if(zc->waterstate == WAS_IN) k = true;
3815 
3816 						if(ent->groundentity /*|| ent->waterlevel ) &&
3817 							/*temppos[2] < 32 || zc->waterstate != WAS_IN)*/ || ent->waterlevel/*zc->waterstate*/ )
3818 						{
3819 							k = false;
3820 							yaw = temppos[2];
3821 							temppos[2] = 0;
3822 							x = VectorLength(temppos);
3823 //							if(yaw > JumpMax) k = true;
3824 
3825 							if(!k)
3826 							{
3827 								k = false;
3828 								if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);	//set the movin' yaw
3829 								if((ent->groundentity || ent->waterlevel) && trace_priority < TRP_ANGLEKEEP) {ent->s.angles[YAW] = zc->moveyaw; k = true;}
3830 
3831 								if(x < dist && fabs(yaw) < 20/*JumpMax*/&& k)
3832 								{
3833 									iyaw = Get_yaw(temppos);
3834 									i = Bot_moveT (ent,iyaw,temppos,x,&bottom);
3835 									rs_trace = gi.trace(/*ent->s.origin*/v,ent->mins,ent->maxs,v,ent,MASK_BOTSOLIDX);
3836 
3837 									if(Route[zc->routeindex].state == GRS_ITEMS && !i)
3838 									{
3839 										if(x < 30) zc->routeindex++;
3840 									}
3841 
3842 									else if((Route[zc->routeindex].state == GRS_ITEMS
3843 										|| Route[zc->routeindex].state == GRS_NORMAL)
3844 										&& !rs_trace.allsolid && !rs_trace.startsolid
3845 										&& HazardCheck(ent,v)
3846 										&& fabs(bottom) < 20 && i && !ent->waterlevel/*&& rs_trace.fraction == 1.0*/)
3847 									{
3848 										j = false;
3849 										if(v[2] < ent->s.origin[2] && bottom < 0) j = true;
3850 										else if(v[2] >= ent->s.origin[2] && bottom >= 0) j = true;
3851 										if(j)
3852 										{
3853 											VectorCopy(temppos,ent->s.origin);
3854 											VectorCopy(v,trmin);
3855 											dist -= x;
3856 //�A�C�e�������N�`�F�b�N2>>
3857 											if(Route[zc->routeindex].state <= GRS_ITEMS)
3858 											{
3859 												if(zc->havetarget)
3860 												{
3861 													for(i = 0;i < (MAXLINKPOD - (ctf->value != 0));i++)
3862 													{
3863 														j = Route[zc->routeindex].linkpod[i];
3864 														if(!j) break;
3865 //gi.bprintf(PRINT_HIGH,"tryto change index2\n");
3866 														if(j > zc->routeindex && j < zc->targetindex)
3867 														{
3868 //gi.bprintf(PRINT_HIGH,"change index2\n");
3869 															zc->routeindex = j;
3870 															break;
3871 														}
3872 													}
3873 												}
3874 											}
3875 //�A�C�e�������N�`�F�b�N<<
3876 											zc->routeindex++;
3877 											if(i == 2) ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
3878 
3879 											Get_RouteOrigin(zc->routeindex,v);
3880 											VectorSubtract(v,ent->s.origin,temppos);
3881 											if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[PITCH] = Get_pitch(temppos);
3882 											if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);
3883 											if(k && trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = zc->moveyaw;
3884 										}
3885 									}
3886 									else if((Route[zc->routeindex].state == GRS_ITEMS
3887 										|| Route[zc->routeindex].state == GRS_NORMAL)
3888 										&& fabs(bottom) < 20 && ent->waterlevel
3889 										/*&& !(zc->zcstate & STS_LADDERUP)*/)
3890 									{
3891 										j = false;
3892 										if(v[2] < ent->s.origin[2] && bottom < 0) j = true;
3893 										else if(v[2] >= ent->s.origin[2] && bottom >= 0) j = true;
3894 										if(j)
3895 										{
3896 											VectorCopy(temppos,ent->s.origin);
3897 											//VectorCopy(v,ent->s.origin);
3898 											VectorCopy(v,trmin);
3899 											dist -= x;
3900 											zc->routeindex++;
3901 											Get_RouteOrigin(zc->routeindex,v);
3902 											VectorSubtract(v,ent->s.origin,temppos);
3903 											if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[PITCH] = Get_pitch(temppos);
3904 											if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);
3905 											if(k && trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = zc->moveyaw;
3906 										}
3907 										else dist = x;
3908 									}
3909 									else dist = x;
3910 								}
3911 								else if(x < dist) dist = x;
3912 							}
3913 
3914 							k = false;
3915 							if((zc->routeindex - 1) >= 0 &&
3916 								(Route[zc->routeindex].state == GRS_ONPLAT
3917 								|| Route[zc->routeindex].state == GRS_ONTRAIN))
3918 							{
3919 								Get_RouteOrigin(zc->routeindex - 1,v);
3920 								if(fabs(v[2] - ent->s.origin[2]) <= JumpMax)
3921 								{
3922 									if(zc->waterstate < WAS_IN
3923 										/*&& Route[zc->routeindex].ent->trainteam == NULL*/
3924 										&& Route[zc->routeindex].ent->nextthink > level.time) k = true;
3925 								}
3926 
3927 							}
3928 							if(k && !(zc->zcstate & STS_WAITS))
3929 							{
3930 								if((zc->routeindex + 1) < CurrentIndex)
3931 								{
3932 									Get_RouteOrigin(zc->routeindex + 1,v);
3933 									if((v[2] - ent->s.origin[2]) > JumpMax)
3934 									{
3935 										if((Route[zc->routeindex].ent->union_ent->s.origin[2]
3936 											- ent->s.origin[2]) > JumpMax
3937 											/*|| !TraceX(ent,v)*/)
3938 										{
3939 											zc->waitin_obj = Route[zc->routeindex].ent;
3940 											zc->zcstate |= STS_W_COMEPLAT;
3941 											k = false;
3942 											for(i = 1;i <=3;i++)
3943 											{
3944 												if(zc->routeindex - i >= 0)
3945 												{
3946 													Get_RouteOrigin(zc->routeindex - i,v);
3947 													if(zc->waitin_obj->absmax[0] < (v[0] + ent->mins[0])) k = true;
3948 													else if(zc->waitin_obj->absmax[1] < (v[1] + ent->mins[1])) k = true;
3949 													else if(zc->waitin_obj->absmin[0] > (v[0] + ent->maxs[0])) k = true;
3950 													else if(zc->waitin_obj->absmin[1] > (v[1] + ent->maxs[1])) k = true;
3951 													if(k) break;
3952 												}
3953 											}
3954 											if(k) VectorCopy(v,zc->movtarget_pt);
3955 											else Get_RouteOrigin(zc->routeindex - 1,zc->movtarget_pt);
3956 
3957 											goto VCHCANSEL;
3958 										}
3959 									}
3960 								}
3961 							}
3962 
3963 						}
3964 						//ent->s.angles[YAW] = zc->moveyaw;
3965 					}
3966 				}
3967 				else if(zc->routeindex >= CurrentIndex)
3968 				{
3969 #ifdef _DEBUG
3970 gi.bprintf(PRINT_HIGH,"OFF 6\n"); //ppx
3971 #endif
3972 					zc->routeindex = 0;
3973 					zc->route_trace = false;
3974 				}
3975 			}
3976 			else
3977 			{
3978 #ifdef _DEBUG
3979 gi.bprintf(PRINT_HIGH,"OFF 7\n"); //ppx
3980 #endif
3981 				zc->routeindex = 0;
3982 				zc->route_trace = false;
3983 			}
3984 		}
3985 	}
3986 	else
3987 	{
3988 #ifdef _DEBUG
3989 gi.bprintf(PRINT_HIGH,"OFF 8\n"); //ppx
3990 #endif
3991 		zc->route_trace = false;
3992 	}
3993 
3994 	//--------------------------------------------------------------------------------------
3995 	//ground entity check
3996 	//
3997 	//
3998 	//
3999 	//	�������Ɗm�F
4000 	//
4001 	//
4002 	//--------------------------------------------------------------------------------------
4003 
4004 	if(!(zc->zcstate & STS_W_DOOROPEN ) && (!ent->groundentity || ent->groundentity != zc->waitin_obj))
4005 	{
4006 		k = false;
4007 		if(zc->waitin_obj) if(Q_stricmp (zc->waitin_obj->classname,"func_door")) k = true;
4008 
4009 		if(!k)
4010 		{
4011 			zc->zcstate &= ~STS_WAITS;
4012 			zc->waitin_obj = NULL;
4013 		}
4014 	}
4015 
4016 	if(ent->groundentity && /*!j &&*/ !(zc->zcstate & STS_WAITS) )
4017 	{
4018 		it_ent = ent->groundentity;
4019 		if( it_ent->classname[0] == 'f')
4020 		{
4021 			if(Q_stricmp (it_ent->classname, "func_plat") == 0)
4022 			{
4023 /*if(it_ent->moveinfo.state == PSTATE_UP && it_ent->nextthink <= level.time )
4024 gi.bprintf(PRINT_HIGH,"aw shit!!\n");*/
4025 				if(it_ent->pos1[2] > it_ent->pos2[2]
4026 					&& ((it_ent->moveinfo.state == PSTATE_UP && it_ent->velocity[2] > 0 ) || it_ent->moveinfo.state == PSTATE_BOTTOM)
4027 					/*&& it_ent->s.origin[2] != it_ent->s.old_origin[2]*/)
4028 				{
4029 //gi.bprintf(PRINT_HIGH,"osssre onplat!!\n");
4030 					zc->waitin_obj = it_ent;
4031 					zc->zcstate |= STS_W_ONPLAT;
4032 					if(zc->route_trace)
4033 					{
4034 //gi.bprintf(PRINT_HIGH,"ore onplat!!\n");
4035 						if(Route[zc->routeindex].ent == zc->waitin_obj
4036 							&& Route[zc->routeindex].state == GRS_ONPLAT)
4037 						{
4038 //gi.bprintf(PRINT_HIGH,"YEAH onplat!!\n");
4039 							if(zc->waitin_obj->union_ent->s.origin[2] > (ent->s.origin[2] + 32))
4040 							{
4041 								zc->zcstate &= ~STS_W_ONPLAT;
4042 								zc->zcstate |= STS_W_COMEPLAT;
4043 							}
4044 							else zc->routeindex++;
4045 						}
4046 					/*	for(i = 0;i < 10;i++)
4047 						{
4048 							if((zc->routeindex + i) >= CurrentIndex) break;
4049 							if(!Route[zc->routeindex + i].index) break;
4050 							if(Route[zc->routeindex + i].state == GRS_ONPLAT
4051 								&& Route[zc->routeindex + i].ent == zc->waitin_obj)
4052 							{
4053 								zc->routeindex += i + 1;
4054 								break;
4055 							}
4056 						}*/
4057 					}
4058 				}
4059 			}
4060 			//on train
4061 			else if(Q_stricmp (it_ent->classname, "func_train") == 0
4062 				&& it_ent->nextthink >= level.time
4063 				&& ((it_ent->s.origin[2] - it_ent->s.old_origin[2]) > 0
4064 				|| zc->route_trace))
4065 //				&& abs(it_ent->moveinfo.start_origin[2] - it_ent->moveinfo.end_origin[2]) > 54)
4066 			{
4067 //gi.bprintf(PRINT_HIGH,"challenge!!\n");
4068 				//route trace on
4069 				if(zc->route_trace && zc->routeindex > 0)
4070 				{
4071 					j = false;
4072 					k = zc->routeindex - 1;
4073 					for(i = 0;i < 3;i++)
4074 					{
4075 						if((k + i) < CurrentIndex)
4076 						{
4077 							if(Route[k + i].state == GRS_ONTRAIN)
4078 							{
4079 								if(Route[k + i].ent == it_ent) j = true;
4080 								else if(it_ent->trainteam != NULL)
4081 								{
4082 									e = it_ent->trainteam;
4083 									while(1)
4084 									{
4085 										if(e == it_ent)
4086 										{
4087 											break;
4088 										}
4089 										if(e == Route[k + i].ent)
4090 										{
4091 											j = true;
4092 											it_ent = e;
4093 											Route[k + i].ent = e;
4094 											break;
4095 										}
4096 										e = e->trainteam;
4097 									}
4098 								}
4099 								else if(/*e*/it_ent->target_ent)
4100 								{
4101 									if(VectorCompare(Route[k + i].Tcourner,/*e*/it_ent->target_ent->s.origin))
4102 									{
4103 										j = true;
4104 										//it_ent = e;
4105 										break;
4106 									}
4107 								}
4108 								if(j) break;
4109 							}
4110 						}
4111 						else break;
4112 					}
4113 					if(j)
4114 					{
4115 //gi.bprintf(PRINT_HIGH,"On train1!!\n");
4116 						zc->zcstate |= STS_W_ONTRAIN;
4117 						zc->waitin_obj = it_ent;
4118 						zc->routeindex = k + i + 1;
4119 					}
4120 				}
4121 /*					if(Route[zc->routeindex - 1].state == GRS_ONTRAIN
4122 //						&& it_ent->trainteam == NULL
4123 						&& it_ent == Route[zc->routeindex - 1].ent)
4124 					{
4125 							zc->zcstate |= STS_W_ONTRAIN;
4126 							zc->waitin_obj = it_ent;
4127 					}
4128 					else if(Route[zc->routeindex].state == GRS_ONTRAIN
4129 						&& it_ent == Route[zc->routeindex].ent
4130 						&& zc->routeindex + 1 < CurrentIndex)
4131 					{
4132 						Get_RouteOrigin(zc->routeindex + 1,v);
4133 						if(!TraceX(ent,v))
4134 						{
4135 							zc->zcstate |= STS_W_ONTRAIN;
4136 							zc->waitin_obj = it_ent;
4137 						}
4138 						zc->routeindex++;
4139 					}
4140 					else if(Route[zc->routeindex].state == GRS_ONTRAIN
4141 						&& it_ent->trainteam
4142 						&& zc->routeindex + 1 < CurrentIndex)
4143 					{
4144 						Get_RouteOrigin(zc->routeindex + 1,v);
4145 						if(!TraceX(ent,v))
4146 						{
4147 							k = false;
4148 							e = it_ent->trainteam;
4149 							while(1)
4150 							{
4151 								if(e == it_ent) break;
4152 								if(e == Route[zc->routeindex].ent)
4153 								{
4154 									k = true;
4155 									break;
4156 								}
4157 								e = e->trainteam;
4158 							}
4159 							if(k)
4160 							{
4161 								zc->zcstate |= STS_W_ONTRAIN;
4162 								zc->waitin_obj = it_ent;
4163 								zc->routeindex++;
4164 							}
4165 						}
4166 					}
4167 				}*/
4168 				else
4169 				{
4170 //					if(it_ent->moveinfo.start_origin[2] > it_ent->moveinfo.end_origin[2]) x = it_ent->moveinfo.end_origin[2];
4171 //					else x = it_ent->moveinfo.start_origin[2];
4172 
4173 					if((it_ent->s.origin[2] - it_ent->s.old_origin[2]) > 0
4174 						/*|| (it_ent->s.origin[2] == it_ent->s.old_origin[2] && x == it_ent->s.origin[2])*/ )
4175 					{
4176 //gi.bprintf(PRINT_HIGH,"On train2!!\n");
4177 						zc->zcstate |= STS_W_ONTRAIN;
4178 						zc->waitin_obj = it_ent;
4179 					}
4180 					else if((it_ent->s.origin[2] - it_ent->s.old_origin[2]) > -2
4181 						&& trace_priority && zc->second_target == NULL)
4182 					{
4183 //gi.bprintf(PRINT_HIGH,"On train3!!\n");
4184 						zc->zcstate |= STS_W_ONTRAIN;
4185 						zc->waitin_obj = it_ent;
4186 					}
4187 					else zc->zcstate |= STS_W_DONT;
4188 				}
4189 			}
4190 		}
4191 	}
4192 
4193 	if((zc->zcstate & STS_W_DONT) && ent->groundentity)
4194 	{
4195 		if(zc->zcstate & STS_W_ONPLAT)
4196 		{
4197 			if(Q_stricmp (ent->groundentity->classname, "func_plat"))
4198 			{
4199 				zc->zcstate &= ~STS_WAITS;
4200 				zc->waitin_obj = NULL;
4201 			}
4202 		}
4203 		else if(zc->zcstate & STS_W_ONTRAIN)
4204 		{
4205 			if(Q_stricmp (ent->groundentity->classname, "func_train"))
4206 			{
4207 				zc->zcstate &= ~STS_WAITS;
4208 				zc->waitin_obj = NULL;
4209 			}
4210 		}
4211 		else if(zc->zcstate & (STS_W_ONDOORUP | STS_W_ONDOORDWN))
4212 		{
4213 			if(Q_stricmp (ent->groundentity->classname, "func_door"))
4214 			{
4215 				zc->zcstate &= ~STS_WAITS;
4216 				zc->waitin_obj = NULL;
4217 			}
4218 		}
4219 		else
4220 		{
4221 			zc->zcstate &= ~STS_WAITS;
4222 			zc->waitin_obj = NULL;
4223 		}
4224 	}
4225 
4226 
4227 	//on plat
4228 	else if((
4229 		(zc->zcstate & STS_W_ONPLAT)
4230 		|| (zc->zcstate & STS_W_COMEPLAT)
4231 		|| (zc->zcstate & STS_W_ONDOORUP)
4232 		|| (zc->zcstate & STS_W_ONDOORDWN)) && !(zc->zcstate & STS_W_DONT))
4233 	{
4234 		k = false;
4235 		//if door
4236 		if(zc->zcstate & (STS_W_ONDOORUP | STS_W_ONDOORDWN) )
4237 		{
4238 			// up
4239 			if(zc->zcstate & STS_W_ONDOORUP)
4240 			{
4241 				if(zc->waitin_obj->moveinfo.state == PSTATE_UP
4242 					|| zc->waitin_obj->moveinfo.state == PSTATE_BOTTOM) k = true;
4243 			}
4244 			// down
4245 			else
4246 			{
4247 				if(zc->waitin_obj->moveinfo.state == PSTATE_TOP
4248 					|| zc->waitin_obj->moveinfo.state == PSTATE_DOWN) k = true;
4249 			}
4250 		}
4251 		else if(zc->zcstate & STS_W_COMEPLAT)
4252 		{
4253 			if(Route[zc->routeindex].state == GRS_ONTRAIN)
4254 			{
4255 				if(!TraceX(ent,/*zc->waitin_obj*/Route[zc->routeindex].ent->union_ent->s.origin)) k = true;
4256 				if((/*zc->waitin_obj*/Route[zc->routeindex].ent->union_ent->s.origin[2]
4257 								+ 8 - ent->s.origin[2]) > JumpMax) k = true;
4258 			}
4259 			else
4260 			{
4261 				if((zc->waitin_obj->union_ent->s.origin[2]
4262 											- ent->s.origin[2]) > JumpMax) k = true;
4263 			}
4264 //			if(zc->waitin_obj->velocity[2] == 0) k = false;
4265 			if(zc->routeindex - 1 > 0 && zc->waterstate < WAS_IN)
4266 			{
4267 				Get_RouteOrigin(zc->routeindex -1 ,trmin);
4268 				if((trmin[2] - ent->s.origin[2]) > JumpMax
4269 						&& (v[2] - ent->s.origin[2]) > JumpMax)
4270 //				Get_RouteOrigin(zc->routeindex - 1,v);
4271 //				if((v[2] - ent->s.origin[2]) > JumpMax)
4272 					k = false;
4273 			}
4274 		}
4275 		else
4276 		{
4277 			if(/*!k &&*/ zc->waitin_obj->moveinfo.state == PSTATE_UP
4278 				|| zc->waitin_obj->moveinfo.state == PSTATE_BOTTOM) k = true;
4279 
4280 			if(zc->waitin_obj->moveinfo.state == PSTATE_BOTTOM) plat_go_up (zc->waitin_obj);
4281 
4282 			if(zc->route_trace)
4283 			{
4284 				Get_RouteOrigin(zc->routeindex,v);
4285 				if(ent->s.origin[2] > v[2] ) k = 2;
4286 			}
4287 		}
4288 		//have target
4289 		if(/*j ||*/ k != true)
4290 		{
4291 			if(k == 2) zc->zcstate |= STS_W_DONT;
4292 			else
4293 			{
4294 				zc->zcstate &= ~STS_WAITS;
4295 				zc->waitin_obj = NULL;
4296 			}
4297 		}
4298 		else
4299 		{
4300 			if(zc->zcstate & STS_W_COMEPLAT)
4301 			{
4302 				k = false;
4303 				if(zc->routeindex -1 >0)
4304 				{
4305 					if(1/*Route[zc->routeindex - 1].state <= GRS_ITEMS*/)
4306 					{
4307 						//Get_RouteOrigin(zc->routeindex - 1,trmax);
4308 						VectorCopy(zc->movtarget_pt,trmax);
4309 						trmax[2] = 0;
4310 						k = true;
4311 					}
4312 				}
4313 				if(!k) goto VCHCANSEL;
4314 			}
4315 			else
4316 			{
4317 				trmax[0] = (zc->waitin_obj->absmin[0] + zc->waitin_obj->absmax[0]) / 2;
4318 				trmax[1] = (zc->waitin_obj->absmin[1] + zc->waitin_obj->absmax[1]) / 2;
4319 				trmax[2] = 0;
4320 			}
4321 			VectorSubtract(trmax,ent->s.origin,temppos);
4322 			yaw = temppos[2];
4323 			temppos[2] = 0;
4324 			x = VectorLength(temppos);
4325 			if( x == 0) goto VCHCANSEL;	//if center position move cancel
4326 			if( x < dist) dist = x;
4327 
4328 			if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);
4329 		}
4330 	}
4331 	// on train
4332 	else if(zc->zcstate & STS_W_ONTRAIN)
4333 	{
4334 		i = false;
4335 
4336 		if(zc->route_trace)
4337 		{
4338 			Get_RouteOrigin(zc->routeindex,v);
4339 
4340 			if((zc->routeindex - 1) >= 0)
4341 			{
4342 				if(Route[zc->routeindex - 1].state != GRS_ONTRAIN) i = true;
4343 			}
4344 			else i = true;
4345 
4346 			if(TraceX(ent,v))
4347 			{
4348 				x = v[2] - /*zc->waitin_obj->union_ent->s.origin[2];*/ent->s.origin[2];
4349 				if(x <= JumpMax)
4350 				{
4351 //gi.bprintf(PRINT_HIGH,"released!!! %f %i\n",x,Route[zc->routeindex].state);
4352 					i = true;
4353 				}
4354 				else zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
4355 			}
4356 			else zc->rt_locktime = level.time + FRAMETIME * POD_LOCKFRAME;
4357 		}
4358 		else if(j || (zc->waitin_obj->s.origin[2] - zc->waitin_obj->s.old_origin[2]) <= 0 ) i = true;
4359 
4360 		if(i)
4361 		{
4362 			zc->zcstate |= STS_W_DONT;
4363 			zc->zcstate &= ~STS_WAITS;
4364 //			zc->waitin_obj = NULL;
4365 		}
4366 		else
4367 		{
4368 			k = false;
4369 			if(zc->route_trace)
4370 			{
4371 				rs_trace = gi.trace(ent->s.origin,NULL,NULL,v,ent,MASK_BOTSOLIDX/*MASK_PLAYERSOLID*/);
4372 				if(rs_trace.ent == zc->waitin_obj )
4373 				{
4374 					rs_trace = gi.trace(v,NULL,NULL,ent->s.origin,ent,MASK_BOTSOLIDX/*MASK_PLAYERSOLID*/);
4375 					if(rs_trace.ent == zc->waitin_obj )
4376 					{
4377 						VectorSubtract(v,ent->s.origin,temppos);
4378 						k = true;
4379 					}
4380 				}
4381 			}
4382 			if(!k)
4383 			{
4384 //gi.bprintf(PRINT_HIGH,"ponko1!\n");
4385 				VectorCopy(zc->waitin_obj->union_ent->s.origin,trmax);
4386 				//trmax[0] = (zc->waitin_obj->absmin[0] + zc->waitin_obj->absmax[0]) / 2;
4387 				//trmax[1] = (zc->waitin_obj->absmin[1] + zc->waitin_obj->absmax[1]) / 2;
4388 				trmax[2] += 8;
4389 				VectorSubtract(trmax,ent->s.origin,temppos);
4390 				yaw = temppos[2];
4391 				temppos[2] = 0;
4392 				x = VectorLength(temppos);
4393 
4394 //gi.bprintf(PRINT_HIGH,"ponko2! %f < %f\n",x,dist);
4395 
4396 				if( x < dist  /*MOVE_SPD_RUN*/)
4397 				{
4398 					dist = x;
4399 //					goto VCHCANSEL;	//if center position move cancel
4400 				}
4401 			}
4402 			if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);
4403 		}
4404 		goto GOMOVE;
4405 	}
4406 	//wait for door open
4407 	else if(zc->zcstate & STS_W_DOOROPEN)
4408 	{
4409 		if(!trace_priority
4410 			|| zc->waitin_obj->moveinfo.state == PSTATE_TOP
4411 			/*|| (zc->waitin_obj->moveinfo.state == PSTATE_DOWN)*/)
4412 		{
4413 //gi.bprintf(PRINT_HIGH,"release %i %i\n",trace_priority,zc->waitin_obj->moveinfo.state);
4414 			zc->zcstate &= ~STS_WAITS;
4415 			zc->waitin_obj = NULL;
4416 		}
4417 		else if(zc->waitin_obj->moveinfo.state == PSTATE_BOTTOM
4418 			|| zc->waitin_obj->moveinfo.state == PSTATE_UP)
4419 		{
4420 			VectorSubtract(zc->movtarget_pt,ent->s.origin,temppos);
4421 			temppos[2] = 0;
4422 			x = VectorLength(temppos);
4423 			dist *= 0.25;
4424 			if(x < 10 || VectorCompare(ent->s.origin,zc->movtarget_pt))
4425 			{
4426 //				if(abs(zc->waitin_obj->s.origin[2] - zc->waitin_obj->s.old_origin[2]) == 0) goto VCHCANSEL;
4427 
4428 				if(!zc->waitin_obj->union_ent)
4429 				{
4430 					trmin[0] = (zc->waitin_obj->absmin[0] + zc->waitin_obj->absmax[0]) / 2;
4431 					trmin[1] = (zc->waitin_obj->absmin[1] + zc->waitin_obj->absmax[1]) / 2;
4432 					trmin[2] = (zc->waitin_obj->absmin[2] + zc->waitin_obj->absmax[2]) / 2;
4433 				}
4434 				else VectorCopy(zc->waitin_obj->union_ent->s.origin,trmin);
4435 				trmin[2] += 8;
4436 				VectorSubtract(trmin,ent->s.origin,temppos);
4437 				if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);
4438 				if(trace_priority < TRP_ANGLEKEEP)
4439 				{
4440 					ent->s.angles[YAW] = zc->moveyaw;
4441 					ent->s.angles[PITCH] = Get_pitch(temppos);
4442 				}
4443 				goto VCHCANSEL;
4444 			}
4445 			else
4446 			{
4447 				if(trace_priority < TRP_MOVEKEEP) zc->moveyaw = Get_yaw(temppos);
4448 				if(!zc->waitin_obj->union_ent)
4449 				{
4450 					trmin[0] = (zc->waitin_obj->absmin[0] + zc->waitin_obj->absmax[0]) / 2;
4451 					trmin[1] = (zc->waitin_obj->absmin[1] + zc->waitin_obj->absmax[1]) / 2;
4452 					trmin[2] = (zc->waitin_obj->absmin[2] + zc->waitin_obj->absmax[2]) / 2;
4453 				}
4454 				else VectorCopy(zc->waitin_obj->union_ent->s.origin,trmin);
4455 
4456 				trmin[2] += 8;
4457 				VectorSubtract(trmin,ent->s.origin,temppos);
4458 				if(trace_priority < TRP_ANGLEKEEP)
4459 				{
4460 					ent->s.angles[YAW] = Get_yaw(temppos);
4461 					ent->s.angles[PITCH] = Get_pitch(temppos);
4462 				}
4463 			}
4464 		}
4465 	}
4466 
4467 //LADDER
4468 
4469 
4470 	//--------------------------------------------------------------------------------------
4471 	//ladder check
4472 /*	front = NULL, left = NULL, right = NULL;
4473 	k = false;
4474 	if(zc->route_trace)
4475 	{
4476 		Get_RouteOrigin(zc->routeindex,v);
4477 		if((v[2] - ent->s.origin[2]) >= 32) k = true;
4478 
4479 	}
4480 	if(k && !zc->first_target && !zc->second_target && !(ent->client->ps.pmove.pm_flags & PMF_DUCKED))
4481 	{
4482 		tempflag = false;
4483 
4484 		VectorCopy(ent->mins,trmin);
4485 		VectorCopy(ent->maxs,trmax);
4486 
4487 		trmin[2] += 20;
4488 
4489 		//front
4490 		f1 = 32;
4491 		if(zc->route_trace) f1 = 32;
4492 
4493 		iyaw = zc->moveyaw;
4494 		yaw = iyaw * M_PI * 2 / 360;
4495 		touchmin[0] = cos(yaw) * f1;//28 ;
4496 		touchmin[1] = sin(yaw) * f1;
4497 		touchmin[2] = 0;
4498 
4499 		VectorAdd(ent->s.origin,touchmin,touchmax);
4500 		rs_trace = gi.trace (ent->s.origin, trmin,ent->maxs, touchmax,ent, MASK_BOTSOLID );
4501 		front = rs_trace.ent;
4502 
4503 		if(rs_trace.contents & CONTENTS_LADDER) tempflag = true;
4504 
4505 		//right
4506 		if(!tempflag)
4507 		{
4508 			iyaw = zc->moveyaw + 90;
4509 			if(iyaw > 180) iyaw -= 360;
4510 			yaw = iyaw * M_PI * 2 / 360;
4511 			touchmin[0] = cos(yaw) * 32 ;
4512 			touchmin[1] = sin(yaw) * 32 ;
4513 			touchmin[2] = 0;
4514 
4515 			VectorAdd(ent->s.origin,touchmin,touchmax);
4516 			rs_trace = gi.trace (ent->s.origin, trmin,ent->maxs, touchmax,ent,  MASK_BOTSOLID );
4517 			right = rs_trace.ent;
4518 
4519 			if(rs_trace.contents & CONTENTS_LADDER) tempflag = true;
4520 		}
4521 		//left
4522 		if(!tempflag)
4523 		{
4524 			iyaw = zc->moveyaw - 90;
4525 			if(iyaw < -180) iyaw += 360;
4526 			yaw = iyaw * M_PI * 2 / 360;
4527 			touchmin[0] = cos(yaw) * 32 ;
4528 			touchmin[1] = sin(yaw) * 32 ;
4529 			touchmin[2] = 0;
4530 
4531 			VectorAdd(ent->s.origin,touchmin,touchmax);
4532 			rs_trace = gi.trace (ent->s.origin, trmin,ent->maxs, touchmax,ent, MASK_BOTSOLID );
4533 			left = rs_trace.ent;
4534 
4535 			if(rs_trace.contents & CONTENTS_LADDER)	tempflag = true;
4536 		}
4537 
4538 		//ladder
4539 		if(tempflag)
4540 		{
4541 			VectorCopy(rs_trace.endpos,trmax);
4542 			VectorCopy(trmax,touchmax);
4543 			touchmax[2] += 8190;
4544 			rs_trace = gi.trace (temppos, trmin,ent->maxs, touchmax,ent, MASK_BOTSOLID );
4545 
4546 			VectorCopy(rs_trace.endpos,temppos);
4547 			VectorAdd(rs_trace.endpos,touchmin,touchmax);
4548 			rs_trace = gi.trace (temppos, trmin,ent->maxs, touchmax,ent, MASK_BOTSOLID);
4549 
4550 			if(!(rs_trace.contents & CONTENTS_LADDER) && rs_trace.fraction)
4551 			{
4552 //	gi.WriteByte (svc_temp_entity);
4553 //	gi.WriteByte (TE_RAILTRAIL);
4554 //	gi.WritePosition (ent->s.origin);
4555 //	gi.WritePosition (temppos);
4556 //	gi.multicast (ent->s.origin, MULTICAST_PHS);
4557 
4558 				ent->velocity[0] = 0;
4559 				ent->velocity[1] = 0;
4560 				if(zc->moveyaw == iyaw)
4561 				{
4562 gi.bprintf(PRINT_HIGH,"ladder On!\n");
4563 					ent->s.angles[YAW] = zc->moveyaw;
4564 					VectorCopy(trmax,ent->s.origin);
4565 					zc->zcstate |= STS_LADDERUP;
4566 					ent->s.angles[YAW] = zc->moveyaw;
4567 					ent->s.angles[PITCH] = -29;
4568 
4569 					if(ent->waterlevel > 1)
4570 					{
4571 						ent->velocity[2] = VEL_BOT_WLADRUP;
4572 //				if(VectorCompare(ent->s.origin,ent->s.old_origin)) ent->velocity[2] += 50;
4573 					}
4574 					else
4575 					{
4576 						ent->velocity[2] = VEL_BOT_LADRUP;
4577 //			if(VectorCompare(ent->s.origin,ent->s.old_origin)) ent->velocity[2] += 50;
4578 					}
4579 //					gi.bprintf(PRINT_HIGH,"ladder!!\n");
4580 					goto VCHCANSEL;
4581 				}
4582 				else
4583 				{
4584 					zc->moveyaw = iyaw;
4585 					ent->s.angles[YAW] = zc->moveyaw;
4586 				}
4587 				goto VCHCANSEL;
4588 			}
4589 		}
4590 	}
4591 
4592 */
4593 	//--------------------------------------------------------------------------------------
4594 	//rocket jump
4595 	//	ent->client->weaponstate = WEAPON_READY;
4596 	if (ent->groundentity && ent->client->weaponstate == WEAPON_READY && zc->second_target
4597 		&& trace_priority < TRP_ANGLEKEEP)
4598 	{
4599 		if((zc->second_target->s.origin[2] - ent->s.origin[2]) > 100
4600 			&& ent->health > 70	&& ent->waterlevel <=1 )
4601 		{
4602 			j = false;
4603 			v[0] = ent->s.origin[0];
4604 			v[1] = ent->s.origin[1];
4605 			v[2] = zc->second_target->s.origin[2];
4606 			rs_trace = gi.trace(v,NULL,NULL,zc->second_target->s.origin,zc->second_target,MASK_SOLID);
4607 			if(rs_trace.fraction == 1.0) j = true;
4608 
4609 			VectorSubtract (zc->second_target->s.origin,ent->s.origin,trmin);
4610 			VectorCopy(trmin,trmax);
4611 			trmax[2] = 0;
4612 			it = Fdi_ROCKETLAUNCHER;//FindItem("Rocket Launcher");
4613 			i = ITEM_INDEX(Fdi_ROCKETS/*FindItem("Rockets")*/);
4614 
4615 //ent->client->pers.inventory[ITEM_INDEX(it)] = 1;
4616 //ent->client->pers.inventory[ent->client->ammo_index] = 1;
4617 			if(	VectorLength(trmax) < 280 && canrocj && j)
4618 			{
4619 				VectorNormalize (trmin);
4620 				ent->s.angles[YAW] = Get_yaw (trmin);
4621 				zc->moveyaw = ent->s.angles[YAW];
4622 				ent->s.angles[PITCH] = 90;
4623 				trmin[2] -= 24;
4624 				VectorNormalize (trmin);
4625 //				it->use(ent,it);
4626 				ent->client->pers.weapon = it;
4627 				ent->client->ammo_index = i;
4628 				ShowGun(ent);
4629 
4630 				ent->velocity[2] += VEL_BOT_JUMP;
4631 				zc->zcstate |= STS_ROCJ;
4632 				gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
4633 				PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
4634 				Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
4635 				ent->client->buttons |= BUTTON_ATTACK;
4636 				goto VCHCANSEL;		//�ړ������L�����Z��
4637 			}
4638 			else zc->second_target = NULL;
4639 		}
4640 		else if((zc->second_target->s.origin[2] - ent->s.origin[2]) > 100)
4641 		{
4642 			if(ent->health <= 70 ) zc->second_target = NULL;
4643 		}
4644 	}
4645 
4646 	//--------------------------------------------------------------------------------------
4647 	//bot move to moveyaw
4648 GOMOVE:
4649 	//jumping	======================================================
4650 	if(!ent->groundentity && !ent->waterlevel && !ent->client->zc.trapped)
4651 	{
4652 		if(ent->velocity[2] > VEL_BOT_JUMP && !(zc->zcstate & STS_SJMASKEXW)) ent->velocity[2] = VEL_BOT_JUMP;
4653 
4654 		k = false;
4655 		if(ent->client->ps.pmove.pm_flags & PMF_DUCKED) k = true;
4656 		for( x = 0 ; x < 90; x += 10)
4657 		{
4658 			dist = MOVE_SPD_RUN * ent->moveinfo.speed;
4659 			//right trace
4660 			yaw = zc->moveyaw + x;
4661 			if(yaw > 180) yaw -= 360;
4662 			i = Bot_moveT(ent,yaw,temppos,dist,&bottom);
4663 			if(i)// true || (i == 2 && ent->velocity > 0))
4664 			{
4665 				if(bottom <= 24 && bottom > 0 && ent->velocity[2] <= 10 /*&& i == true*/)
4666 				{
4667 					//if(ent->velocity[2] > 0 || bottom >= 0)
4668 							VectorCopy(temppos,ent->s.origin);
4669 					break;
4670 				}
4671 				//turbo
4672 				if(!ent->waterlevel && ent->s.origin[2] > ent->s.old_origin[2]
4673 					&& zc->route_trace
4674 					&& !(zc->zcstate & STS_LADDERUP)
4675 					&& !(zc->zcstate & STS_SJMASK)
4676 					&& (zc->routeindex + 1) < CurrentIndex
4677 					&& ent->velocity[2] >= 100
4678 					&& ent->velocity[2] < (100 + ent->gravity * sv_gravity->value * FRAMETIME))
4679 				{
4680 					Get_RouteOrigin(zc->routeindex ,v);
4681 					Get_RouteOrigin(zc->routeindex + 1,vv);
4682 					k = 0;
4683 
4684 					j = Bot_moveT(ent,yaw,trmin,16,&f1);
4685 					VectorSubtract(v,ent->s.origin,trmin);
4686 					if((vv[2] - v[2]) > JumpMax) k = 1;
4687 					else if((v[2] - ent->s.origin[2]) > JumpMax) k = 2;
4688 					else if(!TargetJump_Chk(ent,vv,0) && VectorLength(trmin) < 64)
4689 					{
4690 //gi.bprintf(PRINT_HIGH,"dist %f!!\n",VectorLength(trmin));
4691 						if(TargetJump_Chk(ent,vv,ent->velocity[2])) k = 1;
4692 					}
4693 
4694 
4695 					if(!j) k = 0;
4696 					else if( f1 > 10 && f1 < -10) k = 0;
4697 					if(k)
4698 					{
4699 						if(k == 2) VectorCopy(v,vv);
4700 						if(TargetJump_Turbo(ent,vv))
4701 						{
4702 //gi.bprintf(PRINT_HIGH,"speed %f!!\n",ent->moveinfo.speed);
4703 //if(ent->velocity[2] > (VEL_BOT_JUMP + 100 + ent->gravity * sv_gravity->value * FRAMETIME ))
4704 //	ent->velocity[2] = VEL_BOT_JUMP + 100 + ent->gravity * sv_gravity->value * FRAMETIME;
4705 							VectorSubtract(vv,ent->s.origin,v);
4706 							zc->moveyaw = Get_yaw(v);
4707 							if(ent->velocity[2] > VEL_BOT_JUMP) zc->zcstate |= STS_TURBOJ;
4708 							if(k == 1) zc->routeindex++;
4709 							break;
4710 						}
4711 					}
4712 				}
4713 //				bottom > 0else ent->moveinfo.speed = 0.2;
4714 				if(bottom <= 0)
4715 				{
4716 					VectorCopy(temppos,ent->s.origin);
4717 					if(i == 2 /*&& k*/) ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
4718 					else ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
4719 					break;
4720 				}
4721 				else
4722 				{
4723 					ent->moveinfo.speed = 0.3;//0.2;
4724 				}
4725 			}
4726 			else
4727 			{
4728 				ent->moveinfo.speed = 0.3;//0.2;
4729 			}
4730 
4731 			if(x == 0) continue;
4732 			//left trace
4733 			yaw = zc->moveyaw - x;
4734 			if(yaw < -180) yaw += 360;
4735 			i = Bot_moveT(ent,yaw,temppos,dist,&bottom);
4736 			if(i )//== true || (i == 2 && ent->velocity > 0))
4737 			{
4738 				if(bottom <= 24 && bottom >0  && ent->velocity[2] <= 10 /*&& i == true*/)
4739 				{
4740 					//if(ent->velocity[2] > 0 || bottom >= 0)
4741 							VectorCopy(temppos,ent->s.origin);
4742 					break;
4743 				}
4744 				//turbo
4745 				if(!ent->waterlevel && ent->s.origin[2] > ent->s.old_origin[2]
4746 					&& zc->route_trace
4747 					&& !(zc->zcstate & STS_LADDERUP)
4748 					&& !(zc->zcstate & STS_SJMASK)
4749 					&& (zc->routeindex + 1) < CurrentIndex
4750 					&& ent->velocity[2] >= 100
4751 					&& ent->velocity[2] < (100 + ent->gravity * sv_gravity->value * FRAMETIME))
4752 				{
4753 					Get_RouteOrigin(zc->routeindex ,v);
4754 					Get_RouteOrigin(zc->routeindex + 1,vv);
4755 					k = 0;
4756 
4757 					j = Bot_moveT(ent,yaw,trmin,16,&f1);
4758 					VectorSubtract(v,ent->s.origin,trmin);
4759 					if((vv[2] - v[2]) > JumpMax) k = 1;
4760 					else if((v[2] - ent->s.origin[2]) > JumpMax) k = 2;
4761 					else if(!TargetJump_Chk(ent,vv,0) && VectorLength(trmin) < 64)
4762 					{
4763 //gi.bprintf(PRINT_HIGH,"dist %f!!\n",VectorLength(trmin));
4764 						if(TargetJump_Chk(ent,vv,ent->velocity[2])) k = 1;
4765 					}
4766 
4767 					if(!j) k = 0;
4768 					else if( f1 > 10 && f1 < -10) k = 0;
4769 					if(k )
4770 					{
4771 						if(k == 2) VectorCopy(v,vv);
4772 						if(TargetJump_Turbo(ent,vv))
4773 						{
4774 //gi.bprintf(PRINT_HIGH,"speed %f!!\n",ent->moveinfo.speed);
4775 //if(ent->velocity[2] > (VEL_BOT_JUMP + 100 + ent->gravity * sv_gravity->value * FRAMETIME ))
4776 //	ent->velocity[2] = VEL_BOT_JUMP + 100 + ent->gravity * sv_gravity->value * FRAMETIME;
4777 //if(ent->moveinfo.speed < 0.5) ent->moveinfo.speed = 0.5;
4778 							VectorSubtract(vv,ent->s.origin,v);
4779 							zc->moveyaw = Get_yaw(v);
4780 							if(ent->velocity[2] > VEL_BOT_JUMP) zc->zcstate |= STS_TURBOJ;
4781 							if(k == 1) zc->routeindex++;
4782 							break;
4783 						}
4784 					}
4785 				}
4786 //				else ent->moveinfo.speed = 0.2;
4787 				if(bottom <= 0)
4788 				{
4789 					VectorCopy(temppos,ent->s.origin);
4790 					if(i == 2 /*&& k*/) ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
4791 					else ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
4792 					break;
4793 				}
4794 				else ent->moveinfo.speed = 0.3;//0.2;
4795 			}
4796 			else ent->moveinfo.speed = 0.3;//0.2;
4797 		}
4798 		if(x >= 90 /*&& ent->velocity[2] < 0*/)
4799 		{
4800 //gi.bprintf(PRINT_HIGH,"jump fail!\n");
4801 			if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] += ((random() - 0.5) * 360);
4802 			if(ent->s.angles[YAW]>180) ent->s.angles[YAW] -= 360;
4803 			else if(ent->s.angles[YAW]< -180) ent->s.angles[YAW] += 360;
4804 		}
4805 		goto VCHCANSEL;
4806 	}
4807 
4808 	// on ground or in water ======================================================
4809 	waterjumped = false;
4810 	if(ent->groundentity || ent->waterlevel )
4811 	{
4812 		if(ent->groundentity && /*zc->waterstate == WAS_NONE*/ent->waterlevel <= 0 ) k = 1;
4813 		else if(ent->waterlevel)
4814 		{
4815 			k = 2;
4816 			if(zc->route_trace)
4817 			{
4818 				Get_RouteOrigin(zc->routeindex,v);
4819 				VectorSubtract(v,ent->s.origin,vv);
4820 				vv[2] = 0;
4821 				if(v[2] < ent->s.origin[2] && VectorLength(vv) < 24) k = 0;
4822 			}
4823 			if(ent->waterlevel == 3) k = 0;
4824 		}
4825 		else if(ent->waterlevel) k = 0;
4826 		else k = 1;
4827 		if(k) if(ent->client->ps.pmove.pm_flags & PMF_DUCKED) k = 0;
4828 
4829 		if(zc->waterstate) f1 = BOTTOM_LIMIT_WATER;
4830 		else f1 = - JumpMax;//BOTTOM_LIMIT;//dropable height
4831 
4832 		if(zc->nextcheck < (level.time + FRAMETIME * 10))
4833 		{
4834 			VectorSubtract(zc->pold_origin,ent->s.origin,temppos);
4835 			if(VectorLength(temppos) < 64)
4836 			{
4837 				if(zc->route_trace)
4838 				{
4839 					if(!chedit->value)
4840 					{
4841 						zc->route_trace = false;
4842 						zc->routeindex++;
4843 					}
4844 					zc->second_target = NULL;
4845 				}
4846 				else f1 = BOTTOM_LIMITM;
4847 			}
4848 
4849 			if(zc->nextcheck < level.time)
4850 			{
4851 				VectorCopy(ent->s.origin,zc->pold_origin);
4852 				zc->nextcheck = level.time + FRAMETIME * 40;
4853 			}
4854 		}
4855 		f3 = 20;	//movablegap
4856 		//this v not modify till do special
4857 		if(zc->route_trace) Get_RouteOrigin(zc->routeindex,v);
4858 
4859 		if(ent->waterlevel && zc->route_trace)
4860 		{
4861 			if(v[2] + 20 <= ent->s.origin[2])
4862 			{
4863 				f2 = 20,f3 = 0;
4864 			}
4865 			else
4866 			{
4867 				if(zc->waterstate /*== WAS_FLOAT*/) f2 = JumpMax;//TOP_LIMIT_WATER;
4868 				else f2 = JumpMax;
4869 			}
4870 		}
4871 		else
4872 		{
4873 			if(zc->waterstate /*== WAS_FLOAT*/) f2 = JumpMax;//TOP_LIMIT_WATER;
4874 			else f2 = JumpMax;
4875 		}
4876 
4877 //if(ent->client->ps.pmove.pm_flags & PMF_DUCKED) gi.bprintf(PRINT_HIGH,"cycle!\n");
4878 		ladderdrop = true;
4879 		for( x = 0 ; x <= 180 && dist != 0; x += 10)
4880 		{
4881 			//right trace
4882 			yaw = zc->moveyaw + x;
4883 			if(yaw > 180) yaw -= 360;
4884 			if(j = Bot_moveT (ent,yaw,temppos,dist,&bottom))
4885 			{
4886 				//special
4887 				if(x == 0 && /*bottom < 20 &&*/ !ent->waterlevel
4888 					&& !(ent->client->ps.pmove.pm_flags & PMF_DUCKED))
4889 				{
4890 					if( zc->second_target)
4891 					{
4892 						if(((zc->second_target->s.origin[2] + 8 ) - (ent->s.origin[2] + bottom)) > f2)
4893 						{
4894 							if(Bot_Fall(ent,temppos,dist))
4895 							{
4896 								ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
4897 								break;
4898 							}
4899 						}
4900 					}
4901 					else if( zc->route_trace)
4902 					{
4903 //						Get_RouteOrigin(zc->routeindex,v);
4904 //						FRAMETIME * (ent->velocity[2] - ent->gravity * sv_gravity->value * FRAMETIME)
4905 						if((v[2] - (ent->s.origin[2] + bottom )) > f2 ||
4906 							(bottom > 20 && v[2] > ent->s.origin[2]))
4907 						{
4908 							ladderdrop = false;
4909 							if(Bot_Fall(ent,temppos,dist) && !zc->waterstate)
4910 							{
4911 								ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
4912 								break;
4913 							}
4914 							if((v[2] - ent->s.origin[2]) <= JumpMax)
4915 							{
4916 								if(Route[zc->routeindex].state == GRS_ONTRAIN && zc->waterstate < WAS_IN) break;
4917 								if(zc->routeindex > 0)
4918 									if(Route[zc->routeindex - 1].state == GRS_ONTRAIN
4919 										&& Route[zc->routeindex - 1].ent == ent->groundentity) break;
4920 							}
4921 						}
4922 						else if(ent->groundentity)
4923 						{
4924 //if(Q_stricmp (ent->groundentity->classname,"worldspawn"))
4925 //gi.bprintf(PRINT_HIGH,"%s!\n",ent->groundentity->classname);
4926 							if(!Q_stricmp (ent->groundentity->classname,"func_rotating"))
4927 							{
4928 								if(Bot_Fall(ent,temppos,dist))
4929 								{
4930 									ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
4931 									break;
4932 								}
4933 							}
4934 							else if(Route[zc->routeindex].state == GRS_ONROTATE)
4935 							{
4936 								if(!TraceX(ent,v) || !HazardCheck(ent,v)) break;
4937 								if(!BankCheck(ent,v)) break;
4938 								if(Bot_Fall(ent,temppos,dist))
4939 								{
4940 									ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
4941 									break;
4942 								}
4943 							}
4944 							if(0/*dist < 16 && v[2] < (ent->s.origin[2] - 24)
4945 								&& !(zc->zcstate & STS_WAITSMASK) && ent->waterlevel*/)
4946 							{
4947 								if(Bot_moveT (ent,yaw,trmin,32,&iyaw))
4948 								{
4949 									if(iyaw < 0)
4950 									{
4951 										ent->moveinfo.speed = 0.05;
4952 										VectorCopy(trmin,ent->s.origin);
4953 										break;
4954 									}
4955 								}
4956 							}
4957 						}
4958 					}
4959 				}
4960 
4961 				//jumpable1
4962 				if(/*((bottom > 20 && !ent->waterlevel) || (bottom > 0 && (ent->waterlevel == 2 || (ent->waterlevel == 1 && ent->groundentity == NULL))))*/
4963 					bottom > 20
4964 					&& bottom <= f2 && j == true && k
4965 					&& !(ent->client->ps.pmove.pm_flags & PMF_DUCKED))
4966 				{
4967 					ent->moveinfo.speed = 0.15;
4968 					if(k == 1/*!ent->waterlevel*/)
4969 					{
4970 						ent->velocity[2] += VEL_BOT_JUMP;
4971 						gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
4972 						PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
4973 					}
4974 					else
4975 					{
4976 						ent->moveinfo.speed = 0.1;
4977 						//waterjumped = true;
4978 						if(ent->velocity[2] < VEL_BOT_WJUMP/*=1*/ || VectorCompare(ent->s.origin,ent->s.old_origin))
4979 						{
4980 							ent->velocity[2] /*+*/= VEL_BOT_WJUMP;//(/*VEL_BOT_WJUMP*/ 110 /*+ bottom*/);
4981 							zc->zcstate |= STS_WATERJ;
4982 							goto VCHCANSEL;
4983 						}
4984 						goto VCHCANSEL;
4985 					}
4986 					Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
4987 					zc->moveyaw = yaw;
4988 					ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
4989 					break;
4990 				}
4991 				//dropable1
4992 				else if(bottom <= f3 &&(bottom >= f1 || /*zc->waterstate*/ent->waterlevel /* 2*/))
4993 				{
4994 //					ent->client->anim_priority = ANIM_BASIC;
4995 					if(bottom < 0 && !zc->waterstate/*(ent->waterlevel && !zc->waterstate/*ent->waterlevel < 2)*/)
4996 					{
4997 						f2 = FRAMETIME * (ent->velocity[2] - ent->gravity * sv_gravity->value * FRAMETIME);
4998 						if(bottom >= f2 && ent->velocity[2] < 0/*20*/) temppos[2] += bottom;
4999 						else temppos[2] += f2;//20;
5000 					}
5001 					VectorCopy(temppos,ent->s.origin);
5002 					if(f1 > BOTTOM_LIMIT) ent->moveinfo.speed = 0.25;
5003 					if(j != true)
5004 					{
5005 //gi.bprintf(PRINT_HIGH,"ducked1!!\n");
5006 						ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
5007 					}
5008 					else ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
5009 
5010 					if(x > 30 || !zc->route_trace)
5011 					{
5012 						f2 = zc->moveyaw;
5013 						zc->moveyaw = yaw;
5014 						if(f2 == ent->s.angles[YAW] && trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = yaw;
5015 					}
5016 					break;
5017 				}
5018 				//dropable?1
5019 				else if ( bottom < f1 && !zc->waterstate/*!ent->waterlevel*/ && x <= 30)
5020 				{
5021 					if( ladderdrop &&  zc->ground_contents & CONTENTS_LADDER && bottom != -9999)
5022 					{
5023 						VectorCopy(temppos,ent->s.origin);
5024 						zc->moveyaw = yaw;
5025 						ent->moveinfo.speed = 0.2;
5026 						goto VCHCANSEL;
5027 					}
5028 
5029 					if( ladderdrop &&  bottom < 0 && !zc->waterstate/*!ent->waterlevel*/)
5030 					{
5031 						if(Bot_moveW ( ent,yaw,temppos,dist,&bottom))
5032 						{
5033 							if(zc->second_target) iyaw = zc->second_target->s.origin[2] - ent->s.origin[2];
5034 							else iyaw = -41;
5035 							if(bottom > -20 && iyaw < -40)
5036 							{
5037 								VectorCopy(temppos,ent->s.origin);
5038 								break;
5039 							}
5040 						}
5041 					}
5042 					//fall1
5043 					if(Bot_Fall(ent,temppos,dist))
5044 					{
5045 //						ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
5046 //gi.bprintf(PRINT_HIGH,"drop!\n");
5047 						break;
5048 					}
5049 				}
5050 			}
5051 //else if(ent->client->zc.waterstate == 1 && x == 0) gi.bprintf(PRINT_HIGH,"maaaap %i\n",j);
5052 
5053 			if(x == 0 && (zc->battlemode & FIRE_SHIFT)) zc->battlemode &= ~FIRE_SHIFT;
5054 			if(x == 0 || x == 180) continue;
5055 			//left trace
5056 			yaw = zc->moveyaw - x;
5057 			if(yaw < -180) yaw += 360;
5058 			if(j = Bot_moveT (ent,yaw,temppos,dist,&bottom))
5059 			{
5060 				if(zc->waterstate == WAS_FLOAT) f2 = TOP_LIMIT_WATER;
5061 				else f2 = JumpMax;
5062 				//jumpable2
5063 				if(/*((bottom > 20 && !ent->waterlevel) || (bottom > 0 && (ent->waterlevel == 2 || (ent->waterlevel == 1 && ent->groundentity == NULL))) )*/
5064 					bottom > 20
5065 					&& bottom <= f2 && j == true && k
5066 					&& !(ent->client->ps.pmove.pm_flags & PMF_DUCKED))
5067 				{
5068 					ent->moveinfo.speed = 0.15;
5069 					if(k == 1/*!ent->waterlevel*/)
5070 					{
5071 						ent->velocity[2] += VEL_BOT_JUMP;
5072 						gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
5073 						PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
5074 					}
5075 					else
5076 					{
5077 						ent->moveinfo.speed = 0.1;
5078 						//waterjumped = true;
5079 						if(ent->velocity[2] < VEL_BOT_WJUMP/*= 1*/ || VectorCompare(ent->s.origin,ent->s.old_origin))
5080 						{
5081 							ent->velocity[2] /*+*/= VEL_BOT_WJUMP;//(/*VEL_BOT_WJUMP*/ 110 /*+ bottom*/);
5082 							zc->zcstate |= STS_WATERJ;
5083 							goto VCHCANSEL;
5084 						}
5085 						goto VCHCANSEL;
5086 					}
5087 					Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
5088 					zc->moveyaw = yaw;
5089 					ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
5090 					break;
5091 				}
5092 				//dropable2
5093 				else if(bottom <= f3 && (bottom >= f1 || ent->waterlevel /* 2zc->waterstate*/))
5094 				{
5095 					//ent->client->anim_priority = ANIM_BASIC;
5096 					if(bottom < 0 && !zc->waterstate/*(ent->waterlevel && !zc->waterstate/*ent->waterlevel < 2)*/)
5097 					{
5098 //gi.bprintf(PRINT_HIGH,"ponko\n");
5099 						f2 = FRAMETIME * (ent->velocity[2] - ent->gravity * sv_gravity->value * FRAMETIME);
5100 						if(bottom >= f2 && ent->velocity[2] < 0/*20*/) temppos[2] += bottom;
5101 						else temppos[2] += f2;//20;
5102 					}
5103 					VectorCopy(temppos,ent->s.origin);
5104 					if(f1 > BOTTOM_LIMIT) ent->moveinfo.speed = 0.25;
5105 					if(j != true)
5106 					{
5107 //gi.bprintf(PRINT_HIGH,"ducked2!!\n");
5108 						ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
5109 					}
5110 					else ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
5111 
5112 					if(x > 30 || !zc->route_trace)
5113 					{
5114 						f2 = zc->moveyaw;
5115 						zc->moveyaw = yaw;
5116 						if(f2 == ent->s.angles[YAW]  && trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = yaw;
5117 					}
5118 					break;
5119 				}
5120 				//dropable?2
5121 				else if (bottom < f1 && !zc->waterstate/*!ent->waterlevel*/ && x <= 30)
5122 				{
5123 					if( ladderdrop && zc->ground_contents & CONTENTS_LADDER  && bottom != -9999)
5124 					{
5125 						VectorCopy(temppos,ent->s.origin);
5126 						zc->moveyaw = yaw;
5127 						ent->moveinfo.speed = 0.2;
5128 						goto VCHCANSEL;
5129 					}
5130 
5131 					if( ladderdrop && bottom < 0 && !zc->waterstate/*!ent->waterlevel*/)
5132 					{
5133 						if(Bot_moveW ( ent,yaw,temppos,dist,&bottom))
5134 						{
5135 							if(zc->second_target) iyaw = zc->second_target->s.origin[2] - ent->s.origin[2];
5136 							else iyaw = -41;
5137 							if(bottom > -54 && iyaw < -40)
5138 							{
5139 								VectorCopy(temppos,ent->s.origin);
5140 								break;
5141 							}
5142 						}
5143 					}
5144 
5145 					//fall2
5146 					if(Bot_Fall(ent,temppos,dist))
5147 					{
5148 //						ent->client->ps.pmove.pm_flags &= ~PMF_DUCKED;
5149 						break;
5150 					}
5151 				}
5152 			}
5153 		}
5154 
5155 		if(!zc->route_trace && zc->first_target == NULL)
5156 		{
5157 			if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = yaw;
5158 		}
5159 
5160 		if(x >= 70)
5161 		{
5162 			if(zc->second_target) zc->second_target = NULL;
5163 /*			else if(!zc->route_trace && zc->first_target == NULL)
5164 			{
5165 				if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = yaw;
5166 			}*/
5167 			else if( 0/*zc->route_trace*/)
5168 			{
5169 //gi.bprintf(PRINT_HIGH,"OFF 9\n"); //ppx
5170 				k = false;
5171 				if(  x > 90 && ent->groundentity)
5172 				{
5173 					if(!Q_stricmp (ent->groundentity->classname,"func_train")) k = true;
5174 				}
5175 				else if( x > 90 && Route[zc->routeindex].state == GRS_ONTRAIN) k = true;
5176 				if(k && trace_priority < TRP_ANGLEKEEP)
5177 				{
5178 					VectorCopy(Origin,ent->s.origin);
5179 					VectorCopy(Velocity,ent->velocity);
5180 					ent->s.angles[YAW] = OYaw;
5181 					goto VCHCANSEL;
5182 				}
5183 /*				if(!k)
5184 				{
5185 					if(++zc->routeindex >= CurrentIndex) zc->routeindex = 0;
5186 					zc->route_trace = false;
5187 				}*/
5188 			}
5189 		}
5190 
5191 		if(/*zc->waterstate*/ent->waterlevel && !waterjumped)
5192 		{
5193 			k = false;
5194 			VectorCopy(ent->s.origin,temppos);
5195 //			temppos[2] += 26;
5196 //			i = gi.pointcontents (temppos);
5197 			if(zc->second_target != NULL)
5198 			{
5199 				k = 2;
5200 				x = zc->second_target->s.origin[2] - ent->s.origin[2];
5201 				if(x > 13/*8*/) x = 13;//8;
5202 				else if(x < -13/*8*/) x = -13;//8;
5203 				if(x < 0)//�A�C�e������
5204 				{
5205 					if( Bot_Watermove (ent,temppos,dist,x))
5206 					{
5207 						VectorCopy(temppos,ent->s.origin);
5208 						k = true;
5209 					}
5210 				}
5211 				else if(x >0 && zc->waterstate == WAS_IN
5212 					&& !(ent->client->ps.pmove.pm_flags & PMF_DUCKED)) //�A�C�e�����
5213 				{
5214 					if(ent->velocity[2] < 0) ent->velocity[2] = 0;
5215 					if( Bot_Watermove (ent,temppos,dist,x))
5216 					{
5217 						VectorCopy(temppos,ent->s.origin);
5218 						k = true;
5219 					}
5220 				}
5221 			}
5222 			else if(zc->route_trace )
5223 			{
5224 				Get_RouteOrigin(zc->routeindex,v);
5225 
5226 				k = 2;
5227 				x = v[2] - ent->s.origin[2];
5228 				if(x > 13/*8*/) x = 13;//8;
5229 				else if(x < -13/*8*/) x = -13;//8;
5230 				if(x < 0)//�A�C�e������
5231 				{
5232 					if( Bot_Watermove (ent,temppos,dist,x))
5233 					{
5234 //gi.bprintf(PRINT_HIGH,"Down! %f\n",x);
5235 						VectorCopy(temppos,ent->s.origin);
5236 						k = true;
5237 					}
5238 				}
5239 				else if(x > 0 && zc->waterstate == WAS_IN
5240 					&& !(ent->client->ps.pmove.pm_flags & PMF_DUCKED)) //�A�C�e�����
5241 				{
5242 //gi.bprintf(PRINT_HIGH,"UP! %f\n",x);
5243 					if(ent->velocity[2] < -10) ent->velocity[2] = 0;
5244 					if( Bot_Watermove (ent,temppos,dist,x))
5245 					{
5246 						VectorCopy(temppos,ent->s.origin);
5247 						k = true;
5248 					}
5249 				}
5250 				else if(x == 0)
5251 				{
5252 //gi.bprintf(PRINT_HIGH,"ZERO! %f\n",x);
5253 //					VectorSubtract(v,ent->s.origin,vv);
5254 //					if(VectorLength(vv) < 13) VectorCopy(v,ent->s.origin);
5255 				}
5256 			}
5257 			else if((ent->air_finished - FRAMETIME * 20 ) < level.time
5258 				&& zc->waterstate == WAS_IN)
5259 			{
5260 				if( Bot_Watermove (ent,temppos,dist,13/*8*/))
5261 				{
5262 					VectorCopy(temppos,ent->s.origin);
5263 					k = true;
5264 				}
5265 				else k = 2;
5266 			}
5267 
5268 			if(k == true) Get_WaterState(ent);
5269 			if(zc->route_trace && v[2] == ent->s.origin[2]) k = 3;
5270 
5271 			if((!ent->groundentity && !zc->waterstate && k && ent->velocity[2] < 1)
5272 				||(zc->waterstate == WAS_IN && (ent->client->ps.pmove.pm_flags & PMF_DUCKED)))
5273 			{
5274 				if( Bot_Watermove (ent,temppos,dist,-7/*8*/) && k != 3)
5275 				{
5276 					VectorCopy(temppos,ent->s.origin);
5277 				}
5278 			}
5279 			if(zc->waterstate == WAS_IN)  ent->moveinfo.decel = level.time;
5280 			else if(!k)	//���ʂɂ����Ƃ����Ƃ�
5281 			{
5282 				if( ( level.time - ent->moveinfo.decel) > 4.0 && !zc->route_trace)
5283 				{
5284 					ent->velocity[2] = -200;
5285 					ent->moveinfo.decel = level.time;
5286 				}
5287 			}
5288 
5289 			if(ent->groundentity && ent->waterlevel == 1)
5290 			{
5291 				VectorSubtract(ent->s.origin,ent->s.old_origin,temppos);
5292 				if(!temppos[0] && !temppos[1] && !temppos[2]) ent->velocity[2] += 80;
5293 			}
5294 		}
5295 		//not in water
5296 		else if(zc->route_trace && !dist)
5297 		{
5298 			Get_RouteOrigin(zc->routeindex,v);
5299 			if(v[2] < (ent->s.origin[2] - 20))
5300 			{
5301 				if( Bot_Watermove (ent,temppos,dist,-20))
5302 				{
5303 					VectorCopy(temppos,ent->s.origin);
5304 				}
5305 			}
5306 		}
5307 
5308 	}
5309 	//sticking
5310 /*	if(VectorCompare(ent->s.origin,ent->s.old_origin) && ent->waterlevel)
5311 	{
5312 		ent->velocity[2] += 200;
5313 	}
5314 */
5315 	//--------------------------------------------------------------------------------------
5316 	//player check door and corner
5317 	if(!zc->route_trace && trace_priority && !zc->second_target && random() < 0.2)
5318 	{
5319 		VectorCopy(ent->s.origin,v);
5320 		VectorCopy(ent->mins,touchmin);
5321 		touchmin[2] += 16;
5322 		VectorCopy(ent->maxs,touchmax);
5323 		if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)	touchmax[2] = 0;
5324 		else v[2] += 20;
5325 
5326 		//right
5327 		if(random() < 0.5)
5328 		{
5329 			f1 = zc->moveyaw + 90;
5330 			if(f1 > 180) iyaw -= 360;
5331 			f2 = zc->moveyaw + 135;
5332 			if(f2 > 180) iyaw -= 360;
5333 		}
5334 		//left
5335 		else
5336 		{
5337 			f1 = zc->moveyaw - 90;
5338 			if(f1 < 180) iyaw += 360;
5339 			f2 = zc->moveyaw - 135;
5340 			if(f2 < 180) iyaw += 360;
5341 		}
5342 
5343 		yaw = f1 * M_PI * 2 / 360;
5344 		trmin[0] = cos(yaw) * 128 ;
5345 		trmin[1] = sin(yaw) * 128 ;
5346 		trmin[2] = 0;
5347 		VectorAdd(v,trmin,trmax);
5348 		rs_trace = gi.trace (v, NULL,NULL, trmax,ent, MASK_BOTSOLIDX/*MASK_PLAYERSOLID*/ );
5349 		x = rs_trace.fraction;
5350 
5351 		yaw = f2 * M_PI * 2 / 360;
5352 		trmin[0] = cos(yaw) * 128 ;
5353 		trmin[1] = sin(yaw) * 128 ;
5354 		trmin[2] = 0;
5355 		VectorAdd(v,trmin,trmax);
5356 		rs_trace = gi.trace (v, NULL/*touchmin*/,NULL/*touchmax*/, trmax,ent, MASK_BOTSOLIDX/*MASK_PLAYERSOLID*/ );
5357 
5358 		if( x > rs_trace.fraction && x > 0.5) zc->moveyaw = f1;
5359 	}
5360 
5361 
5362 	//--------------------------------------------------------------------------------------
5363 	//push button
5364 
5365 	it_ent = NULL;
5366 	k = 0;
5367 
5368 	VectorCopy (ent->absmin, touchmin);
5369 	VectorCopy (ent->absmax, touchmax);
5370 
5371 	touchmin[0] -= 48;//32;
5372 	touchmin[1] -= 48;//32;
5373 	touchmin[2] -= 5;
5374 	touchmax[0] += 48;//32;
5375 	touchmax[1] += 48;//32;
5376 	i = gi.BoxEdicts ( touchmin ,touchmax,touch,MAX_EDICTS,AREA_SOLID);
5377 
5378 	if(i)
5379 	{
5380 		for(j = i - 1;j >= 0;j--)
5381 		{
5382 			trent = touch[j];
5383 			if(trent->classname)
5384 			{
5385 				if(!Q_stricmp (trent->classname,"func_button"))
5386 				{
5387 					k = 1;
5388 					it_ent = trent;
5389 					break;
5390 				}
5391 				else if(!Q_stricmp (trent->classname,"func_door")
5392 					|| !Q_stricmp (trent->classname,"func_door_rotating"))
5393 				{
5394 					if(trent->targetname == NULL && !trent->takedamage && ent->groundentity != trent)
5395 					{
5396 						k = 2;
5397 						it_ent = trent;
5398 						break;
5399 					}
5400 				}
5401 			}
5402 		}
5403 	}
5404 	//when touch da button
5405 	if( it_ent != NULL && k == 1)
5406 	{
5407 		if(it_ent->use && it_ent->moveinfo.state == PSTATE_BOTTOM && !it_ent->health)
5408 		{
5409 			k = false;
5410 			if(zc->route_trace && zc->routeindex - 1 > 0)
5411 			{
5412 				k = true;
5413 				i = zc->routeindex;
5414 				if(Route[i].state == GRS_PUSHBUTTON) k = false;
5415 				else if(Route[--i].state == GRS_PUSHBUTTON) k = false;
5416 
5417 				if(!k && Route[i].ent == it_ent) zc->routeindex = i + 1;
5418 				else k = true;
5419 			}
5420 
5421 //			if(!k) buttonuse = true;//it_ent->use(it_ent,ent,it_ent/*ent*/);
5422 			if(!k && it_ent->target)
5423 			{
5424 				string = it_ent->target;
5425 				e = &g_edicts[(int)maxclients->value+1];
5426 				for ( i=maxclients->value+1 ; i<globals.num_edicts ; i++, e++)
5427 				{
5428 					if(!e->inuse || !e->targetname) continue;
5429 					if (Q_stricmp (string, e->targetname) == 0 )
5430 					{
5431 //gi.bprintf(PRINT_HIGH,"yea4  %i %s\n",e->moveinfo.state,e->classname);
5432 						if(e->classname[0] == 't')
5433 						{
5434 							if(!Q_stricmp (e->classname,"trigger_relay"))
5435 							{
5436 								if(e->target)
5437 								{
5438 									string = e->target;
5439 									e = &g_edicts[(int)maxclients->value];
5440 									i=maxclients->value;
5441 									continue;
5442 								}
5443 							}
5444 							else if(!Q_stricmp (e->classname,"target_laser")
5445 								|| !Q_stricmp (e->classname,"target_mal_laser"))
5446 							{
5447 								if(e->spawnflags & 1)
5448 								{
5449 									it_ent->use(it_ent,ent,it_ent);
5450 									break;
5451 								}
5452 							}
5453 						}
5454 						else if(e->classname[0] == 'f')
5455 						{
5456 							it_ent->use(it_ent,ent,it_ent/*ent*/);
5457 							if(!Q_stricmp (e->classname,"func_door")
5458 								|| !Q_stricmp ( e->classname,"func_door_rotating")
5459 								/*&& (e->moveinfo.state == 1 || e->moveinfo.state == 2)*/
5460 							)//	&& abs ((e->moveinfo.start_origin[2] - e->moveinfo.end_origin[2])) > 54 )
5461 							{
5462 								k = false;
5463 	//							return true;
5464 								if(!zc->route_trace /*|| zc->routeindex <= 0*/)
5465 								{
5466 									v[0] = (it_ent->absmin[0] + it_ent->absmax[0]) / 2;
5467 									v[1] = (it_ent->absmin[1] + it_ent->absmax[1]) / 2;
5468 									v[2] = (it_ent->absmin[2] + it_ent->absmax[2]) / 2;
5469 									VectorSubtract(it_ent->union_ent->s.origin,v,temppos);
5470 									VectorScale (temppos, 3, v);
5471 									VectorAdd(ent->s.origin,v,zc->movtarget_pt);
5472 								}
5473 								else
5474 								{
5475 									/*Get_RouteOrigin(zc->routeindex - 1,v);
5476 									VectorSubtract(v,ent->s.origin,temppos);
5477 									VectorScale (temppos, 3, v);
5478 									VectorCopy(ent->s.origin,temppos);
5479 									VectorAdd(ent->s.origin,v,zc->movtarget_pt);*/
5480 									VectorCopy(ent->s.origin,zc->movtarget_pt);
5481 								}
5482 								//VectorScale (temppos, 3, v);
5483 								//VectorAdd(ent->s.origin,v,zc->movtarget_pt);
5484 
5485 								if(fabs (e->moveinfo.start_origin[2] - e->moveinfo.end_origin[2]) > JumpMax )
5486 								{
5487 									if(e->union_ent == NULL)
5488 									{
5489 //gi.bprintf(PRINT_HIGH,"voodoo\n"); //ppx
5490 										it = FindItem("Roam Navi3");
5491 										trent = G_Spawn();
5492 										trent->classname = it->classname;
5493 										trent->s.origin[0] = (e->absmin[0] + e->absmax[0])/2;
5494 										trent->s.origin[1] = (e->absmin[1] + e->absmax[1])/2;
5495 										trent->s.origin[2] = e->absmax[2] + 16;
5496 										trent->union_ent = e;
5497 										e->union_ent = trent;
5498 
5499 										//trent->nextthink = level.time + 10;
5500 										//trent->think = G_FreeEdict;
5501 
5502 										SpawnItem3 (trent, it);
5503 									}
5504 									else
5505 									{
5506 										trent = e->union_ent;
5507 										trent->solid = SOLID_TRIGGER;
5508 										trent->svflags &= ~SVF_NOCLIENT;
5509 //gi.bprintf(PRINT_HIGH,"SPAWNed\n"); //ppx
5510 									}
5511 //									SpawnItem2 (trent, it);
5512 
5513 									zc->second_target = trent;
5514 									trent->target_ent = ent;
5515 
5516 									//�g�O�����͂�������
5517 									if(e->spawnflags & PDOOR_TOGGLE)
5518 									{
5519 										f1 = e->moveinfo.start_origin[2] - e->moveinfo.end_origin[2];
5520 										//�X�^�[�g�n�_����
5521 										if(f1 > 0 )
5522 										{
5523 											k = true;
5524 											if(e->moveinfo.state == PSTATE_BOTTOM || e->moveinfo.state == PSTATE_UP )
5525 											{
5526 												if((trent->s.origin[2] - ent->s.origin[2]) > 32) zc->second_target = NULL;
5527 											}
5528 											else if(e->moveinfo.state == PSTATE_TOP || e->moveinfo.state == PSTATE_DOWN)
5529 											{
5530 												if((trent->s.origin[2] - ent->s.origin[2]) < -48) zc->second_target = NULL;
5531 											}
5532 										}
5533 										else
5534 										{
5535 											k = true;
5536 											if(e->moveinfo.state == PSTATE_TOP || e->moveinfo.state == PSTATE_DOWN)
5537 											{
5538 												if((trent->s.origin[2] - ent->s.origin[2]) > 32) zc->second_target = NULL;
5539 											}
5540 											else if(e->moveinfo.state == PSTATE_BOTTOM || e->moveinfo.state == PSTATE_UP)
5541 											{
5542 												if((trent->s.origin[2] - ent->s.origin[2]) < -48) zc->second_target = NULL;
5543 											}
5544 										}
5545 									}
5546 									//�m�[�}��
5547 									else
5548 									{
5549 										f1 = e->moveinfo.start_origin[2] - e->moveinfo.end_origin[2];
5550 										//�X�^�[�g�n�_����
5551 										if(f1 > 0 )
5552 										{
5553 											if(e->moveinfo.state == PSTATE_BOTTOM || e->moveinfo.state == PSTATE_UP)
5554 											{
5555 												if(fabs(trent->s.origin[2] - ent->s.origin[2]) < JumpMax) k = true;
5556 											}
5557 										}
5558 										else
5559 										{
5560 											if(e->moveinfo.state == PSTATE_BOTTOM || e->moveinfo.state == PSTATE_UP )
5561 											{
5562 												if(fabs(trent->s.origin[2] - ent->s.origin[2]) < JumpMax) k = true;
5563 											}
5564 										}
5565 									}
5566 //									if(Bot_trace (ent,zc->second_target)) k = true;
5567 								}
5568 								if(!k)
5569 								{
5570 									//gi.bprintf(PRINT_HIGH,"waitset %i\n",e->moveinfo.state);
5571 									zc->waitin_obj = e;
5572 									zc->zcstate &= ~STS_WAITS;
5573 									zc->zcstate |= STS_W_DOOROPEN;
5574 								}
5575 								else
5576 								{
5577 									if((e->union_ent->s.origin[2] + 8
5578 											- ent->s.origin[2]) > JumpMax)
5579 									{
5580 										zc->route_trace = false;
5581 										zc->zcstate &= ~STS_WAITS;
5582 									}
5583 								}
5584 								break;
5585 							}
5586 						}
5587 					}
5588 				}
5589 			}
5590 			else if(!k) it_ent->use(it_ent,ent,it_ent/*ent*/);
5591 		}
5592 
5593 	}
5594 	//when touch da door
5595 	else if( it_ent != NULL && k == 2)
5596 	{
5597 		if(it_ent->moveinfo.state == PSTATE_BOTTOM)
5598 		{
5599 			if(it_ent->flags & FL_TEAMSLAVE)  it_ent->teammaster->use(it_ent->teammaster,ent,it_ent->teammaster/*ent*/);
5600 			else it_ent->use(it_ent,ent,it_ent/*ent*/);
5601 		}
5602 
5603 //if(zc->zcstate & STS_WAITSMASK ) gi.bprintf(PRINT_HIGH,"Door Use\n");
5604 
5605 		if(it_ent->moveinfo.state == PSTATE_BOTTOM)
5606 		{
5607 			VectorCopy(ent->s.origin,zc->movtarget_pt);
5608 			zc->waitin_obj = it_ent;
5609 			zc->zcstate &= ~STS_WAITS;
5610 			zc->zcstate |= STS_W_DOOROPEN;
5611 
5612 			if(it_ent->flags & FL_TEAMSLAVE)
5613 			{
5614 				trmin[0] = (it_ent->teammaster->absmin[0] + it_ent->teammaster->absmax[0]) / 2;
5615 				trmin[1] = (it_ent->teammaster->absmin[1] + it_ent->teammaster->absmax[1]) / 2;
5616 				trmax[0] = (it_ent->absmin[0] + it_ent->absmax[0]) / 2;
5617 				trmax[1] = (it_ent->absmin[1] + it_ent->absmax[1]) / 2;
5618 
5619 				temppos[0] = (trmin[0] + trmax[0]) /2;
5620 				temppos[1] = (trmin[1] + trmax[1]) /2;
5621 				if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = Get_yaw(temppos);
5622 			}
5623 			else
5624 			{
5625 				trmax[0] = (it_ent->absmin[0] + it_ent->absmax[0]) / 2;
5626 				trmax[1] = (it_ent->absmin[1] + it_ent->absmax[1]) / 2;
5627 				VectorSubtract(trmax,ent->s.origin,temppos);
5628 				if(trace_priority < TRP_ANGLEKEEP) ent->s.angles[YAW] = Get_yaw(temppos);
5629 			}
5630 		}
5631 		else if(it_ent->moveinfo.state == PSTATE_UP )
5632 		{
5633 			VectorCopy(ent->s.origin,zc->movtarget_pt);
5634 			zc->waitin_obj = it_ent;
5635 			zc->zcstate &= ~STS_WAITS;
5636 			zc->zcstate |= STS_W_DOOROPEN;
5637 		}
5638 	}
5639 VCHCANSEL:
5640 	//--------------------------------------------------------------------------------------
5641 	//ladder check
5642 	front = NULL, left = NULL, right = NULL;
5643 	k = false;
5644 	if(zc->route_trace && (zc->routeindex + 1) < CurrentIndex)
5645 	{
5646 		Get_RouteOrigin(zc->routeindex + 1,v);
5647 		if((v[2] - ent->s.origin[2]) >= 32 /*|| ent->waterlevel*/) k = true;
5648 	}
5649 	if(k && trace_priority && !zc->second_target && !(ent->client->ps.pmove.pm_flags & PMF_DUCKED))
5650 	{
5651 		tempflag = false;
5652 
5653 		VectorCopy(ent->mins,trmin);
5654 		VectorCopy(ent->maxs,trmax);
5655 
5656 		trmin[2] += 20;
5657 
5658 		//front
5659 		f1 = 32;
5660 		if(zc->route_trace) f1 = 32;
5661 
5662 		iyaw = zc->moveyaw;
5663 		yaw = iyaw * M_PI * 2 / 360;
5664 		touchmin[0] = cos(yaw) * f1;//28 ;
5665 		touchmin[1] = sin(yaw) * f1;
5666 		touchmin[2] = 0;
5667 
5668 		VectorAdd(ent->s.origin,touchmin,touchmax);
5669 		rs_trace = gi.trace (ent->s.origin, trmin,ent->maxs, touchmax,ent, MASK_BOTSOLID );
5670 		front = rs_trace.ent;
5671 
5672 		if(rs_trace.contents & CONTENTS_LADDER) tempflag = true;
5673 
5674 		//upper
5675 		if(!tempflag && !zc->waterstate)
5676 		{
5677 			trmax[2] += 32;
5678 			rs_trace = gi.trace (ent->s.origin, trmin,trmax, touchmax,ent, MASK_BOTSOLID );
5679 			if(rs_trace.contents & CONTENTS_LADDER) tempflag = 2;
5680 		}
5681 		if(!tempflag && ent->groundentity)
5682 		{
5683 			Get_RouteOrigin(zc->routeindex,v);
5684 			v[2] = ent->s.origin[2];//0;
5685 			rs_trace = gi.trace (ent->s.origin, trmin,ent->maxs, v,ent, MASK_BOTSOLID );
5686 			if(rs_trace.contents & CONTENTS_LADDER) tempflag = 3;
5687 		}
5688 
5689 		//right
5690 		if(!tempflag)
5691 		{
5692 			iyaw = zc->moveyaw + 90;
5693 			if(iyaw > 180) iyaw -= 360;
5694 			yaw = iyaw * M_PI * 2 / 360;
5695 			touchmin[0] = cos(yaw) * 32 ;
5696 			touchmin[1] = sin(yaw) * 32 ;
5697 			touchmin[2] = 0;
5698 
5699 			VectorAdd(ent->s.origin,touchmin,touchmax);
5700 			rs_trace = gi.trace (ent->s.origin, trmin,ent->maxs, touchmax,ent,  MASK_BOTSOLID );
5701 			right = rs_trace.ent;
5702 
5703 			if(rs_trace.contents & CONTENTS_LADDER) tempflag = true;
5704 		}
5705 		//left
5706 		if(!tempflag)
5707 		{
5708 			iyaw = zc->moveyaw - 90;
5709 			if(iyaw < -180) iyaw += 360;
5710 			yaw = iyaw * M_PI * 2 / 360;
5711 			touchmin[0] = cos(yaw) * 32 ;
5712 			touchmin[1] = sin(yaw) * 32 ;
5713 			touchmin[2] = 0;
5714 
5715 			VectorAdd(ent->s.origin,touchmin,touchmax);
5716 			rs_trace = gi.trace (ent->s.origin, trmin,ent->maxs, touchmax,ent, MASK_BOTSOLID );
5717 			left = rs_trace.ent;
5718 
5719 			if(rs_trace.contents & CONTENTS_LADDER)	tempflag = true;
5720 		}
5721 
5722 		//ladder
5723 		if(tempflag)
5724 		{
5725 #ifdef _DEBUG
5726 gi.bprintf(PRINT_HIGH,"ladder founded! %f\n",iyaw);
5727 #endif
5728 			VectorCopy(rs_trace.endpos,trmax);
5729 			VectorCopy(trmax,touchmax);
5730 			touchmax[2] += 8190;
5731 			rs_trace = gi.trace (/*temppos*/trmax, trmin,ent->maxs, touchmax,ent, MASK_SOLID );
5732 
5733 			 e = rs_trace.ent;
5734 //if((rs_trace.contents & CONTENTS_LADDER)) gi.bprintf(PRINT_HIGH,"damn!\n");
5735 
5736 			k = 0;
5737 			VectorCopy(rs_trace.endpos,temppos);
5738 			VectorAdd(rs_trace.endpos,touchmin,touchmax);
5739 			rs_trace = gi.trace (temppos, trmin,ent->maxs, touchmax,ent, MASK_BOTSOLID);
5740 
5741 			if(e)
5742 			{
5743 				if(Q_stricmp (e->classname, "func_door") == 0)
5744 				{
5745 					k = true;
5746 				}
5747 			}
5748 
5749 			if((!(rs_trace.contents & CONTENTS_LADDER) || k) /*&& rs_trace.fraction < 1.0*/)
5750 			{
5751 //	gi.WriteByte (svc_temp_entity);
5752 //	gi.WriteByte (TE_RAILTRAIL);
5753 //	gi.WritePosition (ent->s.origin);
5754 //	gi.WritePosition (temppos);
5755 //	gi.multicast (ent->s.origin, MULTICAST_PHS);
5756 
5757 				ent->velocity[0] = 0;
5758 				ent->velocity[1] = 0;
5759 				if(zc->moveyaw == iyaw || zc->route_trace)
5760 				{
5761 #ifdef _DEBUG
5762 gi.bprintf(PRINT_HIGH,"ladder On!\n");
5763 #endif
5764 
5765 /*					x = Get_yaw(rs_trace.plane.normal);
5766 					x += 180;
5767 					if(x > 180) x -= 360;
5768 					zc->moveyaw = x;*/
5769 					if(zc->moveyaw != iyaw)  zc->moveyaw = iyaw;
5770 
5771 					ent->s.angles[YAW] = zc->moveyaw;
5772 					if(tempflag != 3) VectorCopy(trmax,ent->s.origin);
5773 					zc->zcstate |= STS_LADDERUP;
5774 					ent->s.angles[YAW] = zc->moveyaw;
5775 					ent->s.angles[PITCH] = -29;
5776 
5777 					if(tempflag == 2)
5778 					{
5779 						ent->velocity[2] += VEL_BOT_JUMP;
5780 						gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
5781 						PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
5782 						Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
5783 						zc->zcstate |= STS_SJMASK;
5784 //						ent->s.frame = FRAME_jump1-1;
5785 //						ent->client->anim_end = FRAME_jump6;
5786 //						ent->client->anim_priority = ANIM_JUMP;
5787 						ent->moveinfo.speed = 0;
5788 					}
5789 					else if(tempflag == 3)
5790 					{
5791 						ent->velocity[2] += VEL_BOT_JUMP;
5792 						gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
5793 						PlayerNoise(ent, ent->s.origin, PNOISE_SELF);	//pon
5794 						Set_BotAnim(ent,ANIM_JUMP,FRAME_jump1-1,FRAME_jump6);
5795 						zc->zcstate |= STS_SJMASK;
5796 //						ent->s.frame = FRAME_jump1-1;
5797 //						ent->client->anim_end = FRAME_jump6;
5798 //						ent->client->anim_priority = ANIM_JUMP;
5799 						ent->moveinfo.speed = MOVE_SPD_JUMP;
5800 					}
5801 					else if(ent->waterlevel > 1)
5802 					{
5803 						ent->velocity[2] = VEL_BOT_WLADRUP;
5804 //				if(VectorCompare(ent->s.origin,ent->s.old_origin)) ent->velocity[2] += 50;
5805 					}
5806 					else
5807 					{
5808 						ent->velocity[2] = VEL_BOT_LADRUP;
5809 //			if(VectorCompare(ent->s.origin,ent->s.old_origin)) ent->velocity[2] += 50;
5810 					}
5811 //					gi.bprintf(PRINT_HIGH,"ladder!!\n");
5812 //					goto VCHCANSEL;
5813 				}
5814 				else
5815 				{
5816 					zc->moveyaw = iyaw;
5817 					ent->s.angles[YAW] = zc->moveyaw;
5818 				}
5819 //				goto VCHCANSEL;
5820 			}
5821 		}
5822 	}
5823 VCHCANSEL_L:
5824 	//--------------------------------------------------------------------------------------
5825 	//player sizebox set
5826 	// ducked
5827 	//special duckset
5828 	if(ent->client->zc.battleduckcnt > 0 && ent->groundentity && ent->velocity[2] < 10)
5829 	{
5830 		ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
5831 		ent->client->zc.battleduckcnt--;
5832 	}
5833 
5834 	if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
5835 	{
5836 		ent->client->zc.n_duckedtime = 0;
5837 		ent->maxs[2] = 4;
5838 		ent->viewheight = -2;
5839 	}
5840 	// not ducked
5841 	else
5842 	{
5843 		if(ent->client->zc.n_duckedtime < FRAMETIME * 10) ent->client->zc.n_duckedtime += FRAMETIME;
5844 		ent->maxs[2] = 32;
5845 		ent->viewheight = 22;
5846 	}
5847 
5848 	//--------------------------------------------------------------------------------------
5849 	// angle set
5850 	VectorCopy(ent->s.angles,ent->client->v_angle);
5851 	if(ent->s.angles[PITCH] < -29) ent->s.angles[PITCH] = -29;
5852 	else if(ent->s.angles[PITCH] > 29) ent->s.angles[PITCH] = 29;
5853 
5854 	//--------------------------------------------------------------------------------------
5855 
5856 //ZOID
5857 	if (ent->client->ctf_grapple)
5858 	{
5859 /*		if(ent->client->ctf_grapplestate > CTF_GRAPPLE_STATE_FLY)
5860 		{
5861 			if(ent->waterlevel && !waterjumped) VectorClear(ent->velocity);
5862 		}*/
5863 		CTFGrapplePull(ent->client->ctf_grapple);
5864 		if(ent->client->ctf_grapplestate > CTF_GRAPPLE_STATE_FLY)
5865 		{
5866 			e = (edict_t*)ent->client->ctf_grapple;
5867 			//ent->velocity[2] =  ent->gravity * sv_gravity->value * FRAMETIME;
5868 			if(ent->groundentity && ent->velocity[2] < 0) ent->velocity[2] =  ent->gravity * sv_gravity->value * FRAMETIME;
5869 			else if(VectorCompare(ent->s.origin,ent->s.old_origin))
5870 			{
5871 				ent->velocity[2] +=  JumpMax;//ent->gravity * sv_gravity->value * FRAMETIME * 4;
5872 
5873 				if(ent->client->ctf_grapplestate == CTF_GRAPPLE_STATE_PULL)
5874 				{
5875 					VectorSubtract(ent->s.origin,e->s.origin,v);
5876 					yaw = Get_yaw(v);
5877 
5878 					yaw = yaw * M_PI * 2 / 360;
5879 					ent->velocity[0] += cos(yaw) * 200 ;				//start
5880 					ent->velocity[1] += sin(yaw) * 200 ;
5881 				}
5882 			}
5883 			else ent->velocity[2] +=  ent->gravity * sv_gravity->value * FRAMETIME * 2;
5884 		}
5885 	}
5886 	else
5887 	{
5888 		if(ent->waterlevel > 2) {ent->velocity[0] = 0;ent->velocity[1] = 0;/*VectorClear(ent->velocity);*/}
5889 		else if(ent->waterlevel && !ent->groundentity && ent->velocity[2] < 0) VectorClear(ent->velocity);//ent->velocity[2] = 0;
5890 	}
5891 //ZOID
5892 
5893 /*
5894 ent->velocity[0] = 800 * (random() - 0.5);
5895 ent->velocity[1] = 800 * (random() - 0.5);
5896 
5897 ent->client->ps.pmove.pm_flags |= PMF_DUCKED;
5898 */
5899 	ent->client->zc.trapped = false;		//trapcatch clear
5900 
5901 	gi.linkentity (ent);
5902 	G_TouchTriggers (ent);
5903 }
5904