Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ assets/scenarios/multiplayer/100-rounds/100-rounds.scar
.aoe4/
cache/
archives/
prettier.config.js
30 changes: 29 additions & 1 deletion scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export const pbgs = {
rus: "unit_spearman_4_rus",
sultanate: "unit_spearman_4_sul",
abbasid: "unit_spearman_4_abb",

abbasid_ha_01: "unit_spearman_4_abb_ha_01",
chinese_ha_01: "unit_spearman_4_chi_ha_01",
french_ha_01: "unit_spearman_4_fre_ha_01",
hre_ha_01: "unit_spearman_4_hre_ha_01",
japanese: "unit_spearman_4_jpn",
byzantine: "unit_spearman_4_byz",
},
manAtArms: {
english: "unit_manatarms_4_eng",
Expand All @@ -22,6 +29,13 @@ export const pbgs = {
rus: "unit_manatarms_4_rus",
sultanate: "unit_manatarms_4_sul",
abbasid: "unit_manatarms_4_abb",

abbasid_ha_01: "unit_manatarms_4_abb_ha_01",
chinese_ha_01: "unit_manatarms_4_chi_ha_01",
french_ha_01: "unit_manatarms_4_fre_ha_01",
hre_ha_01: "unit_manatarms_4_hre_ha_01",
japanese: "unit_manatarms_4_jpn",
byzantine: "unit_manatarms_4_byz",
},
horseMan: {
english: "unit_horseman_4_eng",
Expand All @@ -32,6 +46,13 @@ export const pbgs = {
rus: "unit_horseman_4_rus",
sultanate: "unit_horseman_4_sul",
abbasid: "unit_horseman_4_abb",

abbasid_ha_01: "unit_horseman_4_abb_ha_01",
chinese_ha_01: "unit_horseman_4_chi_ha_01",
french_ha_01: "unit_horseman_4_fre_ha_01",
hre_ha_01: "unit_horseman_4_hre_ha_01",
japanese: "unit_horseman_4_jpn",
byzantine: "unit_horseman_4_byz",
},
mangonel: {
english: "unit_mangonel_3_eng",
Expand All @@ -42,10 +63,17 @@ export const pbgs = {
rus: "unit_mangonel_3_rus",
sultanate: "unit_mangonel_3_sul",
abbasid: "unit_mangonel_3_abb",

abbasid_ha_01: "unit_mangonel_3_abb_ha_01",
chinese_ha_01: "unit_mangonel_3_chi_ha_01",
french_ha_01: "unit_mangonel_3_fre_ha_01",
hre_ha_01: "unit_mangonel_3_hre_ha_01",
japanese: "unit_mangonel_3_jpn",
byzantine: "unit_mangonel_3_byz",
},
}

export const sfxs = {
roundFailure: "mus_stinger_landmark_objective_complete_fail",
roundVictory: "Conquest_enemy_eliminated",
}
}
47 changes: 38 additions & 9 deletions scripts/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { Vector3 } from "./vector3"
import { PRng } from "./prng"

export function getSquadGroupEntity(squadGroup: SGroupID): EntityID {
return Squad_EntityAt(SGroup_GetSpawnedSquadAt(squadGroup, 1), 0)
const sq = SGroup_GetSpawnedSquadAt(squadGroup, 1)
// const et = Squad_EntityAt(sg, 0)
const entity = Squad_GetFirstEntity(sq)
return entity
}

export type SpawnEntityOptions = {
Expand All @@ -14,13 +17,35 @@ export type SpawnEntityOptions = {
}

let nextEntityId = 0
export function spawnSquadGroup(playerOwner: Player, position: Position, pbg: string, options?: SpawnEntityOptions): SGroupID {
/**
* Spawn a SquadGroup
* @param playerOwner
* @param position
* @param pbg should be sbp
* @param options
* @returns SGROUPID
*/
export function spawnSquadGroup(
playerOwner: Player,
position: Position,
pbg: string,
options?: SpawnEntityOptions
): SGroupID {
// @bug 报错
let dummySquadBlueprint: SquadBlueprint = BP_GetSquadBlueprint(pbg)

const squadGroup = SGroup_CreateIfNotFound(`sg_${nextEntityId++}`)
UnitEntry_DeploySquads(playerOwner.id, squadGroup, [{
sbp: dummySquadBlueprint, numSquads: 1
}], position)
UnitEntry_DeploySquads(
playerOwner.id,
squadGroup,
[
{
sbp: dummySquadBlueprint,
num_squads: 1,
},
],
position
)

if (options?.unselectable) {
SGroup_SetSelectable(squadGroup, false)
Expand All @@ -36,11 +61,15 @@ export function spawnSquadGroup(playerOwner: Player, position: Position, pbg: st
SGroup_SetInvulnerable(squadGroup, true)
}


return squadGroup
}

export function spawnEntity(playerOwner: Player, position: Position, pbg: string, options?: SpawnEntityOptions): EntityID {
export function spawnEntity(
playerOwner: Player,
position: Position,
pbg: string,
options?: SpawnEntityOptions
): EntityID {
return getSquadGroupEntity(spawnSquadGroup(playerOwner, position, pbg, options))
}

Expand Down Expand Up @@ -102,7 +131,7 @@ export function copyPositionToVector3(vector: Vector3, position: Position) {
* @returns Random integer between min (inclusive) and max (inclusive).
*/
export function randomInt(prng: PRng, min: number, max: number) {
const range = (max - min) + 1
const range = max - min + 1
return (prng.get_random_32() % range) + min
}

Expand All @@ -112,4 +141,4 @@ export function showNotification(message: string) {

export function isEntityValidAndAlive(entityId: EntityID) {
return Entity_IsValid(entityId.EntityID) && Entity_IsAlive(entityId)
}
}
4 changes: 4 additions & 0 deletions scripts/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* ZERO-BASED get 0 of entities out of squads
*/
declare function Squad_GetFirstEntity(squad: SquadID): any;