本文整理汇总了C++中Chit类的典型用法代码示例。如果您正苦于以下问题:C++ Chit类的具体用法?C++ Chit怎么用?C++ Chit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Chit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ToSector
bool CoreScript::IsSquaddieOnMission(int chitID, int* squadID, Vector2I* wantToConquer)
{
if (!CitizenFilter(chitID)) {
return false;
}
for (int i = 0; i < MAX_SQUADS; ++i) {
if (squads[i].Find(chitID) >= 0) {
if (squadID) {
*squadID = i;
}
if (wantToConquer) {
wantToConquer->Zero();
if (!waypoints[i].Empty()) {
Vector2I waypoint2i = waypoints[i][waypoints[i].Size() - 1];
Vector2I waypointSector = ToSector(waypoint2i);
const SectorData& sd = Context()->worldMap->GetSectorData(waypointSector);
if (sd.CoreLoc() == waypoint2i) {
*wantToConquer = waypointSector;
}
}
}
Chit* chit = Context()->chitBag->GetChit(chitID);
return !waypoints[i].Empty() || (ToSector(chit->Position()) != ToSector(ParentChit()->Position()));
}
}
return false;
}
示例2: while
void CoreScript::OnChitMsg(Chit* chit, const ChitMsg& msg)
{
// Logic split between Sim::OnChitMsg and CoreScript::OnChitMsg
if (msg.ID() == ChitMsg::CHIT_DESTROYED && (chit == parentChit)) {
while (!citizens.Empty()) {
int citizenID = citizens.Pop();
Chit* citizen = Context()->chitBag->GetChit(citizenID);
if (citizen && citizen->GetItem()) {
// Set to rogue team.
citizen->GetItem()->SetRogue();
}
}
Vector2I pos2i = ToWorld2I(chit->Position());
Vector2I sector = ToSector(pos2i);
if (Team::Instance()->IsController(chit->Team())) {
NewsEvent news(NewsEvent::SUPERTEAM_DELETED, ToWorld2F(pos2i), chit->GetItemID(), 0);
Context()->chitBag->GetNewsHistory()->Add(news);
}
int controllerTeam = 0;
if (Team::Instance()->IsControlled(chit->Team(), &controllerTeam)) {
CoreScript* controller = CoreScript::GetCoreFromTeam(controllerTeam);
GLASSERT(controller);
if (controller) {
NewsEvent news(NewsEvent::SUBTEAM_DELETED, ToWorld2F(pos2i), chit->GetItemID(), controller->ParentChit()->GetItemID());
Context()->chitBag->GetNewsHistory()->Add(news);
}
}
int deleterID = chit->GetItemComponent() ? chit->GetItemComponent()->LastDamageID() : 0;
Chit* deleter = Context()->chitBag->GetChit(deleterID);
int superTeam = 0;
if (deleter
&& (deleter->Team() == Team::Instance()->SuperTeam(deleter->Team()))
&& Team::IsDenizen(deleter->Team())
&& Team::IsDenizen(chit->Team()))
{
superTeam = deleter->Team();
}
if (chit->Team() != TEAM_NEUTRAL) {
if (superTeam) {
LumosChitBag::CreateCoreData data = { sector, true, chit->Team(), deleter ? deleter->Team() : 0 };
Context()->chitBag->coreCreateList.Push(data);
}
else {
LumosChitBag::CreateCoreData data = { sector, false, chit->Team(), deleter ? deleter->Team() : 0 };
Context()->chitBag->coreCreateList.Push(data);
}
}
else {
// Neutral cores are taken over by wandering over them
// with enough friend units to have critical mass.
LumosChitBag::CreateCoreData data = { sector, false, 0, 0 };
Context()->chitBag->coreCreateList.Push(data);
}
Team::Instance()->CoreDestroyed(parentChit->Team());
}
}
示例3: FindBuilding
Chit* LumosChitBag::FindBuilding( const grinliz::IString& name,
const grinliz::Vector2I& sector,
const grinliz::Vector2F* pos,
LumosChitBag::EFindMode flags,
CDynArray<Chit*>* arr,
IChitAccept* filter )
{
CDynArray<Chit*>& match = arr ? *arr : findMatch; // sleazy reference trick to point to either passed in or local.
match.Clear();
findWeight.Clear();
for( MapSpatialComponent* it = mapSpatialHash[sector.y*NUM_SECTORS+sector.x]; it; it = it->nextBuilding ) {
Chit* chit = it->ParentChit();
GLASSERT( chit );
if ( filter && !filter->Accept( chit )) { // if a filter, check it.
continue;
}
const GameItem* item = chit->GetItem();
if ( item && ( name.empty() || item->IName() == name )) { // name, if empty, matches everything
match.Push( chit );
}
}
// If we found nothing, or we don't care about the position, return early.
// Else deal with choice / sorting / etc. below.
if ( match.Empty() )
return 0;
if ( !pos )
return match[0];
// NEAREST scans and finds the closest one.
// RANDOM_NEAR chooses one at random, but weighted by the (inverse) of the distance
if ( flags == EFindMode::NEAREST ) {
float closest = ( ToWorld2F(match[0]->Position()) - *pos ).LengthSquared();
int ci = 0;
for( int i=1; i<match.Size(); ++i ) {
float len2 = ( ToWorld2F(match[i]->Position()) - *pos ).LengthSquared();
if ( len2 < closest ) {
closest = len2;
ci = i;
}
}
return match[ci];
}
if ( flags == EFindMode::RANDOM_NEAR ) {
for( int i=0; i<match.Size(); ++i ) {
float len = ( ToWorld2F(match[i]->Position()) - *pos ).Length();
if (len < 1) len = 1;
findWeight.Push( 1.0f/len );
}
int index = random.Select( findWeight.Mem(), findWeight.Size() );
return match[index];
}
// Bad flag? Something didn't return?
GLASSERT( 0 );
return 0;
}
示例4: switch
int CameraComponent::DoTick(U32 delta)
{
float EASE = 0.2f;
switch (mode) {
case PAN:
{
Vector3F d = (dest - camera->PosWC());
Vector3F c = camera->PosWC();
if (d.Length() < 0.01f) {
camera->SetPosWC(dest.x, dest.y, dest.z);
mode = DONE;
}
else {
camera->SetPosWC(c.x + EASE*d.x, c.y + EASE*d.y, c.z + EASE*d.z);
}
}
break;
case TRACK:
{
Chit* chit = Context()->chitBag->GetChit(targetChitID);
if (chit) {
Vector3F pos = chit->Position();
pos.y = 0;
// Scoot the camera to always focus on the target. Removes
// errors that occur from rotation, drift, etc.
const Vector3F* eye3 = camera->EyeDir3();
Vector3F at;
int result = IntersectRayPlane(camera->PosWC(), eye3[0], 1, 0.0f, &at);
if (result == INTERSECT) {
Vector3F t = (camera->PosWC() - at);
//camera->SetPosWC( pos + t );
Vector3F c = camera->PosWC();
Vector3F d = (pos + t) - c;
// If grid moving, the EASE contributes to jitter.
if (GET_SUB_COMPONENT(chit, MoveComponent, GridMoveComponent)) {
EASE = 1.0f;
}
camera->SetPosWC(c.x + EASE*d.x, pos.y + t.y, c.z + EASE*d.z);
}
}
}
break;
case DONE:
break;
default:
GLASSERT(0);
}
return 0;
}
示例5: Context
Chit* CoreScript::CitizenFilter(int chitID)
{
Chit* chit = Context()->chitBag->GetChit(chitID);
if (chit && (chit->Team() == parentChit->Team())) {
return chit;
}
return 0;
}
示例6: GLASSERT
Chit* LumosChitBag::NewGoldChit( const grinliz::Vector3F& pos, Wallet* src )
{
GLASSERT(src);
if (src->Gold() == 0) return 0;
const ChitContext* context = Context();
Vector2F v2 = { pos.x, pos.z };
ItemNameFilter goldFilter( ISC::gold);
this->QuerySpatialHash( &chitList, v2, 1.0f, 0, &goldFilter );
Chit* chit = 0;
// Evil bug this: adding gold to a wallet just before
// deletion. I'm a little concerned where else
// this could be a problem. Would be nice to make
// deletion immediate.
for (int i = 0; i < chitList.Size(); ++i) {
Chit* c = chitList[i];
if (c && !IsQueuedForDelete(c) && c->GetWallet() && !c->GetWallet()->Closed()) {
chit = chitList[i];
break;
}
}
if ( !chit ) {
chit = this->NewChit();
AddItem( "gold", chit, context->engine, 0, 0 );
chit->Add( new RenderComponent( chit->GetItem()->ResourceName() ));
chit->SetPosition( pos );
chit->Add(new GameMoveComponent());
}
chit->GetWallet()->Deposit(src, src->Gold());
return chit;
}
示例7: GetNamedChit
CameraComponent* LumosChitBag::GetCamera() const
{
Chit* chit = GetNamedChit(ISC::Camera);
if (chit) {
GLASSERT(chit);
CameraComponent* cc = (CameraComponent*) chit->GetComponent("CameraComponent");
GLASSERT(cc);
return cc;
}
return 0;
}
示例8: CitizenFilter
bool CoreScript::IsCitizenItemID(int id)
{
for (int i = 0; i < citizens.Size(); ++i) {
int citizenID = citizens[i];
Chit* chit = CitizenFilter(citizenID);
if (chit && chit->GetItemID() == id) {
return true;
}
}
return false;
}
示例9: Context
void LumosChitBag::HandleBolt( const Bolt& bolt, const ModelVoxel& mv )
{
const ChitContext* context = Context();
Chit* chitShooter = GetChit( bolt.chitID ); // may be null
int shooterTeam = -1;
if ( chitShooter && chitShooter->GetItemComponent() ) {
shooterTeam = chitShooter->GetItemComponent()->GetItem()->Team();
}
int explosive = bolt.effect & GameItem::EFFECT_EXPLOSIVE;
if ( !explosive ) {
if ( mv.Hit() ) {
Chit* chitHit = mv.ModelHit() ? mv.model->userData : 0;
DamageDesc dd( bolt.damage, bolt.effect );
if ( chitHit ) {
GLASSERT( GetChit( chitHit->ID() ) == chitHit );
if ( chitHit->GetItemComponent() &&
chitHit->GetItemComponent()->GetItem()->Team() == shooterTeam )
{
// do nothing. don't shoot own team.
}
else {
ChitDamageInfo info( dd );
info.originID = bolt.chitID;
info.awardXP = true;
info.isMelee = false;
info.isExplosion = false;
info.originOfImpact = mv.at;
ChitMsg msg( ChitMsg::CHIT_DAMAGE, 0, &info );
chitHit->SendMessage( msg, 0 );
}
}
else if ( mv.VoxelHit() ) {
context->worldMap->VoxelHit( mv.voxel, dd );
}
}
}
else {
// How it used to work. Now only uses radius:
// Here don't worry about the chit hit. Just ray cast to see
// who is in range of the explosion and takes damage.
// Back up the origin of the bolt just a bit, so it doesn't keep
// intersecting the model it hit. Then do ray checks around to
// see what gets hit by the explosion.
float rewind = Min( 0.1f, 0.5f*bolt.len );
GLASSERT( Equal( bolt.dir.Length(), 1.f, 0.001f ));
Vector3F origin = mv.at - bolt.dir * rewind;
DamageDesc dd( bolt.damage, bolt.effect );
BattleMechanics::GenerateExplosion( dd, origin, bolt.chitID, context->engine, this, context->worldMap );
}
}
示例10: GLASSERT
bool CoreScript::SquadAtRest(int squadID)
{
GLASSERT(squadID >= 0 && squadID < MAX_SQUADS);
if (!waypoints[squadID].Empty()) {
return false;
}
Vector2I sector = ToSector(ParentChit()->Position());
for (int i = 0; i < squads[squadID].Size(); ++i) {
int chitID = squads[squadID][i];
Chit* chit = Context()->chitBag->GetChit(chitID);
if (chit && ToSector(chit->Position()) != sector) {
return false;
}
}
return true;
}
示例11: GLASSERT
SectorPort Visitors::ChooseDestination(int index, const Web& web, ChitBag* chitBag, WorldMap* map )
{
GLASSERT( instance );
GLASSERT( index >=0 && index <NUM_VISITORS );
VisitorData* visitor = &visitorData[index];
Chit* visitorChit = chitBag->GetChit(visitor->id);
SectorPort sectorPort;
if (!visitorChit) return sectorPort;
Vector2I thisSector = ToSector(visitorChit->Position());
const MinSpanTree::Node* node = web.FindNode(thisSector);
if (!node || node->firstChild == 0)
return sectorPort;
int nChildren = web.CountChildren(*node);
int which = random.Rand(nChildren);
const MinSpanTree::Node* child = web.ChildNode(*node, which);
Vector2I sector = child->pos;
const SectorData& sd = map->GetSectorData( sector );
GLASSERT(sd.ports);
if (!sd.ports)
return sectorPort;
int ports[4] = { 1, 2, 4, 8 };
int port = 0;
random.ShuffleArray( ports, 4 );
for( int i=0; i<4; ++i ) {
if ( sd.ports & ports[i] ) {
port = ports[i];
break;
}
}
sectorPort.sector = sector;
sectorPort.port = port;
return sectorPort;
}
示例12: BuildingCounts
void LumosChitBag::BuildingCounts(const Vector2I& sector, int* counts, int n)
{
BuildScript buildScript;
for( MapSpatialComponent* it = mapSpatialHash[sector.y*NUM_SECTORS+sector.x]; it; it = it->nextBuilding ) {
Chit* chit = it->ParentChit();
GLASSERT( chit );
const GameItem* item = chit->GetItem();
if (!item)
continue;
const IString& name = item->IName();
int id = 0;
if (!name.empty()) {
buildScript.GetDataFromStructure(name, &id);
if (id < n) {
counts[id] += 1;
}
}
}
}
示例13: ToWorld3F
Chit* LumosChitBag::NewWildFruit(const grinliz::Vector2I& pos)
{
Vector3F pos3 = ToWorld3F(pos);
pos3.x = floorf(pos3.x) + random.Uniform();
pos3.z = floorf(pos3.z) + random.Uniform();
const GameItem& root = ItemDefDB::Instance()->Get("fruit");
GameItem* item = root.Clone();
item->SetProperName(ISC::wildFruit);
Chit* chit = this->NewChit();
chit->Add(new ItemComponent(item));
chit->Add(new RenderComponent(item->ResourceName()));
chit->Add(new GameMoveComponent());
chit->Add(new HealthComponent());
chit->SetPosition(pos3);
return chit;
}
示例14: floorf
Chit* LumosChitBag::NewCrystalChit( const grinliz::Vector3F& _pos, Wallet* src, bool fuzz )
{
Vector3F pos = _pos;
if ( fuzz ) {
pos.x = floorf(_pos.x) + random.Uniform();
pos.z = floorf(_pos.z) + random.Uniform();
}
int crystal = -1;
for (int i = 0; i < NUM_CRYSTAL_TYPES; ++i) {
if (src->Crystal(i)) {
crystal = i;
break;
}
}
if (crystal == -1) return 0; // done
const char* name = 0;
switch ( crystal ) {
case CRYSTAL_GREEN: name="crystal_green"; break;
case CRYSTAL_RED: name="crystal_red"; break;
case CRYSTAL_BLUE: name="crystal_blue"; break;
case CRYSTAL_VIOLET: name="crystal_violet"; break;
}
const ChitContext* context = Context();
Chit* chit = this->NewChit();
AddItem( name, chit, context->engine, 0, 0 );
chit->Add( new RenderComponent( chit->GetItem()->ResourceName() ));
chit->Add(new GameMoveComponent());
chit->SetPosition( pos );
int c[NUM_CRYSTAL_TYPES] = { 0 };
c[crystal] = 1;
chit->GetWallet()->Deposit(src, 0, c);
return chit;
}
示例15: Citizens
void CoreScript::AssignToSquads()
{
// First, how many do we actually have?
// Filter out everyone that has gone away.
for (int i = 0; i < MAX_SQUADS; ++i) {
//GL_ARRAY_FILTER(squads[i], (this->IsCitizen(ele)));
squads[i].Filter(this, [](CoreScript* cs, int id) {
return cs->IsCitizen(id);
});
if (squads[i].Empty()) {
// Flush out dead squads so they don't have
// control flags laying around.
waypoints[i].Clear();
}
}
int nSquaddies = 0;
for (int i = 0; i < MAX_SQUADS; ++i) {
nSquaddies += squads[i].Size();
}
CChitArray recruits;
int nCitizens = Citizens(&recruits);
int nExpected = nCitizens - CITIZEN_BASE;
if (nSquaddies >= nExpected) return;
struct FilterData {
CoreScript* cs;
Chit* avatar;;
};
FilterData fd = { this, Context()->chitBag->GetAvatar() };
// Filter to: not in squad AND not player controlled
recruits.Filter(fd, [](const FilterData& ffd, Chit* chit) {
return (ffd.cs->SquadID(chit->ID()) < 0 && chit != ffd.avatar);
});
// Sort the best recruits to the end.
// FIXME: better if there was a (working) power approximation
recruits.Sort([](Chit* a, Chit* b) {
const GameItem* itemA = a->GetItem();
const GameItem* itemB = b->GetItem();
int scoreA = itemA->Traits().Level() * (itemA->GetPersonality().Fighting() == Personality::LIKES ? 2 : 1);
int scoreB = itemB->Traits().Level() * (itemB->GetPersonality().Fighting() == Personality::LIKES ? 2 : 1);
// Reverse order. Best at end.
return scoreA > scoreB;
});
for (int n = nExpected - nSquaddies; n > 0; --n) {
for (int i = 0; i < MAX_SQUADS; ++i) {
if ( (squads[i].Size() < SQUAD_SIZE)
&& SquadAtRest(i))
{
Chit* chit = recruits.Pop();
squads[i].Push(chit->ID());
++nSquaddies;
break;
}
}
}
}