1041
1041
//! @param zone the zone player is getting near
1042
1042
//! @param time the current time
1044
// *******************************************************************************
1046
bool sg_cyclesZonesAvoid = false;
1047
static tSettingItem<bool> sg_cyclesZonesAvoidConf("CYCLE_ZONES_AVOID", sg_cyclesZonesAvoid);
1049
REAL sg_cycleZonesApproch = 100.0;
1050
static tSettingItem<REAL>sg_cycleZoneApprochConf("CYCLE_ZONES_APPROCH", sg_cycleZonesApproch);
1052
static void TriggerAvoidZone(gCycle *target, gZone *Zone, REAL currentTime)
1054
// don't execute if players won't want to avoid zones
1055
if (!sg_cyclesZonesAvoid)
1058
eGrid *grid = eGrid::CurrentGrid();
1061
ePlayerNetID *player = target->Player();
1062
if ((player->IsChatting()) && (player->IsActive()) || (!player->IsHuman()))
1064
REAL tarX = target->Position().x;
1065
REAL tarY = target->Position().y;
1066
REAL zonX = Zone->Position().x;
1067
REAL zonY = Zone->Position().y;
1069
REAL tarDirX = target->Direction().x;
1070
REAL tarDirY = target->Direction().y;
1072
if ((tarX == zonX) || (tarY == zonY))
1074
target->Act(&gCycle::se_turnRight, 1);
1082
target->Act(&gCycle::se_turnRight, 1);
1084
target->Act(&gCycle::se_turnLeft, 1);
1087
else if (tarDirX <= -0.01)
1092
target->Act(&gCycle::se_turnLeft, 1);
1094
target->Act(&gCycle::se_turnRight, 1);
1102
target->Act(&gCycle::se_turnLeft, 1);
1104
target->Act(&gCycle::se_turnRight, 1);
1107
else if (tarDirY <= -0.01)
1112
target->Act(&gCycle::se_turnRight, 1);
1114
target->Act(&gCycle::se_turnLeft, 1);
1119
// if all fails, cycle will enter the zone
1044
// *******************************************************************************
1046
bool sg_cyclesZonesAvoid = false;
1047
static tSettingItem<bool> sg_cyclesZonesAvoidConf("CYCLE_ZONES_AVOID", sg_cyclesZonesAvoid);
1049
REAL sg_cycleZonesApproch = 100.0;
1050
static tSettingItem<REAL>sg_cycleZoneApprochConf("CYCLE_ZONES_APPROCH", sg_cycleZonesApproch);
1052
static void TriggerAvoidZone(gCycle *target, gZone *Zone, REAL currentTime)
1054
// don't execute if players won't want to avoid zones
1055
if (!sg_cyclesZonesAvoid)
1058
eGrid *grid = eGrid::CurrentGrid();
1061
ePlayerNetID *player = target->Player();
1062
if ((player->IsChatting()) && (player->IsActive()) || (!player->IsHuman()))
1064
REAL tarX = target->Position().x;
1065
REAL tarY = target->Position().y;
1066
REAL zonX = Zone->Position().x;
1067
REAL zonY = Zone->Position().y;
1069
REAL tarDirX = target->Direction().x;
1070
REAL tarDirY = target->Direction().y;
1072
if ((tarX == zonX) || (tarY == zonY))
1074
target->Act(&gCycle::se_turnRight, 1);
1082
target->Act(&gCycle::se_turnRight, 1);
1084
target->Act(&gCycle::se_turnLeft, 1);
1087
else if (tarDirX <= -0.01)
1092
target->Act(&gCycle::se_turnLeft, 1);
1094
target->Act(&gCycle::se_turnRight, 1);
1102
target->Act(&gCycle::se_turnLeft, 1);
1104
target->Act(&gCycle::se_turnRight, 1);
1107
else if (tarDirY <= -0.01)
1112
target->Act(&gCycle::se_turnRight, 1);
1114
target->Act(&gCycle::se_turnLeft, 1);
1119
// if all fails, cycle will enter the zone
5244
5231
positionUpdatePending_ = false;
5246
5233
return (returnStatus);
5249
5236
// *******************************************************************************
5251
5238
// * PassTheFlag
5253
// *******************************************************************************
5255
void gFlagZoneHack::PassComplete(gCycle *target)
5257
// finish passing the flag
5258
if (passingTheFlag_ && passingOwner_ && passerOwner_)
5262
tColoredString playerName, passingName;
5263
passingName << passerOwner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5264
playerName << target->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5266
if (target == passingOwner_)
5268
message.SetTemplateParameter(1, playerName);
5269
message.SetTemplateParameter(2, passingName);
5270
message << "$flag_pass_complete_same";
5274
message.SetTemplateParameter(1, passingName);
5275
message.SetTemplateParameter(2, playerName);
5276
message << "$flag_pass_complete_diff";
5278
sn_ConsoleOut(message);
5284
void gFlagZoneHack::PassFailed(gCycle *target)
5286
// finish passing the flag
5287
if (passingTheFlag_ && passingOwner_ && passerOwner_)
5291
tColoredString playerName, passingName;
5292
passingName << passerOwner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5293
playerName << target->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5295
message.SetTemplateParameter(1, passingName);
5296
message.SetTemplateParameter(2, playerName);
5297
message << "$flag_pass_failed";
5298
sn_ConsoleOut(message);
5304
void gFlagZoneHack::SetPassing(bool passed, gCycle *passOwner)
5308
passingTheFlag_ = true;
5309
passingOwner_ = passOwner;
5310
passerOwner_ = owner_;
5311
passerOwnerFree_ = false;
5315
passingTheFlag_ = false;
5316
passingOwner_ = NULL;
5317
passerOwner_ = NULL;
5318
passerOwnerFree_ = false;
5324
gFLAGPASS_DISABLE = 0, //! Disable passing the flag to team members
5325
gFLAGPASS_CLOSEST = 1, //! Picks a team member close to the passing player
5326
gFLAGPASS_FURTHEST = 2, //! Picks a team member furthur to the passing player
5327
gFLAGPASS_DISTANCE = 3, //! Picks a team member within the distance specified
5328
gFLAGPASS_PERSON = 4 //! Picks a team member by the given name
5330
tCONFIG_ENUM( gFlagPassMode );
5332
gFlagPassMode sg_flagPassMode = gFLAGPASS_DISABLE;
5333
bool restrictFlagPassMode(const gFlagPassMode &newValue)
5335
if ((newValue < gFLAGPASS_DISABLE) || (newValue > gFLAGPASS_PERSON)) return false;
5338
static tSettingItem<gFlagPassMode> sg_flagPassModeConf("FLAG_PASS_MODE", sg_flagPassMode, &restrictFlagPassMode);
5340
REAL sg_flagPassDistance = 5.0;
5341
bool restrictFlagPassDistance(const REAL &newValue)
5343
if (newValue < 0) return false;
5346
static tSettingItem<REAL> sg_flagPassDistanceConf("FLAG_PASS_DISTANCE", sg_flagPassDistance, &restrictFlagPassDistance);
5348
void gFlagZoneHack::PassTheFlag(tString name)
5352
if (sg_flagPassMode == gFLAGPASS_DISABLE) return;
5355
for (int i = 0; i < owner_->Team()->players.Len(); i++)
5357
ePlayerNetID *p = owner_->Team()->players[i];
5358
if (p && (p != owner_->Player()))
5360
gCycle *pCycle = dynamic_cast<gCycle *>(p->Object());
5362
if (pCycle && pCycle->Alive())
5369
// if no member is alive other than yourself, don't pass the flag
5370
if (alive == 0) return;
5372
// check the modes of each
5373
gCycle *passOwner = NULL;
5374
if (sg_flagPassMode == gFLAGPASS_CLOSEST)
5376
REAL closestDistance = 0;
5377
for (int i = 0; i < owner_->Team()->players.Len(); i++)
5379
ePlayerNetID *p = owner_->Team()->players[i];
5380
if (p && (p != owner_->Player()))
5382
gCycle *pCycle = dynamic_cast<gCycle *>(p->Object());
5384
if (pCycle && pCycle->Alive())
5386
eCoord otherpos = pCycle->Position() - owner_->Position();
5387
REAL distance = otherpos.NormSquared();
5388
if (!passOwner || (distance < closestDistance))
5391
closestDistance = distance;
5399
// put the flag to move towards new owner
5401
SetVelocity(passOwner->Direction() * owner_->verletSpeed_);
5402
SetPosition(owner_->Position());
5403
SetRadius(originalRadius_);
5404
SetExpansionSpeed(0);
5406
positionUpdatePending_ = true;
5408
// announce the passing activation
5411
tColoredString playerName, passingName;
5412
passingName << owner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5413
playerName << passOwner->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5415
message.SetTemplateParameter(1, passingName);
5416
message.SetTemplateParameter(2, playerName);
5417
message << "$flag_pass_active";
5418
sn_ConsoleOut(message);
5420
// set the passing owner (one to receive the flag)
5421
SetPassing(true, passOwner);
5423
// remove the current owner
5427
else if (sg_flagPassMode == gFLAGPASS_FURTHEST)
5429
REAL furthestDistance = 0;
5430
for (int i = 0; i < owner_->Team()->players.Len(); i++)
5432
ePlayerNetID *p = owner_->Team()->players[i];
5433
if (p && (p != owner_->Player()))
5435
gCycle *pCycle = dynamic_cast<gCycle *>(p->Object());
5437
if (pCycle && pCycle->Alive())
5439
eCoord otherpos = pCycle->Position() - owner_->Position();
5440
REAL distance = otherpos.NormSquared();
5441
if (!passOwner || (distance > furthestDistance))
5444
furthestDistance = distance;
5452
// put the flag to move towards new owner
5454
SetVelocity(passOwner->Direction() * owner_->verletSpeed_);
5455
SetPosition(owner_->Position());
5456
SetRadius(originalRadius_);
5457
SetExpansionSpeed(0);
5459
positionUpdatePending_ = true;
5461
// announce the passing activation
5464
tColoredString playerName, passingName;
5465
passingName << owner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5466
playerName << passOwner->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5468
message.SetTemplateParameter(1, passingName);
5469
message.SetTemplateParameter(2, playerName);
5470
message << "$flag_pass_active";
5471
sn_ConsoleOut(message);
5473
// set the passing owner
5474
SetPassing(true, passOwner);
5476
// remove the current owner
5480
else if (sg_flagPassMode == gFLAGPASS_DISTANCE)
5482
REAL furthestDistance = 0;
5483
for (int i = 0; i < owner_->Team()->players.Len(); i++)
5485
ePlayerNetID *p = owner_->Team()->players[i];
5486
if (p && (p != owner_->Player()))
5488
gCycle *pCycle = dynamic_cast<gCycle *>(p->Object());
5490
if (pCycle && pCycle->Alive())
5492
eCoord otherpos = pCycle->Position() - owner_->Position();
5493
REAL distance = otherpos.NormSquared();
5494
if (!passOwner || (distance > furthestDistance))
5497
furthestDistance = distance;
5500
// if distance is over the specified flag distance, break out of the function
5501
if (furthestDistance >= sg_flagPassDistance) break;
5508
// put the flag to move towards new owner
5510
SetVelocity(passOwner->Direction() * owner_->verletSpeed_);
5511
SetPosition(owner_->Position());
5512
SetRadius(originalRadius_);
5513
SetExpansionSpeed(0);
5515
positionUpdatePending_ = true;
5517
// announce the passing activation
5520
tColoredString playerName, passingName;
5521
passingName << owner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5522
playerName << passOwner->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5524
message.SetTemplateParameter(1, passingName);
5525
message.SetTemplateParameter(2, playerName);
5526
message << "$flag_pass_active";
5527
sn_ConsoleOut(message);
5529
// set the passing owner
5530
SetPassing(true, passOwner);
5532
// remove the current owner
5536
else if (sg_flagPassMode == gFLAGPASS_PERSON)
5538
if (name.Filter() == "") return;
5540
ePlayerNetID *p = ePlayerNetID::FindPlayerByName(name);
5543
// make sure that only the same team member will be allowed to get the pass of the flag
5544
if (p->CurrentTeam() != owner_->Team()) return;
5546
passOwner = dynamic_cast<gCycle *>(p->Object());
5549
// put the flag to move towards new owner
5551
SetVelocity(passOwner->Direction() * owner_->verletSpeed_);
5552
SetPosition(owner_->Position());
5553
SetRadius(originalRadius_);
5554
SetExpansionSpeed(0);
5556
positionUpdatePending_ = true;
5558
// announce the passing activation
5561
tColoredString playerName, passingName;
5562
passingName << owner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5563
playerName << passOwner->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5565
message.SetTemplateParameter(1, passingName);
5566
message.SetTemplateParameter(2, playerName);
5567
message << "$flag_pass_active";
5568
sn_ConsoleOut(message);
5570
// set the passing owner
5571
SetPassing(true, passOwner);
5573
// remove the current owner
5240
// *******************************************************************************
5242
void gFlagZoneHack::PassComplete(gCycle *target)
5244
// finish passing the flag
5245
if (passingTheFlag_ && passingOwner_ && passerOwner_)
5249
tColoredString playerName, passingName;
5250
passingName << passerOwner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5251
playerName << target->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5253
if (target == passingOwner_)
5255
message.SetTemplateParameter(1, playerName);
5256
message.SetTemplateParameter(2, passingName);
5257
message << "$flag_pass_complete_same";
5261
message.SetTemplateParameter(1, passingName);
5262
message.SetTemplateParameter(2, playerName);
5263
message << "$flag_pass_complete_diff";
5265
sn_ConsoleOut(message);
5271
void gFlagZoneHack::PassFailed(gCycle *target)
5273
// finish passing the flag
5274
if (passingTheFlag_ && passingOwner_ && passerOwner_)
5278
tColoredString playerName, passingName;
5279
passingName << passerOwner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5280
playerName << target->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5282
message.SetTemplateParameter(1, passingName);
5283
message.SetTemplateParameter(2, playerName);
5284
message << "$flag_pass_failed";
5285
sn_ConsoleOut(message);
5291
void gFlagZoneHack::SetPassing(bool passed, gCycle *passOwner)
5295
passingTheFlag_ = true;
5296
passingOwner_ = passOwner;
5297
passerOwner_ = owner_;
5298
passerOwnerFree_ = false;
5302
passingTheFlag_ = false;
5303
passingOwner_ = NULL;
5304
passerOwner_ = NULL;
5305
passerOwnerFree_ = false;
5311
gFLAGPASS_DISABLE = 0, //! Disable passing the flag to team members
5312
gFLAGPASS_CLOSEST = 1, //! Picks a team member close to the passing player
5313
gFLAGPASS_FURTHEST = 2, //! Picks a team member furthur to the passing player
5314
gFLAGPASS_DISTANCE = 3, //! Picks a team member within the distance specified
5315
gFLAGPASS_PERSON = 4 //! Picks a team member by the given name
5317
tCONFIG_ENUM( gFlagPassMode );
5319
gFlagPassMode sg_flagPassMode = gFLAGPASS_DISABLE;
5320
bool restrictFlagPassMode(const gFlagPassMode &newValue)
5322
if ((newValue < gFLAGPASS_DISABLE) || (newValue > gFLAGPASS_PERSON)) return false;
5325
static tSettingItem<gFlagPassMode> sg_flagPassModeConf("FLAG_PASS_MODE", sg_flagPassMode, &restrictFlagPassMode);
5327
REAL sg_flagPassDistance = 5.0;
5328
bool restrictFlagPassDistance(const REAL &newValue)
5330
if (newValue < 0) return false;
5333
static tSettingItem<REAL> sg_flagPassDistanceConf("FLAG_PASS_DISTANCE", sg_flagPassDistance, &restrictFlagPassDistance);
5335
void gFlagZoneHack::PassTheFlag(tString name)
5339
if (sg_flagPassMode == gFLAGPASS_DISABLE) return;
5342
for (int i = 0; i < owner_->Team()->players.Len(); i++)
5344
ePlayerNetID *p = owner_->Team()->players[i];
5345
if (p && (p != owner_->Player()))
5347
gCycle *pCycle = dynamic_cast<gCycle *>(p->Object());
5349
if (pCycle && pCycle->Alive())
5356
// if no member is alive other than yourself, don't pass the flag
5357
if (alive == 0) return;
5359
// check the modes of each
5360
gCycle *passOwner = NULL;
5361
if (sg_flagPassMode == gFLAGPASS_CLOSEST)
5363
REAL closestDistance = 0;
5364
for (int i = 0; i < owner_->Team()->players.Len(); i++)
5366
ePlayerNetID *p = owner_->Team()->players[i];
5367
if (p && (p != owner_->Player()))
5369
gCycle *pCycle = dynamic_cast<gCycle *>(p->Object());
5371
if (pCycle && pCycle->Alive())
5373
eCoord otherpos = pCycle->Position() - owner_->Position();
5374
REAL distance = otherpos.NormSquared();
5375
if (!passOwner || (distance < closestDistance))
5378
closestDistance = distance;
5386
// put the flag to move towards new owner
5388
SetVelocity(passOwner->Direction() * owner_->verletSpeed_);
5389
SetPosition(owner_->Position());
5390
SetRadius(originalRadius_);
5391
SetExpansionSpeed(0);
5393
positionUpdatePending_ = true;
5395
// announce the passing activation
5398
tColoredString playerName, passingName;
5399
passingName << owner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5400
playerName << passOwner->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5402
message.SetTemplateParameter(1, passingName);
5403
message.SetTemplateParameter(2, playerName);
5404
message << "$flag_pass_active";
5405
sn_ConsoleOut(message);
5407
// set the passing owner (one to receive the flag)
5408
SetPassing(true, passOwner);
5410
// remove the current owner
5414
else if (sg_flagPassMode == gFLAGPASS_FURTHEST)
5416
REAL furthestDistance = 0;
5417
for (int i = 0; i < owner_->Team()->players.Len(); i++)
5419
ePlayerNetID *p = owner_->Team()->players[i];
5420
if (p && (p != owner_->Player()))
5422
gCycle *pCycle = dynamic_cast<gCycle *>(p->Object());
5424
if (pCycle && pCycle->Alive())
5426
eCoord otherpos = pCycle->Position() - owner_->Position();
5427
REAL distance = otherpos.NormSquared();
5428
if (!passOwner || (distance > furthestDistance))
5431
furthestDistance = distance;
5439
// put the flag to move towards new owner
5441
SetVelocity(passOwner->Direction() * owner_->verletSpeed_);
5442
SetPosition(owner_->Position());
5443
SetRadius(originalRadius_);
5444
SetExpansionSpeed(0);
5446
positionUpdatePending_ = true;
5448
// announce the passing activation
5451
tColoredString playerName, passingName;
5452
passingName << owner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5453
playerName << passOwner->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5455
message.SetTemplateParameter(1, passingName);
5456
message.SetTemplateParameter(2, playerName);
5457
message << "$flag_pass_active";
5458
sn_ConsoleOut(message);
5460
// set the passing owner
5461
SetPassing(true, passOwner);
5463
// remove the current owner
5467
else if (sg_flagPassMode == gFLAGPASS_DISTANCE)
5469
REAL furthestDistance = 0;
5470
for (int i = 0; i < owner_->Team()->players.Len(); i++)
5472
ePlayerNetID *p = owner_->Team()->players[i];
5473
if (p && (p != owner_->Player()))
5475
gCycle *pCycle = dynamic_cast<gCycle *>(p->Object());
5477
if (pCycle && pCycle->Alive())
5479
eCoord otherpos = pCycle->Position() - owner_->Position();
5480
REAL distance = otherpos.NormSquared();
5481
if (!passOwner || (distance > furthestDistance))
5484
furthestDistance = distance;
5487
// if distance is over the specified flag distance, break out of the function
5488
if (furthestDistance >= sg_flagPassDistance) break;
5495
// put the flag to move towards new owner
5497
SetVelocity(passOwner->Direction() * owner_->verletSpeed_);
5498
SetPosition(owner_->Position());
5499
SetRadius(originalRadius_);
5500
SetExpansionSpeed(0);
5502
positionUpdatePending_ = true;
5504
// announce the passing activation
5507
tColoredString playerName, passingName;
5508
passingName << owner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5509
playerName << passOwner->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5511
message.SetTemplateParameter(1, passingName);
5512
message.SetTemplateParameter(2, playerName);
5513
message << "$flag_pass_active";
5514
sn_ConsoleOut(message);
5516
// set the passing owner
5517
SetPassing(true, passOwner);
5519
// remove the current owner
5523
else if (sg_flagPassMode == gFLAGPASS_PERSON)
5525
if (name.Filter() == "") return;
5527
ePlayerNetID *p = ePlayerNetID::FindPlayerByName(name);
5530
// make sure that only the same team member will be allowed to get the pass of the flag
5531
if (p->CurrentTeam() != owner_->Team()) return;
5533
passOwner = dynamic_cast<gCycle *>(p->Object());
5536
// put the flag to move towards new owner
5538
SetVelocity(passOwner->Direction() * owner_->verletSpeed_);
5539
SetPosition(owner_->Position());
5540
SetRadius(originalRadius_);
5541
SetExpansionSpeed(0);
5543
positionUpdatePending_ = true;
5545
// announce the passing activation
5548
tColoredString playerName, passingName;
5549
passingName << owner_->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5550
playerName << passOwner->Player()->GetColoredName() << tColoredString::ColorString(1,1,1);
5552
message.SetTemplateParameter(1, passingName);
5553
message.SetTemplateParameter(2, playerName);
5554
message << "$flag_pass_active";
5555
sn_ConsoleOut(message);
5557
// set the passing owner
5558
SetPassing(true, passOwner);
5560
// remove the current owner
7096
7083
zonePosYStr = params.ExtractNonBlankSubString(pos);
7099
7086
tString zoneSizeStr = params.ExtractNonBlankSubString(pos);
7100
7087
tString zoneGrowthStr = params.ExtractNonBlankSubString(pos);
7101
7088
tString zoneDirXStr = params.ExtractNonBlankSubString(pos);
7102
tString zoneDirYStr = params.ExtractNonBlankSubString(pos);
7089
tString zoneDirYStr = params.ExtractNonBlankSubString(pos);
7103
7090
tString zoneInteractive = params.ExtractNonBlankSubString(pos);
7104
7091
tString zoneRedStr = params.ExtractNonBlankSubString(pos);
7105
7092
tString zoneGreenStr = params.ExtractNonBlankSubString(pos);
7106
7093
tString zoneBlueStr = params.ExtractNonBlankSubString(pos);
7107
tString targetRadiusStr = params.ExtractNonBlankSubString(pos);
7108
tString seekOwnerStr = params.ExtractNonBlankSubString(pos);
7109
tString seekSpeedStr = params.ExtractNonBlankSubString(pos);
7110
tString seekUpdateTimeStr = params.ExtractNonBlankSubString(pos);
7094
tString targetRadiusStr = params.ExtractNonBlankSubString(pos);
7095
tString seekOwnerStr = params.ExtractNonBlankSubString(pos);
7096
tString seekSpeedStr = params.ExtractNonBlankSubString(pos);
7097
tString seekUpdateTimeStr = params.ExtractNonBlankSubString(pos);
7112
7099
eCoord zonePos = route.empty() ? eCoord(atof(zonePosXStr)*sizeMultiplier,atof(zonePosYStr)*sizeMultiplier) : route.front();
7113
7100
REAL zoneSize = atof(zoneSizeStr)*sizeMultiplier;
7114
REAL zoneGrowth = atof(zoneGrowthStr)*sizeMultiplier;
7101
REAL zoneGrowth = atof(zoneGrowthStr)*sizeMultiplier;
7116
7103
eCoord zoneDir = eCoord(atof(zoneDirXStr)*sizeMultiplier,atof(zoneDirYStr)*sizeMultiplier);
7117
7104
gRealColor zoneColor;
7118
7105
bool setColorFlag = false;
7119
7106
if ((zoneRedStr.Filter() != "") && (zoneGreenStr.Filter() != "") && (zoneBlueStr.Filter() != ""))
7121
if (zoneRedStr == "r_rand")
7123
tRandomizer &randomizer = tRandomizer::GetInstance();
7124
zoneColor.r = randomizer.Get(0, 15.0) / 15.0;
7128
zoneColor.r = atof(zoneRedStr) / 15.0;
7131
if (zoneGreenStr == "g_rand")
7133
tRandomizer &randomizer = tRandomizer::GetInstance();
7134
zoneColor.g = randomizer.Get(0, 15.0) / 15.0;
7138
zoneColor.g = atof(zoneGreenStr) / 15.0;
7141
if (zoneBlueStr == "b_rand")
7143
tRandomizer &randomizer = tRandomizer::GetInstance();
7144
zoneColor.b = randomizer.Get(0, 15.0) / 15.0;
7148
zoneColor.b = atof(zoneBlueStr) / 15.0;
7108
if (zoneRedStr == "r_rand")
7110
tRandomizer &randomizer = tRandomizer::GetInstance();
7111
zoneColor.r = randomizer.Get(0, 15.0) / 15.0;
7115
zoneColor.r = atof(zoneRedStr) / 15.0;
7118
if (zoneGreenStr == "g_rand")
7120
tRandomizer &randomizer = tRandomizer::GetInstance();
7121
zoneColor.g = randomizer.Get(0, 15.0) / 15.0;
7125
zoneColor.g = atof(zoneGreenStr) / 15.0;
7128
if (zoneBlueStr == "b_rand")
7130
tRandomizer &randomizer = tRandomizer::GetInstance();
7131
zoneColor.b = randomizer.Get(0, 15.0) / 15.0;
7135
zoneColor.b = atof(zoneBlueStr) / 15.0;
7150
7137
setColorFlag = true;
7153
7140
bool zoneInteractiveBool = false;
7154
7141
if (zoneInteractive.ToLower() == "true")
7155
zoneInteractiveBool = true;
7157
Zone = tNEW(gObjectZoneHack(grid, zonePos, true));
7158
Zone->SetRadius(zoneSize);
7159
Zone->SetExpansionSpeed(zoneGrowth);
7160
Zone->SetVelocity(zoneDir);
7142
zoneInteractiveBool = true;
7144
Zone = tNEW(gObjectZoneHack(grid, zonePos, true));
7145
Zone->SetRadius(zoneSize);
7146
Zone->SetExpansionSpeed(zoneGrowth);
7147
Zone->SetVelocity(zoneDir);
7162
7149
if (setColorFlag)
7164
7151
zoneColor.r = (zoneColor.r>1.0)?1.0:zoneColor.r;
7165
7152
zoneColor.g = (zoneColor.g>1.0)?1.0:zoneColor.g;
7166
7153
zoneColor.b = (zoneColor.b>1.0)?1.0:zoneColor.b;
7167
7154
Zone->SetColor(zoneColor);
7170
if (zoneInteractiveBool)
7172
Zone->SetWallBouncesLeft(-1);
7173
Zone->SetWallInteract(zoneInteractiveBool);
7176
REAL targetRadius = atof(targetRadiusStr)*sizeMultiplier;
7177
if(targetRadius != 0)
7178
Zone->SetTargetRadius(targetRadius);
7180
if (seekOwnerStr.Filter() != "")
7182
ePlayerNetID *seekOwnerPlayer = ePlayerNetID::FindPlayerByName(seekOwnerStr);
7183
if (seekOwnerPlayer && seekOwnerPlayer->Object() && seekOwnerPlayer->Object()->Alive())
7184
Zone->SetSeekingCycle(dynamic_cast<gCycle *>(seekOwnerPlayer->Object()));
7187
REAL seekSpeed = atof(seekSpeedStr);
7189
Zone->SetSeekSpeed(seekSpeed);
7191
Zone->SetSeekSpeed(1.0);
7193
REAL seekingUpdateTime = atof(seekUpdateTimeStr);
7194
if (seekingUpdateTime >= 0)
7195
Zone->SetSeekUpdate(seekingUpdateTime);
7197
Zone->SetSeekUpdate(0.5);
7157
if (zoneInteractiveBool)
7159
Zone->SetWallBouncesLeft(-1);
7160
Zone->SetWallInteract(zoneInteractiveBool);
7163
REAL targetRadius = atof(targetRadiusStr)*sizeMultiplier;
7164
if(targetRadius != 0)
7165
Zone->SetTargetRadius(targetRadius);
7167
if (seekOwnerStr.Filter() != "")
7169
ePlayerNetID *seekOwnerPlayer = ePlayerNetID::FindPlayerByName(seekOwnerStr);
7170
if (seekOwnerPlayer && seekOwnerPlayer->Object() && seekOwnerPlayer->Object()->Alive())
7171
Zone->SetSeekingCycle(dynamic_cast<gCycle *>(seekOwnerPlayer->Object()));
7174
REAL seekSpeed = atof(seekSpeedStr);
7176
Zone->SetSeekSpeed(seekSpeed);
7178
Zone->SetSeekSpeed(1.0);
7180
REAL seekingUpdateTime = atof(seekUpdateTimeStr);
7181
if (seekingUpdateTime >= 0)
7182
Zone->SetSeekUpdate(seekingUpdateTime);
7184
Zone->SetSeekUpdate(0.5);
7199
7186
Zone->SetReferenceTime();
7200
Zone->SetRotationSpeed( .3f );
7187
Zone->SetRotationSpeed( .3f );
7202
7189
if(!route.empty())
7438
7425
//! @param time the current time
7440
// *******************************************************************************
7442
bool sg_soccerBallSlowdown = true;
7443
static tSettingItem<bool> sg_soccerBallSlowdownConf("SOCCER_BALL_SLOWDOWN", sg_soccerBallSlowdown);
7445
REAL sg_soccerBallSlowdownSpeed = 0.07;
7446
bool restrictBallSlowdownSpeed(const REAL &newValue)
7448
// if values are less than 0 or greater than 1, no good!
7449
if ((newValue <= 0) || (newValue >= 1))
7452
// if values are in between 0 and 1, good!
7455
static tSettingItem<REAL> sg_soccerBallSlowdownSpeedConf("SOCCER_BALL_SLOWDOWN_SPEED", sg_soccerBallSlowdownSpeed, &restrictBallSlowdownSpeed);
7427
// *******************************************************************************
7429
bool sg_soccerBallSlowdown = true;
7430
static tSettingItem<bool> sg_soccerBallSlowdownConf("SOCCER_BALL_SLOWDOWN", sg_soccerBallSlowdown);
7432
REAL sg_soccerBallSlowdownSpeed = 0.07;
7433
bool restrictBallSlowdownSpeed(const REAL &newValue)
7435
// if values are less than 0 or greater than 1, no good!
7436
if ((newValue <= 0) || (newValue >= 1))
7439
// if values are in between 0 and 1, good!
7442
static tSettingItem<REAL> sg_soccerBallSlowdownSpeedConf("SOCCER_BALL_SLOWDOWN_SPEED", sg_soccerBallSlowdownSpeed, &restrictBallSlowdownSpeed);
7457
7444
bool gSoccerZoneHack::Timestep( REAL time )
7460
bool returnStatus = gZone::Timestep( time );
7462
if ((zoneType == gSoccer_GOAL) && !team)
7463
if (!CheckTeamAssignment()) return true;;
7467
originalVelocity_ = GetVelocity();
7469
// less than 0.1 seconds due to unknown reasons...
7470
// making sure original radius is found to be greater than 0
7471
if ((time < 0.1) && (GetRadius() > 0))
7472
originalRadius_ = GetRadius();
7474
// installazation success!
7478
// for slowing down the soccer ball
7479
if ((zoneType == gSoccer_BALL) && sg_soccerBallSlowdown && (GetVelocity() != eCoord(0,0)))
7481
// store the current speed for setup
7482
eCoord currentVelocity = GetVelocity();
7484
// get the values working with decreasing the velocity speed
7485
if (currentVelocity.x < 0)
7486
currentVelocity.x += sg_soccerBallSlowdownSpeed;
7487
else if (currentVelocity.x > 0)
7488
currentVelocity.x -= sg_soccerBallSlowdownSpeed;
7490
if (currentVelocity.y < 0)
7491
currentVelocity.y += sg_soccerBallSlowdownSpeed;
7492
else if (currentVelocity.y > 0)
7493
currentVelocity.y -= sg_soccerBallSlowdownSpeed;
7495
if (((currentVelocity.x > -1) && (currentVelocity.x < 0)) || ((currentVelocity.x > 0) && (currentVelocity.x < 1)))
7496
currentVelocity.x = 0;
7498
if (((currentVelocity.y > -1) && (currentVelocity.y < 0)) || ((currentVelocity.y > 0) && (currentVelocity.y < 1)))
7499
currentVelocity.y = 0;
7502
SetVelocity(currentVelocity);
7447
bool returnStatus = gZone::Timestep( time );
7449
if ((zoneType == gSoccer_GOAL) && !team)
7450
if (!CheckTeamAssignment()) return true;;
7454
originalVelocity_ = GetVelocity();
7456
// less than 0.1 seconds due to unknown reasons...
7457
// making sure original radius is found to be greater than 0
7458
if ((time < 0.1) && (GetRadius() > 0))
7459
originalRadius_ = GetRadius();
7461
// installazation success!
7465
// for slowing down the soccer ball
7466
if ((zoneType == gSoccer_BALL) && sg_soccerBallSlowdown && (GetVelocity() != eCoord(0,0)))
7468
// store the current speed for setup
7469
eCoord currentVelocity = GetVelocity();
7471
// get the values working with decreasing the velocity speed
7472
if (currentVelocity.x < 0)
7473
currentVelocity.x += sg_soccerBallSlowdownSpeed;
7474
else if (currentVelocity.x > 0)
7475
currentVelocity.x -= sg_soccerBallSlowdownSpeed;
7477
if (currentVelocity.y < 0)
7478
currentVelocity.y += sg_soccerBallSlowdownSpeed;
7479
else if (currentVelocity.y > 0)
7480
currentVelocity.y -= sg_soccerBallSlowdownSpeed;
7482
if (((currentVelocity.x > -1) && (currentVelocity.x < 0)) || ((currentVelocity.x > 0) && (currentVelocity.x < 1)))
7483
currentVelocity.x = 0;
7485
if (((currentVelocity.y > -1) && (currentVelocity.y < 0)) || ((currentVelocity.y > 0) && (currentVelocity.y < 1)))
7486
currentVelocity.y = 0;
7489
SetVelocity(currentVelocity);
7507
7494
return (returnStatus);
7510
7497
// *******************************************************************************
7514
// *******************************************************************************
7516
void gSoccerZoneHack::GoHome()
7518
// clear last team to hit the soccer ball
7521
// send soccer ball back to it's oriignal place on the grid
7501
// *******************************************************************************
7503
void gSoccerZoneHack::GoHome()
7505
// clear last team to hit the soccer ball
7508
// send soccer ball back to it's oriignal place on the grid
7522
7509
SetReferenceTime();
7523
7510
SetPosition(originalPosition_);
7524
SetVelocity(originalVelocity_);
7511
SetVelocity(originalVelocity_);
7525
7512
SetRadius(originalRadius_);
7592
7579
base.Normalize();
7593
7580
eCoord new_v1 = base*-target->Speed();
7594
7581
eCoord new_p1 = p1c + new_v1*(-t+0.01);
7595
new_v1 = new_v1*(1+sg_ballCycleBoost*target->GetAcceleration()/100);
7597
SetPosition(new_p1);
7598
SetVelocity(new_v1);
7602
// set last player to hit the zone
7603
lastTeamIn_ = target->Team();
7605
sg_soccerBallPlayerEntered << target->Player()->GetUserName() << target->Team()->Name().Filter();
7606
sg_soccerBallPlayerEntered.write();
7609
else if (team && (zoneType == gSoccer_GOAL))
7611
if (sg_soccerGoalKillEnemies)
7613
if (target && (team != target->Team()))
7615
sn_ConsoleOut(tOutput("$soccer_goal_enemy_entered", target->Player()->GetColoredName(), Team()->GetColoredName()));
7621
if (sg_soccerGoalRespawnAllies && (team == target->Team()))
7623
gSpawnPoint *pSpawn = Arena.ClosestSpawnPoint(GetPosition());
7626
for(int i = 0; i < Team()->NumPlayers(); i++)
7628
ePlayerNetID *p = Team()->Player(i);
7631
gCycle *cycle = dynamic_cast<gCycle *>(p->Object());
7632
if (!cycle || (!cycle->Alive()))
7634
eCoord cyclePos, cycleDir;
7635
pSpawn->Spawn(cyclePos, cycleDir);
7637
gCycle *newCycle = new gCycle(Grid(), cyclePos, cycleDir, p);
7638
p->ControlObject(newCycle);
7646
sg_soccerGoalPlayerEntered << target->Player()->GetUserName() << target->Team()->Name().Filter() << Team()->Name().Filter();
7647
sg_soccerGoalPlayerEntered.write();
7651
int sg_soccerGoalScore = 1;
7652
static tSettingItem<int> sg_soccerGoalScoreConf("SOCCER_GOAL_SCORE", sg_soccerGoalScore);
7654
bool sg_soccerBallFirstWin = false;
7655
static tSettingItem<bool> sg_soccerBallFirstWinConf("SOCCER_BALL_FIRST_WIN", sg_soccerBallFirstWin);
7657
int sg_soccerBallShotsWin = 0;
7658
static tSettingItem<int> sg_soccerBallShotsWinConf("SOCCER_BALL_SHOTS_WIN", sg_soccerBallShotsWin);
7660
void gSoccerZoneHack::OnEnter( gSoccerZoneHack *target, REAL time )
7662
// check if the zone entering the goal is actually a soccer ball
7663
if ((GetType() == gSoccer_GOAL) && (target->GetType() == gSoccer_BALL) && target->lastTeamIn_)
7665
if (target->lastTeamIn_ == team)
7667
sn_ConsoleOut(tOutput("$soccer_goal_self", Team()->GetColoredName()));
7669
// time to return ball to home
7674
// increase the number of times the ball entered other team's goal
7675
target->ballShots_++;
7677
target->lastTeamIn_->AddScore(sg_soccerGoalScore, tOutput("$soccer_goal_score", target->lastTeamIn_->GetColoredName(), Team()->GetColoredName(), sg_soccerGoalScore), tOutput());
7678
if (sg_soccerBallFirstWin && (target->ballShots_ == 1))
7680
sg_DeclareWinner(target->lastTeamIn_, tOutput("$soccer_winner"));
7682
// ball must vanish after having a winner
7685
else if ((sg_soccerBallShotsWin > 0) && (target->ballShots_ >= sg_soccerBallShotsWin))
7687
eTeam *thisTeam = team; // the team owner of the goal
7688
eTeam *shotTeam = target->lastTeamIn_; // the last team to hit the ball
7690
if (thisTeam && shotTeam)
7692
// ensure the team score's are compared
7693
if (shotTeam->Score() < thisTeam->Score())
7694
sg_DeclareWinner(thisTeam, tOutput("$soccer_winner"));
7696
sg_DeclareWinner(shotTeam, tOutput("$soccer_winner"));
7698
// ball must vanish after having a winner
7704
// return soccer ball home
7582
new_v1 = new_v1*(1+sg_ballCycleBoost*target->GetAcceleration()/100);
7584
SetPosition(new_p1);
7585
SetVelocity(new_v1);
7589
// set last player to hit the zone
7590
lastTeamIn_ = target->Team();
7592
sg_soccerBallPlayerEntered << target->Player()->GetUserName() << target->Team()->Name().Filter();
7593
sg_soccerBallPlayerEntered.write();
7596
else if (team && (zoneType == gSoccer_GOAL))
7598
if (sg_soccerGoalKillEnemies)
7600
if (target && (team != target->Team()))
7602
sn_ConsoleOut(tOutput("$soccer_goal_enemy_entered", target->Player()->GetColoredName(), Team()->GetColoredName()));
7608
if (sg_soccerGoalRespawnAllies && (team == target->Team()))
7610
gSpawnPoint *pSpawn = Arena.ClosestSpawnPoint(GetPosition());
7613
for(int i = 0; i < Team()->NumPlayers(); i++)
7615
ePlayerNetID *p = Team()->Player(i);
7618
gCycle *cycle = dynamic_cast<gCycle *>(p->Object());
7619
if (!cycle || (!cycle->Alive()))
7621
eCoord cyclePos, cycleDir;
7622
pSpawn->Spawn(cyclePos, cycleDir);
7624
gCycle *newCycle = new gCycle(Grid(), cyclePos, cycleDir, p);
7625
p->ControlObject(newCycle);
7633
sg_soccerGoalPlayerEntered << target->Player()->GetUserName() << target->Team()->Name().Filter() << Team()->Name().Filter();
7634
sg_soccerGoalPlayerEntered.write();
7638
int sg_soccerGoalScore = 1;
7639
static tSettingItem<int> sg_soccerGoalScoreConf("SOCCER_GOAL_SCORE", sg_soccerGoalScore);
7641
bool sg_soccerBallFirstWin = false;
7642
static tSettingItem<bool> sg_soccerBallFirstWinConf("SOCCER_BALL_FIRST_WIN", sg_soccerBallFirstWin);
7644
int sg_soccerBallShotsWin = 0;
7645
static tSettingItem<int> sg_soccerBallShotsWinConf("SOCCER_BALL_SHOTS_WIN", sg_soccerBallShotsWin);
7647
void gSoccerZoneHack::OnEnter( gSoccerZoneHack *target, REAL time )
7649
// check if the zone entering the goal is actually a soccer ball
7650
if ((GetType() == gSoccer_GOAL) && (target->GetType() == gSoccer_BALL) && target->lastTeamIn_)
7652
if (target->lastTeamIn_ == team)
7654
sn_ConsoleOut(tOutput("$soccer_goal_self", Team()->GetColoredName()));
7656
// time to return ball to home
7661
// increase the number of times the ball entered other team's goal
7662
target->ballShots_++;
7664
target->lastTeamIn_->AddScore(sg_soccerGoalScore, tOutput("$soccer_goal_score", target->lastTeamIn_->GetColoredName(), Team()->GetColoredName(), sg_soccerGoalScore), tOutput());
7665
if (sg_soccerBallFirstWin && (target->ballShots_ == 1))
7667
sg_DeclareWinner(target->lastTeamIn_, tOutput("$soccer_winner"));
7669
// ball must vanish after having a winner
7672
else if ((sg_soccerBallShotsWin > 0) && (target->ballShots_ >= sg_soccerBallShotsWin))
7674
eTeam *thisTeam = team; // the team owner of the goal
7675
eTeam *shotTeam = target->lastTeamIn_; // the last team to hit the ball
7677
if (thisTeam && shotTeam)
7679
// ensure the team score's are compared
7680
if (shotTeam->Score() < thisTeam->Score())
7681
sg_DeclareWinner(thisTeam, tOutput("$soccer_winner"));
7683
sg_DeclareWinner(shotTeam, tOutput("$soccer_winner"));
7685
// ball must vanish after having a winner
7691
// return soccer ball home
7711
7698
// *******************************************************************************
7715
// *******************************************************************************
7702
// *******************************************************************************
7717
7704
void gSoccerZoneHack::OnVanish( void )
7719
// respawn soccer ball that suddenly disappears
7720
if (zoneType == gSoccer_BALL)
7706
// respawn soccer ball that suddenly disappears
7707
if (zoneType == gSoccer_BALL)
7725
7712
grid->RemoveGameObjectInteresting(this);
7728
7715
// *******************************************************************************
7730
7717
// * SpawnSoccer
7732
// *******************************************************************************
7734
static void sg_SpawnSoccer(std::istream &s)
7719
// *******************************************************************************
7721
static void sg_SpawnSoccer(std::istream &s)
7736
7723
eGrid *grid = eGrid::CurrentGrid();
7741
params.ReadLine(s, true);
7743
if (params.Filter() == "")
7750
float sizeMultiplier = gArena::SizeMultiplier();
7751
float radius, growth;
7752
tString name, type, team;
7753
std::vector<eCoord> route;
7757
name = params.ExtractNonBlankSubString(pos);
7758
if (name.ToLower() == "n")
7760
name = params.ExtractNonBlankSubString(pos);
7761
type = params.ExtractNonBlankSubString(pos);