static void main() { Location my_loc; Weapon_info winfo[6]; int i; struct g_struct gstruct; dbg("Diophantine_main()"); memset((char *) &gstruct, 0, sizeof(gstruct)); gstruct.ANYONE_HERE = 1; gstruct.sav_WANTED_SPEED = gstruct.WANTED_SPEED = max_speed(); gstruct.acc_freedom = 2.0; gstruct.crange = 9999.0; gstruct.D_shootcounter = 0; gstruct.inv_speed = 0.0; set_abs_drive(9.0); /* initialize globals */ gstruct.num_weap = num_weapons(); /* Compute stuff about weapons */ gstruct.max_weap_range = 0; for (i = 0; i < gstruct.num_weap; i++) { get_weapon(i, winfo + i); gstruct.inv_speed += winfo[i].ammo_speed; gstruct.weap_range[i] = winfo[i].range; if (gstruct.weap_range[i] > gstruct.max_weap_range) gstruct.max_weap_range = gstruct.weap_range[i]; } gstruct.inv_speed = gstruct.num_weap / gstruct.inv_speed; while (1) { get_location(&my_loc); Diophantine_watch_out_t(&gstruct); if (gstruct.D_shootcounter == 0) Diophantine_shoot_suckers(&gstruct); else Diophantine_nuke_same_guy(&gstruct); Diophantine_watch_out_a(&gstruct); /* Diophantine_watch_out_t(&gstruct); */ if (gstruct.D_shootcounter == 0) Diophantine_shoot_suckers(&gstruct); else Diophantine_nuke_same_guy(&gstruct); gstruct.WANTED_SPEED = gstruct.sav_WANTED_SPEED; } dbg1("Diophantine_main()"); }
/* ATTAQUE */ int create_action(t_engine *e, t_entity *t, t_entity *attaked) { int id; s_do_action *a; char *w; // int pop; // pop = 0; // if (t->action == ACTION_MOVE) // { // // raccourci le chemin // finish_move(e, t); // pop = 1; // // rajoute l'action dans la queue // } // else if (t->action != ACTION_NONE) reset_actions(e, t); if (!attack_is_valid(e, t, attaked)) return (-1); w = get_weapon(e, t, attaked); if (!w) return (-1); printf("ATTACKKKKKEE :p\n");fflush(stdout); // if (!pop) // { t->action = ACTION_ATTACK; fw_send_action(e, t); // } id = e->id_action++; a = (s_do_action*)xmalloc(sizeof(*a)); a->id = id; a->tag = ACTION_ATTACK; a->entity = t; a->entity->action_fail = 0; t->direction = get_direction(t->direction, &(t->pos), &(attaked->pos)); fw_send_dir(e, a->entity); a->attaked = attaked; a->cpt_time = 0; a->range = get_range(e, t, w); a->damages = get_damages(e, t, w); // <-- a revoir plus tard a->time_take = get_rof(e, t, w); // <-- a revoir plus tard // if (pop) // { // pop_action(e, t, a); // printf("\t\t\t\t\t\tje pop :)\n");fflush(stdout); // } // else // { a->next = e->actions; e->actions = a; // } fflush(stderr); return (id); }
// choose a weapon to buy and returns the weapon ID // emotion: 0 (defensive) - 100 (aggressive) // type: 0 - primary, 1 - secondary int CCSBuyManager::ChooseWeapon(int iEmotion, int iMoney, int iTeam, int iType) { int iPersonality = 1; // personality: 0 - defensive, 1 - normal, 2 - aggressive CServerCS *pServerCS = dynamic_cast<CServerCS *>(g_pServer); int iRandom = RandomLong(0, 100); // choose a random value int delta = iRandom - iEmotion; if (abs(delta) > 33) { if (delta > 0) { iPersonality = 0; // defensive } else { iPersonality = 2; // aggressive } } std::vector<int> &p = personalized; if (m_fBuyPersonalized) { p = personalized; m_fBuyPersonalized = false; } else if (iTeam == CS_TEAM_TERRORIST) { if (iPersonality == 0) p = defensive_t; else if (iPersonality == 1) p = normal_t; else p = aggressive_t; } else { if (iPersonality == 0) p = defensive_ct; else if (iPersonality == 1) p = normal_ct; else p = aggressive_ct; } int iSize = p.size(); std::vector<int> chosen; // weapons which has been chosen int iCount = 0, i, j; for (i = 0; i < iSize; i++) { int iId = p[i]; iCount++; // see if this weapon can be bought // if we're NOT using CS 1.6 and this weapon is only for CS 1.6 if (pServerCS->GetCSVersion() == CS_VERSION_WON && (iId == CS_WEAPON_GALIL || iId == CS_WEAPON_FAMAS || iId == CS_WEAPON_SHIELDGUN)) continue; // skip this weapon // are we on an assasssination map? if (pServerCS->GetMapType() & MAP_AS) { // skip certain weapons which is not available on as_* maps if (iTeam == CS_TEAM_TERRORIST) { if (iId == CS_WEAPON_M3 || iId == CS_WEAPON_XM1014 || iId == CS_WEAPON_MP5NAVY || iId == CS_WEAPON_P90 || iId == CS_WEAPON_M249) continue; // skip this weapon } else { if (iId == CS_WEAPON_AWP) continue; // skip this weapon } } cs_weapontable_s *pWeapon = get_weapon(iId); if (!pWeapon) // check if this weapon is in our list continue; // skip this weapon if not // check if we have enough money (also add some money for ammo) if (iMoney < pWeapon->iPrice + 150) continue; // skip this weapon if not if ((iType == 1 && (UtilCS::WeaponIsPrimary(iId) || iId == CS_WEAPON_SHIELDGUN)) || (iType == 0 && UtilCS::WeaponIsPistol(iId))) continue; // skip this weapon // this is a good weapon, add it to our chosen list for (j = 0; j < iCount; j++) { // add multiple instances of the weapon depends on number of weapon skipped // so that better weapons have more possibility to get chosen chosen.push_back(iId); } iCount = 0; } if (chosen.empty()) return 0; // no weapon is chosen, can't buy weapon // select the weapon to buy in the table float flFactor = (iMoney - 3000.0) / (16000 - 3000) * 3; if (flFactor < 1) flFactor = 1; // 1) better weapons has more chances to get chosen // 2) be even more aggressive if we're rich float f = log10(RandomFloat(1, pow(10, flFactor))); return chosen[(int)((float)(chosen.size() - 1) * f / flFactor + 0.5)]; }
// returns true if buying is completed, false if not bool CBotCS::BuyStuff() { int iId; CServerCS *pServerCS = dynamic_cast<CServerCS *>(g_pServer); switch (m_iBuyCount) { case 0: // if bot is rich, buy armor+helmet; else buy armor if (m_iAccount > RandomLong(3000, 5000)) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): buying armor + helmet"); g_General.FakeClientCommand(this, "buy;menuselect 8;menuselect 2"); } else { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): buying armor"); g_General.FakeClientCommand(this, "buy;menuselect 8;menuselect 1"); } break; case 1: // if bot doesn't have a primary weapon, buy one if (HasPrimary() || HasShield()) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): already have a primary weapon; exiting"); break; // don't proceed if we already have one } // TODO: emotion // select a primary weapon iId = g_pBuyMgrCS->ChooseWeapon(RandomLong(0, 100)/*FIXME*/, m_iAccount, GetTeam()); if (iId != 0) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): Buying weapon: %s", g_General.GetWeaponName(iId)); cs_weapontable_s *pWeapon = get_weapon(iId); assert(pWeapon); if (pServerCS->GetCSVersion() == CS_VERSION_STEAM) g_General.FakeClientCommand(this, pWeapon->szBuyCmd16); else g_General.FakeClientCommand(this, pWeapon->szBuyCmd15); } else { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): no primary weapon is selected"); } break; case 2: // if bot doesn't have a secondary weapon, buy one if (GetWeapons() & ((1 << CS_WEAPON_P228) | (1 << CS_WEAPON_DEAGLE) | (1 << CS_WEAPON_FIVESEVEN) | (1 << CS_WEAPON_ELITE))) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): already have a secondary weapon; exiting"); break; // don't proceed if we already have a good secondary weapon } // TODO: emotion // select a primary weapon iId = g_pBuyMgrCS->ChooseWeapon(RandomLong(0, 100)/*FIXME*/, m_iAccount, GetTeam(), 1); if (iId != 0) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): Buying weapon: %s", g_General.GetWeaponName(iId)); if (HasShield() && iId == CS_WEAPON_ELITE) break; // if we have a shield, we can't buy the dual elites cs_weapontable_s *pWeapon = get_weapon(iId); assert(pWeapon); if (pServerCS->GetCSVersion() == CS_VERSION_STEAM) g_General.FakeClientCommand(this, pWeapon->szBuyCmd16); else g_General.FakeClientCommand(this, pWeapon->szBuyCmd15); } else { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): no secondary weapon is selected"); } break; case 3: // buy enough ammo DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): buying ammo"); g_General.FakeClientCommand(this, "buy;menuselect 6"); // prim. ammo g_General.FakeClientCommand(this, "buy;menuselect 7"); // sec. ammo break; case 4: // buy grenades, defusers, etc. // if bot is CT, randomly buy the defuser if (GetTeam() == CS_TEAM_CT && RandomLong(1, 100) < 33 && m_iAccount > 200) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): buying defuser"); if (pServerCS->GetCSVersion() == CS_VERSION_STEAM) g_General.FakeClientCommand(this, "defuser"); // use alias in CS 1.6 else g_General.FakeClientCommand(this, "buyequip;menuselect 6"); } if (RandomLong(1, 100) < 75 && m_iAccount >= 300 && !(GetWeapons() & CS_WEAPON_HEGRENADE)) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): buying HE Grenade"); // Buy a HE Grenade g_General.FakeClientCommand(this, "buyequip"); g_General.FakeClientCommand(this, "menuselect 4"); } if (RandomLong(1, 100) < 50 && m_iAccount >= 200 && !(GetWeapons() & CS_WEAPON_FLASHBANG)) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): buying Concussion Grenade"); // Buy a Concussion Grenade, i.e., 'FlashBang' g_General.FakeClientCommand(this, "buyequip"); g_General.FakeClientCommand(this, "menuselect 3"); } if (RandomLong(1, 100) < 30 && m_iAccount >= 300 && !(GetWeapons() & CS_WEAPON_SMOKEGRENADE)) { DebugMsg(DEBUG_BOTAI, "CBotCS::BuyStuff(): buying Smoke Grenade"); // Buy a Smoke Grenade g_General.FakeClientCommand(this, "buyequip"); g_General.FakeClientCommand(this, "menuselect 5"); } break; case 5: // buying finished return true; // no more buying break; default: CGeneral::TerminateOnError("CBotCS::BuyStuff(): m_iBuyCount error"); break; } m_iBuyCount++; // add the buying counter return false; }