Ejemplo n.º 1
0
void Game::onPlayersData(sf::Packet & packet)
{
	std::cout << "players data received!\n";
	Entity::Type myType;
	packet >> myType;


	if (myType == Entity::Type::Zombie)
	{
		Entity::ID myID;
		packet >> myID;
		Zombie * me = mGameWorld.createEntity<Zombie>(myID, myType);
		mGameWorld.setPlayerEntity(me->getID());
		mPlayer.setEntity(me);


		sf::Int32 humanCount;
		packet >> humanCount;
		std::cout << "You are the zombie! human count: " << humanCount << std::endl;


		for (sf::Int32 i = 0; i < humanCount; ++i)
		{
			Entity::ID id;
			packet >> id;
			Human * h = mGameWorld.createEntity<Human>(id, Entity::Type::Human);
			mGameWorld.addEntity(h->getID());
		}
	}
Ejemplo n.º 2
0
/*******************************************************************************************************
* PALYER MOVE - checks user input and sets thier heading
*******************************************************************************************************/
int PlayerMove(Human & human, StringOO & move, std::vector<int> attachedLoc)
{
	// attached locations vector = { N, S , E, W }
	int newLocation = 0;
	StringOO moveTo = move.StringLowercase();
	// set the new location variable to the corresponding room number in the attachedLoc vector
	if (moveTo.StringCompare("move north"))
	{
		newLocation = attachedLoc[0];
		human.SetHeading(0);
	}
	else if (moveTo.StringCompare("move south"))
	{
		newLocation = attachedLoc[1];
		human.SetHeading(1);
	}
	else if (moveTo.StringCompare("move east"))
	{
		newLocation = attachedLoc[2];
		human.SetHeading(2);
	}
	else if (moveTo.StringCompare("move west"))
	{
		newLocation = attachedLoc[3];
		human.SetHeading(3);
	}
	else
	{
		newLocation = -1;
	}
	return newLocation;
}
Ejemplo n.º 3
0
int main()
{
	Human	bob;

	std::cout << bob.identify() << std::endl;
	std::cout << bob.getBrain().identify() << std::endl;
}
Ejemplo n.º 4
0
void Player::humanGameStart(Human& h)
{
	cout << " The player game is setting " << endl;

	h.humanSettingGame();
	h.humanDisplayGame();
}
Ejemplo n.º 5
0
void ZombieObserver::updateAgent(AgentPackage package){
  repast::AgentId id(package.id, package.proc, package.type);
  if (id.agentType() == humanType) {
    Human * human = who<Human> (id);
    human->set(package.infected, package.infectionTime);
  }
}
Ejemplo n.º 6
0
void CartWheel3D::addHuman(const string& name, const std::string& characterFile, const std::string& controllerFile, const std::string& actionFile,
        const Math::Point3d& pos, double heading) {
    bool foundMatch = (_humans.find(name) != _humans.end());
    if (foundMatch) {
        ostringstream osError;
        osError << name << " already exists!";
        throwError(osError.str().c_str());
    }

    string sFile = _path + characterFile;
    _world->loadRBsFromFile(sFile.c_str(), _path.c_str(), name.c_str());
    Character* ch = new Character(_world->getAF(_world->getAFCount() - 1));
//    printf("AF: %s\n", _world->getAF(_world->getAFCount() - 1)->getName());
    ArticulatedRigidBody* body = ch->getArticulatedRigidBody(4);
    printf("Trying to get a Body\n");
    if (body==NULL)
        printf("Body not found\n");
    else {
        printf("Body found!!!\n");
////        body->addMeshObj("data/models/bipv3/head.obj", Vector3d(0,0,0), Vector3d(0.5,2,0.5));
//        body->replaceMeshObj("data/models/box3.obj");
//        body->getMesh(0)->scale(Vector3d(0.06,0.06,0.06));
//        body->getMesh(0)->computeNormals();
//        body->setColour(1,0,0,1);
//        body->setMass(-10);
    }

    CompositeController* con = new CompositeController(ch, _oracle, controllerFile.c_str());
    ActionCollectionPolicy* policy = new ActionCollectionPolicy(con);
    policy->loadActionsFromFile(actionFile.c_str());

    // Create a new human
    Human* human = new Human(name, ch, con, policy);
    // Initialize
    human->init();

    human->setHeading(heading);
    human->setPosition(pos);

    ch->setHeading(heading);

    _humans[name] = human;
    ch->getState(&_hStates[name]);
//    doBehavior("Standing", name, NULL);
    setController(name, 0);
    
    
//    printf("\n\nJoints:\n");
//    for(int i=0; i<ch->getJointCount(); i++) {
//        Point3d p1 = ch->getJoint(i)->getChildJointPosition();
//        Point3d p2 = ch->getJoint(i)->getParentJointPosition();
//        printf("Joint: %s, Parent-Joint: %s, Pos: (%f, %f, %f)\n", ch->getJoint(i)->getName(), ch->getJoint(i)->getParent()->getName(), p2.x, p2.y, p2.z);
//        printf("Joint: %s, Child-Joint: %s, Pos: (%f, %f, %f)\n\n", ch->getJoint(i)->getName(), ch->getJoint(i)->getChild()->getName(), p1.x, p1.y, p1.z);
//    }
    printf("\n\n\nArticulated Rigid Bodies:\n");
    for(int i=0; i<ch->getArticulatedRigidBodyCount(); i++) {
        Vector3d p = ch->getArticulatedRigidBody(i)->getCMPosition();
        printf("ARB: %s, Pos: (%f, %f, %f)\n", ch->getArticulatedRigidBody(i)->getName(), p.x, p.y, p.z);
    }
}
Ejemplo n.º 7
0
int main() {
    Human *mark = new Human(5);
    std::cout << "mark's age is " << mark->getAge() << std::endl;
    Human *mark2 = (Human*)mark->clone();
    std::cout << "mark2's age is " << mark2->getAge() << std::endl;
    return 0;
}
Ejemplo n.º 8
0
void CartWheel3D::addHuman(const string& name, const string& characterFile, const string& controllerFile, const Point3d& pos, double heading) {
    bool foundMatch = (_humans.find(name) != _humans.end());
    if (foundMatch) {
        ostringstream osError;
        osError << name << " already exists!";
        throwError(osError.str().c_str());
    }

    string sFile = _path + characterFile;
    _world->loadRBsFromFile(sFile.c_str(), _path.c_str(), name.c_str());
    Character* ch = new Character(_world->getAF(_world->getAFCount() - 1));

    IKVMCController* c = new IKVMCController(ch);

    sFile = _path + controllerFile;
    c->loadFromFile(sFile.c_str());

    BehaviourController* behaviour = new TurnController(ch, c, _oracle);

    Human* human = new Human(name, ch, c, behaviour);
    // Initialize
    human->init();

    human->setHeading(heading);
    human->setPosition(pos);

    ch->setHeading(heading);

    _humans[name] = human;
    ch->getState(&_hStates[name]);
    setController(name, 0);
//    doBehavior("Standing", name, NULL);
}
Ejemplo n.º 9
0
int main()
{
#if 0
    //9.1.2
    double Pi = 3.1415; // a double declared as a local variable(on stack)
    Human Tom; // An object of class Human declared as a local variable
    int * pNumber = new int; // an integer allocated dynamically on free store
    delete pNumber; // de-allocating the memory
    Human * pAnotherHuman = new Human(); // dynamically allocated Huaman
    delete pAnotherHuman; // de-allocating memory allocated for a Human
#elif 1
    // 9.1.3
    Human Tom; // an instance of Human
    Tom.DateOfBirth = "1970";
    Tom.IntroduceSelf();

    Human * pTom = new Human();
    pTom->DateOfBirth = "1970";
    (*pTom).IntroduceSelf();
    pTom->IntroduceSelf();
    delete pTom;
#else
    // 9.1.4
    Human Tom;
    Human *pTom = &Tom;
    pTom->DateOfBirth = "1970";
    pTom->IntroduceSelf();
#endif
    return 0;
}
Ejemplo n.º 10
0
/*
  Gets data from a TrackedPersons msg in the human map. This msg contains a list of agens with
  their positions and orientations.
 */
void GroupHumanReader::groupTrackCallback(const spencer_tracking_msgs::TrackedGroups::ConstPtr& msg) {
    tf::StampedTransform transform;
    ros::Time now = ros::Time::now();
    std::stringstream humId;

    try {
        std::string frame;
        frame = msg->header.frame_id;

        //transform from the groupTrack frame to map
        listener_.waitForTransform("/map", frame,
                msg->header.stamp, ros::Duration(3.0));
        listener_.lookupTransform("/map", frame,
                msg->header.stamp, transform);

        //for every group present in the tracking message
        for (int i = 0; i < msg->groups.size(); i++) {
            spencer_tracking_msgs::TrackedGroup group = msg->groups[i];
            humId << " group" << group.group_id;
            //create a new human with the same id as the message
            Human* curHuman = new Human(humId.str());

            //get the pose of the agent in the groupTrack frame and transform it to the map frame
            geometry_msgs::PoseStamped groupTrackPose, mapPose;
            //geometry_msgs::PoseStamped optitrackPose, mapPose;

            groupTrackPose.pose.position = group.centerOfGravity.pose.position;
            groupTrackPose.pose.orientation = group.centerOfGravity.pose.orientation;
            groupTrackPose.header.stamp = msg->header.stamp;
            groupTrackPose.header.frame_id = frame;
            listener_.transformPose("/map", groupTrackPose, mapPose);

            //set human position
            bg::model::point<double, 3, bg::cs::cartesian> humanPosition;
            humanPosition.set<0>(mapPose.pose.position.x);
            humanPosition.set<1>(mapPose.pose.position.y);
            humanPosition.set<2>(mapPose.pose.position.z);

            //set the human orientation
            std::vector<double> humanOrientation;

            //transform the pose message
            humanOrientation.push_back(0.0);
            humanOrientation.push_back(0.0);
            humanOrientation.push_back(tf::getYaw(mapPose.pose.orientation));

            //put the data in the human
            curHuman->setOrientation(humanOrientation);
            curHuman->setPosition(humanPosition);
            curHuman->setTime(now.toNSec());

            lastConfig_[humId.str()] = curHuman;
        }
    } catch (tf::TransformException ex) {
        ROS_ERROR("%s", ex.what());


    }
}
Ejemplo n.º 11
0
int		main(void)
{
	Human bob;

	std::cout << bob.identify() << std::endl;
	std::cout << bob.getBrain().identify() << std::endl;
	return (0);
}
Ejemplo n.º 12
0
int main(void)
{
	Human human;
	human.action("melee", "Zaz");
	human.action("ranged", "Thor");
	human.action("intimidating", "Tanguy");
	return (0);
}
Ejemplo n.º 13
0
void testInstanceOf() {
	Human* h = new Human();
	
	testing("InstanceOf");
	assertEqual(h->instanceOf(Human), true, "Same class");
	assertEqual(h->instanceOf(Alive), true, "Inherited");
	assertEqual(h->instanceOf(Base), true, "Base class");
	assertEqual(h->instanceOf(Inventory), false, "Different class");
}
int main()
{
	Human human1 = Human();
	Human human2 = Human("Athinodoros", "Fafoutis", 26);
	Human maxHuman = Max(human1, human2);
	cout << maxHuman.GetName() << " " << maxHuman.GetSurname();
	system("PAUSE");
    return 0;
}
Ejemplo n.º 15
0
int main()
{
	Animal Lion;
	Human jisu;
	jisu.move();
	jisu.setAge(22);
	//jisu.parentAge(Lion);
	std::cout << jisu.getAge() << std::endl;
	return 0;
}
Ejemplo n.º 16
0
void ZombieObserver::provideContent(RelogoAgent* agent, std::vector<AgentPackage>& out) {
	AgentId id = agent->getId();
	AgentPackage content = { id.id(), id.startingRank(), id.agentType(), id.currentRank(), 0, false };
	if (id.agentType() == humanType) {
		Human* human = static_cast<Human*> (agent);
		content.infected = human->infected();
		content.infectionTime = human->infectionTime();
	}
	out.push_back(content);
}
Ejemplo n.º 17
0
int CartWheel3D::getController(const std::string& name) {
    int actionIndex = 0;
    Human* human = _humans[name];

    ActionCollectionPolicy* policy = dynamic_cast<ActionCollectionPolicy*> (human->getPolicy());
    if (NULL != policy) {
        actionIndex = policy->getActionIndex();
    }

    return actionIndex;
}
Ejemplo n.º 18
0
void CartWheel3D::runStep(double dt) {
    
    _nTime += dt;
    DynamicArray<ContactPoint>* contactPoints = _world->getContactForces();
    DynamicArray<Vector3d> humanPositions;
    
    for (HumanItr itr = _humans.begin(); itr != _humans.end(); itr++) {
        Human* human = (*itr).second;
        SimBiController* c = human->getController();
        if (NULL != c) {
            c->performPreTasks(dt, contactPoints);

            // Save the current position
            humanPositions.push_back(human->getPosition());

            BehaviourController* b = human->getBehaviour();
            if (NULL != b) {
                if (b->shouldAbort()) {

                }
            }
        }
    }
    _world->advanceInTime(dt);

    bool isHumansWorking = false;
    bool isObjsWorking = false;
    contactPoints = _world->getContactForces();
    for (HumanItr itr = _humans.begin(); itr != _humans.end(); itr++) {
        Human* human = (*itr).second;
        SimBiController* c = human->getController();

        if (NULL != c) {
            c->performPostTasks(dt, contactPoints);

            // Save the current position
            humanPositions.push_back(human->getPosition());

            BehaviourController* b = human->getBehaviour();
            if (NULL != b) {
                if (b->shouldAbort()) {

                }
            }
        }        
        if(_behaviorsManager->runStep(human->getName().c_str(), _nTime)) {
//            printf("nTime: %f\n", _nTime);
            isHumansWorking = true;
        }
    }
    for(int i=0; i<_objects.size(); i++) {
        if(_behaviorsManager->runStep(_objects[i].c_str(), _nTime)) {
            isObjsWorking = true;
        }
    }
    if(!isHumansWorking && !isObjsWorking) {
        _behaviorsManager->setBehaviorsDone(true);
    } 
}
Ejemplo n.º 19
0
/*******************************************************************************************************
* HUMAN STATS - returns the vital statistics for the human player
*******************************************************************************************************/
void HumanStats(Human & HumanObj)
{
	std::cout << "\n   *------------------------------------------------------------*" << std::endl;
	std::cout << "   | Status for the human named * " << HumanObj.GetName() << " *" << std::endl;
	std::cout << "   *------------------------------------------------------------*" << std::endl;
	std::cout << "   |  - Health:       " << HumanObj.GetHealth() << std::endl;
	std::cout << "   |  - Strength:     " << HumanObj.GetStrength() << std::endl;
	std::cout << "   |  - Luck:         " << HumanObj.GetLuck() << std::endl;
	std::cout << "   |  - Intelligence: " << HumanObj.GetIntelligence() << std::endl;
	std::cout << "   *------------------------------------------------------------*" << std::endl;
}
Ejemplo n.º 20
0
Archivo: main.cpp Proyecto: nyhu/PCPP
int main() {
    Human	attack;

	attack.action("meleeAttack", "Arthur");
	attack.action("rangedAttack", "Charly");
	attack.action("intimidatingShout", "Gaston");
    
	attack.action("fart", "shit");
    
    return 0;
}
Ejemplo n.º 21
0
void Lift::elevate() {
    for(std::list<Human*>::iterator i = passengers.begin(); i != passengers.end(); ++i) {
        Human* bufferHuman = *i;
        routingList.push_back(bufferHuman->neededStorey());
    }
    routingList.sort();

    for (std::list<int>::iterator i = routingList.begin(); i != routingList.end(); ++i) {
        moveTo(*i);
        passengers.pop_back();
    }
}
Ejemplo n.º 22
0
void ZombieObserver::provideContent(const repast::AgentRequest& request, std::vector<AgentPackage>& out) {
	const vector<AgentId>& ids = request.requestedAgents();
	for (int i = 0, n = ids.size(); i < n; i++) {
		AgentId id = ids[i];
		AgentPackage content = { id.id(), id.startingRank(), id.agentType(), id.currentRank(), 0, false };
		if (id.agentType() == humanType) {
			Human* human = who<Human> (id);
			content.infected = human->infected();
			content.infectionTime = human->infectionTime();
		}
		out.push_back(content);
	}
}
Ejemplo n.º 23
0
void HumanListModel::setData(const long id, const QVariant &value, int role)
{
    switch (role)
    {
    case Human::ProfessionRole:
    {
        Human * item = (Human *)find( id );
        item->setProfession(value.toString());
        break;
    }
    case Human::MoraleRole:
    {
        Human * item = (Human *)find( id );
        item->setMorale(value.toFloat());
        break;
    }
    case Human::FatigueRole:
    {
        Human * item = (Human *)find( id );
        item->setFatigue(value.toFloat());
        break;
    }
    case Human::HungerRole:
    {
        Human * item = (Human *)find( id );
        item->setHunger(value.toFloat());
        break;
    }
    default:
        qWarning() << "HumanListModel::setData does not understand what role" << role << "is.";
        break;
    }
}
Ejemplo n.º 24
0
int main()
{
  Human me;
  Human a;
  me.age = 32;
  me.name = "Антон";
  me.weight = 68;
  a.age = 10;
  a.name = "Роберт";
  a.weight = 20;
  
  me.print();
  a.print();
}
int jail(Human &h,int pmove[],int &c1loc,int cmove[],int &c1,bool &who){
    if(who==true){
        pmove[h.getloc()]=0;
        h.setloc(10);
        h.setroll(0);//Dont know if i need it??????????????????????????????????????????????
        pmove[h.getloc()]=1;
        cout<<"You are in Jail\n";
    }else if(who==false){
        cmove[c1loc]=0;
        c1loc=10;
        c1=0;
        cmove[c1loc]=1;
        cout<<"The computer is in Jail\n";
    }
}
Ejemplo n.º 26
0
void Zombie::update(const std::vector<std::string>& levelData,
	std::vector<Human*>& humans,
	std::vector<Zombie*>& zombies,
	float deltaTime) {

	Human* closestHuman = getNearestHuman(humans);

	if (closestHuman != nullptr) {
		_direction = glm::normalize(closestHuman->getPosition() - _position);
		_position += _direction * _speed * deltaTime;
	}

	collideWithLevel(levelData);

}
Ejemplo n.º 27
0
void Shop::buyPotion(Human& human)
{
    costDisplay(potionCost, human.getGold());
    display->ask("\n| Would you like to buy a potion? [y/n]: ");
    if (strncmp("y", display->getInputBuffer(), 1) == 0)
    {
        if(human.getGold() >= potionCost)
        {
            human.setPotionCount(human.getPotionCount() + 1);
            human.decreaseGoldBy(potionCost);
        }
        else
        {
            display->text("\n[!] You're bad at math, huh?\n");
        }
    }
}
Ejemplo n.º 28
0
void Zombie::update(const std::vector<std::string>& levelData,
                    std::vector<Human*>& humans,
                    std::vector<Zombie*>& zombies) {

    // Find the closest human
    Human* closestHuman = getNearestHuman(humans);

    // If we found a human, move towards him
    if (closestHuman != nullptr) {
        // Get the direction vector twoards the player
        glm::vec2 direction = glm::normalize(closestHuman->getPosition() - _position);
        _position += direction * _speed;
    }

    // Do collision
    collideWithLevel(levelData);
}
Ejemplo n.º 29
0
	int alien_attack()
	{
		Human *cap;
		cap = new Human(35, 20);

		Alien *al;
		al = new Alien(20, 30);

		cout << "Oh no! An intruder has somehow beamed aboard your ship!\n";
		cout << "I wonder how they made it past the shields...\n";
		cout << "Quick, you need to attack." << endl << endl;

		cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n' );
		//As long as both you and the alien are alive:
		while((cap->getLife() > 0) && (al->getLife() > 0)) {
			cout << "Press ENTER to attack.";
			cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n' );
			cout << endl;

			//Gets user damage and adjusts the alien's life points
			al->setLife(al->getLife() - cap->getDamage());
			//If lifepoints go below 0, alien is dead (cannot have neg lifepoints)
			if(al->getLife() < 0) {
				al->setLife(0);
			}
			else {
				cout << "The alien's life is now " << al->getLife() << " points." << endl << endl;
				cap->setLife(cap->getLife() - al->getDamage());
				if(cap->getLife() < 0) {
					cap->setLife(0);
				}
				cout << "Your life is now " << cap->getLife() << " points." << endl;
			}
		}
		//user wins the battle
		if(al->getLife() == 0) {
			cout << endl;
			cout << "You've killed the intruder! I guess we'll never know what it\n";
			cout << "was really here for...\n";
			cout << "You are now ready to move on to a different sector.\n";
			cout << "Press ENTER to continue...";
			cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n' );
			return 1;
		}
		//user loses the battle :(
		else {
			cout << endl;
			cout << "You have been gravely wounded by the alien's razor sharp claws.\n";
			cout << "Your crew managed to save you at the last minute, but you must\n";
			cout << "return to Earth for medical attention and recuperation.\n";
			cout << "Press ENTER to continue...";
			cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n' );
			return 0;
		}
	}
Ejemplo n.º 30
0
void Shop::buy(Human& human, Armor armor)
{
	display->showAttributes(armor);
	costDisplay(armor.getPrice(), human.getGold());
	display->ask("\n| Would you like to buy this item? [y/n]: ");
	if (strncmp("y", display->getInputBuffer(), 1) == 0)
	{
		if (armor.getPrice() <= human.getGold())
		{
			human.setArmor(armor);
			human.decreaseGoldBy(armor.getPrice());
		}
		else
		{
			display->text("\n[!]You cannot afford this item\n");
		}
	}
}