<commit_before>/*
 *  Agent.cpp
 *  openc2e
 *
 *  Created by <NAME> on Tue May 25 2004.
 *  Copyright (c) 2004 <NAME>. All rights reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 */

#include "Agent.h"
#include "MetaRoom.h"
#include "World.h"
#include "Engine.h"
#include <iostream>
#include "caosVM.h"
#include "AudioBackend.h"
#include <boost/format.hpp>
#include "Room.h"
#include "Vehicle.h"
#include "AgentHelpers.h"
#include "creaturesImage.h"
#include "Camera.h"

void Agent::core_init() {
	initialized = false;
	lifecount = 0;
}

Agent::Agent(unsigned char f, unsigned char g, unsigned short s, unsigned int p) :
  vm(0), zorder(p), timerrate(0), attr(0), visible(true) {
	core_init();

	setClassifier(f, g, s);

	lastScript = -1;

	x = 0; y = 0; // note that c2e agents are moved in finishInit

	has_custom_core_size = false;

	velx.setFloat(0.0f);
	vely.setFloat(0.0f);

	avel = 0.0f; fvel = 0.0f; svel = 0.0f;
	admp = 0.0f; fdmp = 0.0f; sdmp = 0.0f;
	spin = 0.0f;

	spritesperrotation = 0;
	numberrotations = 0;

	wasmoved = false;

	if (engine.version == 2) {
		accg = 10;
		aero = 20;
		rest = 40;
		
		size = 127; // TODO: correct default?
		thrt = 0;
		falling = false; // TODO: it looks like grav should be 0, but make sure!
	} else if (engine.version > 2) {
		accg = 0.3f;
		aero = 0;
		elas = 0;

		perm = 50; // TODO: correct default?
		falling = true;
	}

	moved_last_tick = false;
	
	range = 500;

	// TODO: is this the correct default?
	clac[0] = 0; // message# for activate 1
	if (engine.version < 3) {
		// TODO: is this the correct default? (this is equivalent to bhvr click == 0)
		clac[0] = -1; clac[1] = -1; clac[2] = -1;
	}
	clik = -1;
	
	dying = false;
	unid = -1;

	paused = displaycore = false;

	cr_can_push = cr_can_pull = cr_can_stop = cr_can_hit = cr_can_eat = cr_can_pickup = false; // TODO: check this
	imsk_key_down = imsk_key_up = imsk_mouse_move = imsk_mouse_down = imsk_mouse_up = imsk_mouse_wheel = imsk_translated_char = false;

	emitca_index = -1; emitca_amount = 0.0f;

	objp.setAgent(0); // not strictly necessary
}

void Agent::finishInit() {
	// lc2e, at least, seems to position agents centered on (-9876,-9876) to begin with
	// TODO: where should we place agents in other games? is this code right at all anyway?
	// (bear in mind that there are no parts present for some C1/C2 agents when finishInit is called, atm)
	if (engine.version > 2 && !engine.bmprenderer) { // TODO: need to think about bmp-specific code some more
		x = -9876.0f + (getWidth() / 2.0f); y = -9876.0f + (getHeight() / 2.0f);
	}
	
	// shared_from_this() can only be used if these is at least one extant
	// shared_ptr which owns this
	world.agents.push_front(boost::shared_ptr<Agent>(this));
	agents_iter = world.agents.begin();

	if (findScript(10))
		queueScript(10); // constructor
	<commit_msg>don't call script 10 as a constructor in C1/C2 mode<commit_after>/*
 *  Agent.cpp
 *  openc2e
 *
 *  Created by <NAME> on Tue May 25 2004.
 *  Copyright (c) 2004 <NAME>. All rights reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 */

#include "Agent.h"
#include "MetaRoom.h"
#include "World.h"
#include "Engine.h"
#include <iostream>
#include "caosVM.h"
#include "AudioBackend.h"
#include <boost/format.hpp>
#include "Room.h"
#include "Vehicle.h"
#include "AgentHelpers.h"
#include "creaturesImage.h"
#include "Camera.h"

void Agent::core_init() {
	initialized = false;
	lifecount = 0;
}

Agent::Agent(unsigned char f, unsigned char g, unsigned short s, unsigned int p) :
  vm(0), zorder(p), timerrate(0), attr(0), visible(true) {
	core_init();

	setClassifier(f, g, s);

	lastScript = -1;

	x = 0; y = 0; // note that c2e agents are moved in finishInit

	has_custom_core_size = false;

	velx.setFloat(0.0f);
	vely.setFloat(0.0f);

	avel = 0.0f; fvel = 0.0f; svel = 0.0f;
	admp = 0.0f; fdmp = 0.0f; sdmp = 0.0f;
	spin = 0.0f;

	spritesperrotation = 0;
	numberrotations = 0;

	wasmoved = false;

	if (engine.version == 2) {
		accg = 10;
		aero = 20;
		rest = 40;
		
		size = 127; // TODO: correct default?
		thrt = 0;
		falling = false; // TODO: it looks like grav should be 0, but make sure!
	} else if (engine.version > 2) {
		accg = 0.3f;
		aero = 0;
		elas = 0;

		perm = 50; // TODO: correct default?
		falling = true;
	}

	moved_last_tick = false;
	
	range = 500;

	// TODO: is this the correct default?
	clac[0] = 0; // message# for activate 1
	if (engine.version < 3) {
		// TODO: is this the correct default? (this is equivalent to bhvr click == 0)
		clac[0] = -1; clac[1] = -1; clac[2] = -1;
	}
	clik = -1;
	
	dying = false;
	unid = -1;

	paused = displaycore = false;

	cr_can_push = cr_can_pull = cr_can_stop = cr_can_hit = cr_can_eat = cr_can_pickup = false; // TODO: check this
	imsk_key_down = imsk_key_up = imsk_mouse_move = imsk_mouse_down = imsk_mouse_up = imsk_mouse_wheel = imsk_translated_char = false;

	emitca_index = -1; emitca_amount = 0.0f;

	objp.setAgent(0); // not strictly necessary
}

void Agent::finishInit() {
	// lc2e, at least, seems to position agents centered on (-9876,-9876) to begin with
	// TODO: where should we place agents in other games? is this code right at all anyway?
	// (bear in mind that there are no parts present for some C1/C2 agents when finishInit is called, atm)
	if (engine.version > 2 && !engine.bmprenderer) { // TODO: need to think about bmp-specific code some more
		x = -9876.0f + (getWidth() / 2.0f); y = -9876.0f + (getHeight() / 2.0f);
	}
	
	// shared_from_this() can only be used if these is at least one extant
	// shared_ptr which owns this
	world.agents.push_front(boost::shared_ptr<Agent>(this));
	agents_iter = world.agents.begin();

	if (engine.version > 2 && findScript(10))
		queueScript(10); // constructor
	
{'fraction_non_alphanumeric': 0.12436472346786248, 'fraction_numerical': 0.03333333333333333, 'mean_word_length': 3.4311258278145695, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 18, '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': '4758297', 'n_tokens_mistral': 2629, 'n_tokens_neox': 2419, 'n_words': 815}