<commit_before>/* bzflag
 * Copyright (c) 1993 - 2005 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/* the common header */
#include "common.h"

/* interface header */
#include "CustomZone.h"

/* system headers */
#include <stdlib.h>
#include <string>
#include <sstream>
#include <math.h>

/* local implementation headers */
//#include "EntryZones.h"
#include "WorldInfo.h"
#include "Flag.h"
#include "Team.h"


CustomZone::CustomZone()
{
  pos[0] = pos[1] = pos[2] = 0.0f;
  rotation = 0.0f;
  size[0] = size[1] = size[2] = 1.0f;
}


// make a safety zone for all team flags
void CustomZone::addFlagSafety(float x, float y, WorldInfo* worldInfo)
{
  pos[0] = x;
  pos[1] = y;
  pos[2] = 0.0f;
  size[0] = 0.0f;
  size[1] = 0.0f;
  size[2] = 0.0f;
  rotation = 0.0f;

  // add the qualifiers
  for (int team = 0; team < CtfTeams; team++) {
    std::string qual = getFlagSafetyQualifier(team);
    if (qual.size() > 0) {
      qualifiers.push_back(qual);
    }
  }

  worldInfo->addZone(this);

  return;
}


void CustomZone::addZoneFlagCount(FlagType* flagType, int count)
{
  ZoneFlagMap::iterator it = zoneFlagMap.find(flagType);
  if (it != zoneFlagMap.end()) {
    count += it->second;
  }
  if (count < 0) {
    count = 0;
  }
  zoneFlagMap[flagType] = count;
  return;
}


bool CustomZone::read(const char *cmd, std::istream& input) {
  if (strcmp(cmd, "flag") == 0) {
    std::string args, flag;

    std::getline(input, args);
    std::istringstream parms(args);

    while (parms >> flag) {
      if (flag == "good") {
	FlagSet &fs = Flag::getGoodFlags();
	for (FlagSet::iterator it = fs.begin(); it != fs.end(); ++it) {
	  FlagType *f = *it;
	  if (f->endurance != FlagNormal) { // Null and Team flags
	    qualifiers.push_back(getFlagTypeQualifier(f));
	  }
	}
      }
      else if (flag == "bad") {
	FlagSet &fs = Flag::getBadFlags();
	for (FlagSet::iterator it = fs.begin(); it != fs.end(); ++it) {
	  FlagType *f = *it;
	  if (f->endurance != FlagNormal) { // Null and Team flags
	    qualifiers.push_back(getFlagTypeQualifier(f));
	  }
	}
      }
      else {
	FlagType* f = Flag::getDescFromAbbreviation(flag.c_str());
	if (f == Flags::Null) {
	  DEBUG1("WARNING: bad flag type: %s\n", flag.c_str());
          input.putback('\n');
	  return false;
	}
	if (f->endurance != FlagNormal) {
	  DEBUG1("WARNING: you probably want a safety: %s\n", flag.c_str());
          input.putback('\n');
	  return false;
	}
	qualifiers.push_back(getFlagTypeQualifier(f));
      }
    }

    input.putback('\n');
    if (qualifiers.size() == 0) {
      return false;
    }
  }
  else if (strcmp(cmd, "zoneflag") == 0) {
    std::string args, flag;
    std::getline(input, args);
    std::istringstream parms(args);
    int count;

    if (!(parms >> flag)) {
      return false;
    }
    if (!(parms >> count)) {
      count = 1;<commit_msg>more checking, fix the stupid brace<commit_after>/* bzflag
 * Copyright (c) 1993 - 2005 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

/* the common header */
#include "common.h"

/* interface header */
#include "CustomZone.h"

/* system headers */
#include <stdlib.h>
#include <string>
#include <sstream>
#include <math.h>

/* local implementation headers */
//#include "EntryZones.h"
#include "WorldInfo.h"
#include "Flag.h"
#include "Team.h"


CustomZone::CustomZone()
{
  pos[0] = pos[1] = pos[2] = 0.0f;
  rotation = 0.0f;
  size[0] = size[1] = size[2] = 1.0f;
}


// make a safety zone for all team flags
void CustomZone::addFlagSafety(float x, float y, WorldInfo* worldInfo)
{
  pos[0] = x;
  pos[1] = y;
  pos[2] = 0.0f;
  size[0] = 0.0f;
  size[1] = 0.0f;
  size[2] = 0.0f;
  rotation = 0.0f;

  // add the qualifiers
  for (int team = 0; team < CtfTeams; team++) {
    std::string qual = getFlagSafetyQualifier(team);
    if (qual.size() > 0) {
      qualifiers.push_back(qual);
    }
  }

  worldInfo->addZone(this);

  return;
}


void CustomZone::addZoneFlagCount(FlagType* flagType, int count)
{
  ZoneFlagMap::iterator it = zoneFlagMap.find(flagType);
  if (it != zoneFlagMap.end()) {
    count += it->second;
  }
  if (count < 0) {
    count = 0;
  }
  zoneFlagMap[flagType] = count;
  return;
}


bool CustomZone::read(const char *cmd, std::istream& input)
{
  if (strcmp(cmd, "flag") == 0) {
    std::string args, flag;

    std::getline(input, args);
    std::istringstream parms(args);

    while (parms >> flag) {
      if (flag == "good") {
	FlagSet &fs = Flag::getGoodFlags();
	for (FlagSet::iterator it = fs.begin(); it != fs.end(); ++it) {
	  FlagType *f = *it;
	  if (f->endurance != FlagNormal) { // Null and Team flags
	    const std::string& qual = getFlagTypeQualifier(f);
	    if (qual.size() > 0) {
	      qualifiers.push_back(qual);
            }
	  }
	}
      }
      else if (flag == "bad") {
	FlagSet &fs = Flag::getBadFlags();
	for (FlagSet::iterator it = fs.begin(); it != fs.end(); ++it) {
	  FlagType *f = *it;
	  if (f->endurance != FlagNormal) { // Null and Team flags
	    const std::string& qual = getFlagTypeQualifier(f);
	    if (qual.size() > 0) {
	      qualifiers.push_back(qual);
            }
	  }
	}
      }
      else {
	FlagType* f = Flag::getDescFromAbbreviation(flag.c_str());
	if (f == Flags::Null) {
	  DEBUG1("WARNING: bad flag type: %s\n", flag.c_str());
          input.putback('\n');
	  return false;
	}
	if (f->endurance != FlagNormal) {
	  DEBUG1("WARNING: you probably want a safety: %s\n", flag.c_str());
          input.putback('\n');
	  return false;
	}
        const std::string& qual = getFlagTypeQualifier(f);
	if (qual.size() > 0) {
	  qualifiers.push_back(qual);
        }
      }
    }

    input.putback('\n');
    if (qualifiers.size() == 0) {
      return false;
    }
  }
  else if (strcmp(cmd, "zoneflag") == 0) {
    std::string args, flag;
    std::getline(input, args);
    std::istringstream parms(args);
    int count;

    if (!(parms >> flag)) {
      return false;
    }
    if (!(parms >> count)) {
      count = 1;
{'fraction_non_alphanumeric': 0.16421495046532572, 'fraction_numerical': 0.014259981987391174, 'mean_word_length': 3.0162748643761303, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7624386', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2376, 'n_words': 633}