<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.
 */

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

/* system headers */
#include <sstream>
#include <string>

/* common headers */
#include "global.h" // for CtfTeams
#include "ObstacleMgr.h"
#include "ParseColor.h"
#include "PhysicsDriver.h"
#include "BzMaterial.h"


CustomGroup::CustomGroup(const std::string& groupdef)
{
  group = new GroupInstance(groupdef);
  if (groupdef.size() <= 0) {
    std::cout << "warning: group instance has no group definition" << std::endl;
  }
  return;
}


CustomGroup::~CustomGroup()
{
  delete group;
  return;
}


bool CustomGroup::read(const char *cmd, std::istream& input) {

  if (strcmp(cmd, "team") == 0) {
    int team;
    if (!(input >> team) || (team < 0) || (team >= CtfTeams)) {
      std::cout << "bad team specification" << std::endl;
      return false;
    } else {
      group->setTeam(team);
    }
  }
  else if (strcasecmp(cmd, "tint") == 0) {
    float tint[4];
    if (!parseColorStream(input, tint)) {
      std::cout << "bad " << cmd << " specification" << std::endl;
      return false;
    } else {
      group->setTint(tint);
    }
  }
  else if (strcasecmp(cmd, "phydrv") == 0) {
    std::string drvname;
    if (!(input >> drvname)) {
      std::cout << "missing Physics Driver parameter" << std::endl;
      return false;
    }
    int phydrv = PHYDRVMGR.findDriver(drvname);
    if ((phydrv == -1) && (drvname != "-1")) {
      std::cout << "couldn't find PhysicsDriver: " << drvname << std::endl;
    } else {
      group->setPhysicsDriver(phydrv);
    }
  }
  else if (strcasecmp(cmd, "matref") == 0) {
    std::string materialName;
    if (!(input >> materialName)) {
      std::cout << "missing matref parameter" << std::endl;
    }
    const BzMaterial* matref = MATERIALMGR.findMaterial(materialName);
    if ((matref == NULL) && (materialName != "-1")) {
      std::cout << "couldn't find reference material: " << materialName
		<< std::endl;
    } else {
      group->setMaterial(matref);
    }
  }
  else if (strcasecmp(cmd, "matref") == 0) {
    std::string materialName;
    if (!(input >> materialName)) {
      std::cout << "missing matref parameter" << std::endl;
    }
    const BzMaterial* matref = MATERIALMGR.findMaterial(materialName);
    if ((matref == NULL) && (materialName != "-1")) {
      std::cout << "couldn't find reference material: " << materialName
		<< std::endl;
    } else {
      group->setMaterial(matref);
    }
  }
  else if (strcasecmp(cmd, "matswap") == 0) {
    std::string srcName;
    std::string dstName;
    if (!(input >> srcName) || !(input >> dstName)) {
      std::cout << "missing matswap parameter" << std::endl;
    }
    const BzMaterial* srcMat = MATERIALMGR.findMaterial(srcName);
    const BzMaterial* dstMat = MATERIALMGR.findMaterial(dstName);
    if (srcMat == NULL) {
      std::cout << "couldn't find matswap source: " << srcName
		<< std::endl;
    } else if (dstMat == NULL) {<commit_msg>matswap III, redundancy strikes back<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.
 */

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

/* system headers */
#include <sstream>
#include <string>

/* common headers */
#include "global.h" // for CtfTeams
#include "ObstacleMgr.h"
#include "ParseColor.h"
#include "PhysicsDriver.h"
#include "BzMaterial.h"


CustomGroup::CustomGroup(const std::string& groupdef)
{
  group = new GroupInstance(groupdef);
  if (groupdef.size() <= 0) {
    std::cout << "warning: group instance has no group definition" << std::endl;
  }
  return;
}


CustomGroup::~CustomGroup()
{
  delete group;
  return;
}


bool CustomGroup::read(const char *cmd, std::istream& input) {

  if (strcmp(cmd, "team") == 0) {
    int team;
    if (!(input >> team) || (team < 0) || (team >= CtfTeams)) {
      std::cout << "bad team specification" << std::endl;
      return false;
    } else {
      group->setTeam(team);
    }
  }
  else if (strcasecmp(cmd, "tint") == 0) {
    float tint[4];
    if (!parseColorStream(input, tint)) {
      std::cout << "bad " << cmd << " specification" << std::endl;
      return false;
    } else {
      group->setTint(tint);
    }
  }
  else if (strcasecmp(cmd, "phydrv") == 0) {
    std::string drvname;
    if (!(input >> drvname)) {
      std::cout << "missing Physics Driver parameter" << std::endl;
      return false;
    }
    int phydrv = PHYDRVMGR.findDriver(drvname);
    if ((phydrv == -1) && (drvname != "-1")) {
      std::cout << "couldn't find PhysicsDriver: " << drvname << std::endl;
    } else {
      group->setPhysicsDriver(phydrv);
    }
  }
  else if (strcasecmp(cmd, "matref") == 0) {
    std::string materialName;
    if (!(input >> materialName)) {
      std::cout << "missing matref parameter" << std::endl;
    }
    const BzMaterial* matref = MATERIALMGR.findMaterial(materialName);
    if ((matref == NULL) && (materialName != "-1")) {
      std::cout << "couldn't find reference material: " << materialName
		<< std::endl;
    } else {
      group->setMaterial(matref);
    }
  }
  else if (strcasecmp(cmd, "matswap") == 0) {
    std::string srcName;
    std::string dstName;
    if (!(input >> srcName) || !(input >> dstName)) {
      std::cout << "missing matswap parameter" << std::endl;
    }
    const BzMaterial* srcMat = MATERIALMGR.findMaterial(srcName);
    const BzMaterial* dstMat = MATERIALMGR.findMaterial(dstName);
    if (srcMat == NULL) {
      std::cout << "couldn't find matswap source: " << srcName
		<< std::endl;
    } else if (dstMat == NULL) {
{'fraction_non_alphanumeric': 0.16050552922590838, 'fraction_numerical': 0.00631911532385466, 'mean_word_length': 3.2863913337846986, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 42, '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': '6505995', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2060, 'n_words': 569}